Shop OBEX P1 Docs P2 Docs Learn Events
Arithmetic and bit shift?? — Parallax Forums

Arithmetic and bit shift??

James LongJames Long Posts: 1,181
edited 2007-03-02 17:04 in Propeller 1
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.
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)
Serial = fullduplexserial.·

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

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-02 06:05
    I'm not sure what you're trying to do. I understand about receiving a combination of button state and button number, but I'm not sure what you want to do with it. You can isolate the button state with "state := button_value >> 6" and the button number with "number := button_value & $3F". What do you want to send back?
  • JamesxJamesx Posts: 132
    edited 2007-03-02 10:38
    There are three different data types to keep straight with fullduplexserial: decimal, character, and binary.

    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
  • James LongJames Long Posts: 1,181
    edited 2007-03-02 17:04
    Mike,

    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
Sign In or Register to comment.