The 4x4 keypad works like this
ABC D
1 + + + +
2 + + + +
3 + + + +
4 + + + +
Where you apply power to A, then check for that voltage on 1, 2, 3, and
4. You then apply power to B and check 1, 2, 3, and 4 again, and so on.
*dat = ~(1 << pos);
This line is setting a bit in dat, if we break all of it down it looks
like this (I think, I still much up bitwise some days)
1 << pos, this bit shifts 1 to the left pos positions. So, in binary
(I'm going to pad this to nibble size) if we shift 0001 left 2 places we
get 0100, 1 is 0010, ect.
~(1 << pos), we then invert the result from (1 << pos), so if we had
0010 and inverted it with ~ we'd get 1101
Hope that helps.
Jason
ticrus00 wrote:
> Forgive me I am new at this. I am trying to understand whats going on
> in the keypad.c sample code provided with the ts-7200 board.
> Specifically:
>
> unsigned int get_keys(void) {
> unsigned int pos, on = 0;
>
> for(pos = 0; pos < 4; pos++) {
> *dat = ~(1 << pos); <- I DON'T UNDERSTAND THIS
> on |= (~(*dat >> 4) & 0xf) << (4 * pos);
> }
> return on;
> }
>
> The above arrow is the line I am not following because to me its is
> setting *dat equal to ~(1 << pos). But when *dat is used in the line
> below it is a different value. I don't know anything about the keypad
> and maybe thats my problem. Is it some sort of msg to the keypad? Is
> there any documentation out there besides the keypad.c and the
> hardware guide that came with the board?
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|