Byte bitwise rotary
lojza
Posts: 2
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 shift· 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
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
You need to do: Pin := ((Pin << 1) | (Pin >> 7)) & $FF
If you change Pin to a byte, you can leave off the "& $FF".