Arithmetic and bit shift??
James Long
Posts: 1,181
Here is my problem. I'm receiving a byte which is coded as follows. The top 2 bits (MSB) are information of state of a button(EZlcd) and the lower 6 bits are the button number (0 -63)
I'm trying to strip off the information, but when i do and send back the button number.....it doesn't work.
I can put in a button number (dec) and the display indicates perfectly.
I have posted the code here....for someone to clue me in to what I'm doing wrong. I know I'm doing something wrong.....I'm just not sure as·to what.
The "serial.tx(button_v)" is the culprit. If I put in the number 4....it works fine. I have tried "serial.tx(button_v.byte[noparse][[/noparse]0])" and shifting the bits left and then right. But it seems the value of "button_v" is something strange. It should be a byte of info....."button_value" is a byte of information.
I know I have shifted the number bitwise.....will this cause the number to different?
I was trying to do this with the state of the button(pressed or un-pressed) and was getting weird results as well.....so i just took that out for now. Once I find a solution.....I'll put it back in.
Help would be appreciated.
James L
I'm trying to strip off the information, but when i do and send back the button number.....it doesn't work.
I can put in a button number (dec) and the display indicates perfectly.
I have posted the code here....for someone to clue me in to what I'm doing wrong. I know I'm doing something wrong.....I'm just not sure as·to what.
Serial = fullduplexserial.·button_value := 0
· button_value := serial.rxcheck
· button_v := button_value
· if button_v =< 127
··· button_v := (button_v <- 2) >> 2
··· serial.tx(button_state)
··· serial.tx(button_v)
··· serial.tx(2)
The "serial.tx(button_v)" is the culprit. If I put in the number 4....it works fine. I have tried "serial.tx(button_v.byte[noparse][[/noparse]0])" and shifting the bits left and then right. But it seems the value of "button_v" is something strange. It should be a byte of info....."button_value" is a byte of information.
I know I have shifted the number bitwise.....will this cause the number to different?
I was trying to do this with the state of the button(pressed or un-pressed) and was getting weird results as well.....so i just took that out for now. Once I find a solution.....I'll put it back in.
Help would be appreciated.
James L
Comments
I've had trouble sorting these three data types out, and practicing with PC_Debug and fullduplex has helping clarified things. Maybe your problem is related to something similar. (I think fullduplexderial is basically equivalent to the combination of PC_Debug and fullduplex.) Another issue is how you have your terrminal emulater set up: binary vs. ascii.
Jim C
I found a solution......I thought about it after I layed down last night. Bit shift only works in 32 bits. So I wasn't shifting far enough to get the upper digits off. I had to shift 26 to the left.
I have to know what button to put down....and it must know what number to put back up. But I did a work around.
I see how the "&" would work well.
I'll try that....it will take fewer steps than what I'm doing now. I know it will work.
I haven't used the logic and,or , not statements much lately and I forget what the resulting number will be. I looked in the manual....but it escaped me.....that is why I used bit shift.
James L