Jason, thank you I think I am half way there. My failure to
understand how the keypad seems to be my problem.
I have a few more questions. If it is setting 1 bit in *dat, why the
need to invert? Is 1 treated as low voltage and 0 as a large voltage?
I noticed it is setting a bit in the far right nibble. If A,B,C,D
are set in that nibble, is 1,2,3,4 the left nibble? If so, am I right
in saying that if you change bits in the first nibble for A,B,C, or D,
then the left nibble will change? Also what happens if 2 or more lines
are selected, such as A and B at the same time? Could you explain the
second line, 'on |= (~(*dat >> 4) & 0xf) << (4 * pos);'? I appreciate
the time you have taken to help me out.
Justin
--- In Jason Stahls <> wrote:
>
> 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/
|