Shop OBEX P1 Docs P2 Docs Learn Events
Byte bitwise rotary — Parallax Forums

Byte bitwise rotary

lojzalojza Posts: 2
edited 2007-04-21 16:12 in Propeller 1
Hi, I'm newbie and I'm playing with LEDs and my problem is: When I change·variable Pin in following code from Long to Byte,·bitwise rotary in last line·does't work like bitwise rotary, but like bitwise shiftshocked.gif· What's wrog?


CON
· _clkmode = xtal1 + pll16x·····
· _xinfreq = 5_000_000··········
'
VAR
· Long Pin·······················
'
PUB Start·····································································
· BlinkingLED····················
'······························································································································
PRI BlinkingLED··················
· Pin := %00000111············································
· dira[noparse][[/noparse]23..16] := %11111111
· Repeat
······· outa[noparse][[/noparse]23..16] := Pin
······· WaitCnt(8_000_000 + Cnt)
······· Pin<-=1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-21 15:57
    All arithmetic on the Propeller is done on 32 bit values including the circular shift. The current value of Pin is fetched, extended with zeros to make a 32 bit value, the shift is done, and the least significant 8 bits are stored back into Pin ... not exactly what you expected.

    You need to do: Pin := ((Pin << 1) | (Pin >> 7)) & $FF

    If you change Pin to a byte, you can leave off the "& $FF".
  • lojzalojza Posts: 2
    edited 2007-04-21 16:12
    Very clever. smile.gif· Thanks a lot.
Sign In or Register to comment.