How to read 4 bits NOT in convenient INA/INB/INC locations
xanatos
Posts: 1,120
I have a program that reads a 4 bit nibble from an auxillary chip and during prototyping, I was able to conveniently place it so that all 4 bits lined up with INB on my BS2. Unfortunately the real production unit I am working with must (for reasons too long to explain here) have those bits appear of pins 11, 12, 13 and 14.
I find myself unsure of how to read those bits as a single entity now. My code was a simple "IF INB = 12 THEN...". Now I have IN11, IN12, IN13 and IN14. How can I read them as one "thing"?
Thanks,
Dave
UPDATE: This works - but is this the most simple way of doing it?:
keyIn = (IN14<<3)+(IN13<<2)+(IN12<<1)+IN11
It gets the bits in the right place and works in the program, just wondering if there's a better way, like INS(11..14) or something.
I find myself unsure of how to read those bits as a single entity now. My code was a simple "IF INB = 12 THEN...". Now I have IN11, IN12, IN13 and IN14. How can I read them as one "thing"?
Thanks,
Dave
UPDATE: This works - but is this the most simple way of doing it?:
keyIn = (IN14<<3)+(IN13<<2)+(IN12<<1)+IN11
It gets the bits in the right place and works in the program, just wondering if there's a better way, like INS(11..14) or something.
Comments
myBits = (INS >> 11) & $F
This gets you bits 14, 13, 12, and 11 as a 4-bit number in myBits. You don't have to assign the value to a temporary variable ... you can use that expression in an IF statement (in parentheses).
Note: The mask was wrong ... 5 bits when it should have been 4.
I knew if you were on tonight you'd have a more elegant solution than my four-part bitwise shift! Thanks very much!!!
Dave