The code "value = input_x()" could read an entire Byte from 8 pins. But, how to read just 4 pins in the same way of the input_x() command?
I think is easy with input(PIN_X) command, but is there another way?
thank
n-squared
Joined: 03 Oct 2006 Posts: 99
Posted: Fri Jan 06, 2012 12:25 am
There is no way of reading a nibble DIRECTLY.
What you can do is input_x() and AND it with a mask:
Code:
X = input_b() & 0x0F; / bits 0 to 3
Y = input_b() >> 4; // bits 4 to 7
Z = (input_b() & 0x3C) >> 2; // bits 2 to 5
BR
NN _________________ Every solution has a problem.
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
Posted: Fri Jan 06, 2012 2:56 am
As an extra comment, look at the 'swap' function in CCS. This uses a single byte command to swap the high and low nibbles in a byte. Much more efficient than four rotations.
Best Wishes
eguti
Joined: 01 Jan 2012 Posts: 2 Location: Brazil
Posted: Fri Jan 06, 2012 8:01 am
Thanks Ttelmah and n-squared. I will try both tips.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum