Problem with Spin case statement
Rsadeika
Posts: 3,837
In the 'main', the 'repeat' statement has a 'case' statement which is not working as expected, and I cannot figure out why. What I expect to occur is when I select the device 'tv', I only should get an LED activity on the power btn, but I am also getting an LED activity on the 'r arrow head' btn, which should only become active when the device is set to 'vcr'. I double checked my 'indents', and they seem to be in the correct position, so what is wrong with this?
Thanks
Ray
Thanks
Ray
con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 con ' PST formmatting control #1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR, #16, CLS obj ir : "jm_sircs_rx" ' sircs decoding term : "jm_txserial" ' tx serial misc : "tools" pub main | code, bc, devcode, keycode ir.init(0) ''ir.init(27) ' IR demod on p27 term.init(30, 115_200) ' term on programming port misc.waitms(1000) repeat code := ir.getir devcode := code & $f80 keycode := code & $7f ' wait for key bc := ir.bitcount ' get bitcount ''case bc ''12: case devcode %000010000000 : ''device tv showcode(devcode) ''devcode = %000010000000 case keycode %000000010101 : ''Power key LED1 term.bin(devcode, 12) term.tx(CR) term.bin(keycode, 12) term.tx(CR) %010110000000 : ''device vcr showcode(devcode) ''devcode = %010110000000 case keycode %000000011010 : ''r arrow head LED1 term.bin(devcode, 12) term.tx(CR) term.bin(keycode, 12) term.tx(CR) misc.waitms(400) devcode := 0 keycode := 0 PRI tv_power LED1 PRI vcr_r_a_head LED1 PRI showcode(devcode) term.bin(devcode, 12) term.tx(CR) PRI LED1 misc.high(1) misc.waitms(250) misc.low(1)
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (MagIO2) : 3/3/2010 2:21:48 PM GMT
This investigation started with the fact that I was not certain as to what variable value 'devcode := (code & $f80) >> 7' was providing. So, I borrowed some of JonnyMac's code to find out exactly what the values are, since I am certain that his program is providing the correct values. The first thing I noticed was that devcode = 0, when I used 'devcode := (code & $f80) >> 7', I changed it to 'devcode := code & $f80' which is now providing the type of value that I was expecting.
The thing that has me a bit flustered is that in the program above, I have applied some sensible logic IMO, but the outcome is not what I am expecting. So, now I have to figure out what part of my logic is not translating to the programs functionality, to provide the correct outcome; using the saying of "garbage in, garbage out", it must BE MY FAULT. I think this is going to take awhile ...
Ray
Ray
But I can't believe what you say about the devcode:
assume code is $00001_0010101
then code & $f80 (which is %11111_0000000) will give you %00001_0000000
and %00001_0000000 >> 7 is %00001
I ran across a bit of information on the codes that is new to me:
The 15-bit code is a wired code; the device code is eight bits, the key code is seven bits. The 20-bit code is 8 + 12 (not confirmed yet). Based on that you might do something like this:
With this structure you've got the constituent parts of the code that just came in and it might be easier to work with.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA