Bit test or -flag test in spin
gwkaub
Posts: 10
Ok this has me lost; working in spin can I check a bit or negative flag ?
I'm trying to send out long & short pulses (IR code) I call dash & dot.
Sending out high bit first 16 bits. I first need to check 1 or 0, being high bit I could check -flag.
This is the code giving me problem:
pub aux
t1 := 1600 'dash 1.6 ms
t2 := 750 'dot 750 µs
strobe(46500) 'sync pulse 9.3 ms
waitcnt(22000 + cnt) '4.4 MS
strobe(3500) '700 µs
waitcnt(2000 + cnt) '400 µs
start := $08ff
repeat 16
if start and $8000 'high bit 1
dash
else
dot
strobe(2500)
start <<= 1 'shift left for next bit
repeat 16
if code and $8000 'high bit 1
dash
else
dot
strobe(2500)
code <<= 1 'shift left for next bit
I'm trying to send out long & short pulses (IR code) I call dash & dot.
Sending out high bit first 16 bits. I first need to check 1 or 0, being high bit I could check -flag.
This is the code giving me problem:
pub aux
t1 := 1600 'dash 1.6 ms
t2 := 750 'dot 750 µs
strobe(46500) 'sync pulse 9.3 ms
waitcnt(22000 + cnt) '4.4 MS
strobe(3500) '700 µs
waitcnt(2000 + cnt) '400 µs
start := $08ff
repeat 16
if start and $8000 'high bit 1
dash
else
dot
strobe(2500)
start <<= 1 'shift left for next bit
repeat 16
if code and $8000 'high bit 1
dash
else
dot
strobe(2500)
code <<= 1 'shift left for next bit
Comments
As an example, are you trying to say
If X & Y == 1 ?
You can test a bit by using a mask.
Make sure you're using & to test bits, not and (which is a logical test)
Then I send 16 bit code for key pressed.
pub aux
t1 := 1600 'dash 1.6 ms
t2 := 750 'dot 750 µs
strobe(46500) 'sync paulse 9.3 ms
waitcnt(22000 + cnt) '4.4 MS
strobe(3500) '700 µs
waitcnt(2000 + cnt) '400 µs
start := $08ff
repeat 16
if start & $8000 'high bit 1
dash
else
dot
strobe(2500)
start <<= 1 'shift left for next bit
repeat 16
if code & $8000 'high bit 1
dash
else
dot
strobe(2500)
code <<= 1 'shift left for next bit
if code and $8000 must be if code & $8000
AND is used in a case where you want to test two or more things:
If X > Y AND if Y > Z then
do something.
The manual will have the examples for AND and &.
You have redundant elements in your code; you can use this method to send any 16-bit value (start or the code).
Note the use of bitwise and (&) with the mask so the if expression will only evaluate as true when value.bit15 is one. When using logical and, any non-zero value is promoted to true; this is not what you want when testing specific bits.