|
I tried interfacing my keypad using the 'scan rows and columns' method. I used PORTC and set PC0-PC3 (rows) as output pins, while PC4- PC7 (columns) as input pins. So i stored $0F in DDRC. PC4-PC7 are hooked up to Vcc with a 10k pull up resistor. I found a sample code in my book, and in the "idkey" subroutine (which identifies which key is pressed), i'm a little unsure about what's going on. From what I see, it basically loads a keycode from a keytable,(for example key #1 corresponds to $EE, 1110 1110) and stores the data in PORTC. It then loads PORTC, and compares the value of PORTC to the one that was previously stored. That's what i understand from the arrows below. Please correct me if i'm wrong. My question is actually below. idkey pshy pshb ldy #KYTAB clra idkey1 inca iny ldab 0,y <------ loads keycode_0 stab PORTC,x <------ stores keycode_0 in PRTC psha <------ ldaa PORTC,x <------ now loads PRTC w/ keycode_1 cba <------ keycode_0 ==? keycode_1 pula <------ beq idkey2 <------ Leave if they are equal cmpa #12 blo idkey1 clra idkey2 staa COL ;TEST TEST TEST pulb puly rts In my book it says "Note also that writing to a port with some lines configured as input does not affect the corresponding data register bits." So when I tried to store $EE in port C, does that mean $EE was *not* stored in PORTC? If it was not stored, what was the point of storing it in PORTC? I have more questions, but i'll start with this one. Eileen |
|
|
|
> -----Original Message----- > From: eileeniicg [mailto:] > Sent: Sunday, September 28, 2003 3:11 PM > > In my book it says "Note also that writing to a port with some lines > configured as input does not affect the corresponding data register > bits." So when I tried to store $EE in port C, does that mean $EE > was *not* stored in PORTC? If it was not stored, what was the point > of storing it in PORTC? I have more questions, but i'll start with > this one. > > Eileen Eileen, Another way to say the note above is, "You can't store to an input line," which makes perfect sense if you think about it. For a Port C with DDRC written as you have, reading it could return %XXXX1110, where the X's could be 0 or 1. Now, with your hardware pulling up PC4-7 and no key being pressed in the row being grounded by bit 0, Port C should read $FE. If your keypad looks like this: PC0 PC1 PC2 PC3 PC4 1 2 3 C PC5 4 5 6 D PC5 7 8 9 E PC7 0 A B F If 1 is pressed $EE should be read back from Port C; 4, $DE; 7, $BE; and 0, $7E, that is, the ungrounded inputs will all read high. I hope this explains it. Emmett Redd Ph.D. mailto: Associate Professor (417)836-5221 Department of Physics, Astronomy, and Material Science Southwest Missouri State University Fax (417)836-6226 901 SOUTH NATIONAL Dept (417)836-5131 SPRINGFIELD, MO 65804 USA |
|
|
|
Thanks. So the point of storing the value $EE in PORTC is to simply drive the PC0 bit to 0? Eileen --- In , "Redd, Emmett R" <err557f@s...> wrote: > > -----Original Message----- > > From: eileeniicg [mailto:Eileen@r...] > > Sent: Sunday, September 28, 2003 3:11 PM > > > > In my book it says "Note also that writing to a port with some lines > > configured as input does not affect the corresponding data register > > bits." So when I tried to store $EE in port C, does that mean $EE > > was *not* stored in PORTC? If it was not stored, what was the point > > of storing it in PORTC? I have more questions, but i'll start with > > this one. > > > > Eileen > > > > Eileen, > > Another way to say the note above is, "You can't store to an input > line," which makes perfect sense if you think about it. For a Port C > with DDRC written as you have, reading it could return %XXXX1110, where > the X's could be 0 or 1. Now, with your hardware pulling up PC4-7 and > no key being pressed in the row being grounded by bit 0, Port C should > read $FE. > > If your keypad looks like this: > PC0 PC1 PC2 PC3 > > PC4 1 2 3 C > > PC5 4 5 6 D > > PC5 7 8 9 E > > PC7 0 A B F > > If 1 is pressed $EE should be read back from Port C; 4, $DE; 7, $BE; and > > 0, $7E, that is, the ungrounded inputs will all read high. > > I hope this explains it. > > Emmett Redd Ph.D. mailto:EmmettRedd@s... > Associate Professor (417)836-5221 > Department of Physics, Astronomy, and Material Science > Southwest Missouri State University Fax (417)836-6226 > 901 SOUTH NATIONAL Dept (417)836-5131 > SPRINGFIELD, MO 65804 USA |
|
In a message dated 9/28/03 4:50:46 PM Eastern Daylight Time, writes: I tried interfacing my keypad using the 'scan rows and columns' method. I used PORTC and set PC0-PC3 (rows) as output pins, while PC4- PC7 (columns) as input pins. So i stored $0F in DDRC. PC4-PC7 are hooked up to Vcc with a 10k pull up resistor. ================================================= I figure any algorithm that can be expressed in a clear sentence or two can be programmed. I'd use c rather than assembler, because you can concentrate on the algorithm more easily... 'what value is in each variable' rather than 'which variable is in what register' and 'gee, I already used that register, so I need to push it, but I've got to remember to pull it back before I branch out of this loop'. Anyway, heres my two sentences on how to read the keypad: We are going to turn on the columns one at a time... we'll be storing binary 0001,0010,0100,1000.... (thats 1,2,4,8) to turn them on. These magic numbers can be looked up in a table or 'computed' with an expresion like (1 << n) where n is the times thru the loop 0,1,2,3. On ea pass thru the loop, we turn on the column then read the rows and see if any one of the four bits in the nibble we are interested in is pulled lo. So we read the port, AND with 0x0f to get rid of the hi nibble we arent interested in, then if it's not F then there is a bit lo. The value is probably E,D, B or 8 if only one button is pressed, This tells us which row 0,1,2, or 3 is low. So we can now compute which key is pressed by column*4 +row. Does this seems clearer or more complicated? [Non-text portions of this message have been removed] |
|
> -----Original Message----- > From: eileeniicg [mailto:] > Sent: Sunday, September 28, 2003 5:53 PM > To: > Subject: [m68HC11] Re: Keypad question (oh no!) > > Thanks. So the point of storing the value $EE in PORTC is to simply > drive the PC0 bit to 0? > > Eileen And to have E stored in the high nybble for comparison with the value read back from Port C to determine if 1 has been pressed. Emmett |