| ??? 03/30/03 08:03 Read: times |
#42538 - keypad routine |
I have the following keypad subroutine which is made to work for p1.0-1.3 connected to rows, and p2.0-p2.3 connected to columns.
However, my keypad is connected with p1.0-p1.3 to the rows, and p1.4-p1.7 to the columns. The second code segment I have put here is the way I modified it for my setup, but it only displays characters from the first column of the lookup table(1, 4, 7, and *) no matter if I hit a different key from the same row. For instance, when I hit a 1, 2, 3, or A, it displays a 1. When I hit a 4, 5, 6, or B, it displays a 4. When I hit a 7, 8, 9, or C, it displays a 7. When I hit a *, 0, #, or D, it displays a *. How can I fix my code so that itwill locate the correct column and row location of the characters instead of just locating characters from the first column of each row? ;----------Below, this is the original code for p1.0-1.3 connected to rows, and p2.0-p2.3 connected to columns.;---------- mov p2, #0ffh k1: mov p1, #0 mov a, p2 anl a, #00001111b cjne a, #00001111b, k1 k2: acall delay mov a, p2 anl a, #00001111b cjne a, #00001111b, over sjmp k2 over: acall delay mov a, p2 anl a, #00001111b cjne a, #00001111b, over1 sjmp k2 over1: mov p1, #11111110b mov a, p2 anl a, #00001111b cjne a, #00001111b, row_0 mov p1, #11111101b mov a, p2 anl a, #00001111b cjne a, #00001111b, row_1 mov p1, #11111011 mov a, p2 anl a, #00001111b cjne a, #00001111b, row_2 mov p1, #11110111b mov a, p2 anl a, #00001111b cjne a, #00001111b, row_3 ljmp k2 row_0: mov dptr, #kcode0 sjmp find row_1: mov dptr, #kcode1 sjmp find row_2: mov dptr, #kcode2 sjmp find row_3: mov dptr, #kcode3 find: rrc a jnc match inc dptr sjmp find match: clr a movc a, @a+dptr lcall lcd_cout ;ascii look up table for each row kcode0: .db '1', '2', '3', 'A' ;row 0 kcode1: .db '4', '5', '6', 'B' ;row 1 kcode2: .db '7', '8', '9', 'C' ;row 2 kcode3: .db '*', '0', '#', 'D' ;row 3 ;------------------------------------------------------------------------------------ ;-------------Below is my modified version of the original code----------------------- k1: mov p1, #0f0h mov a, p1 anl a, #11110000b cjne a, #11110000b, k2 sjmp k1 k2: acall delay mov a, p1 anl a, #11110000b cjne a, #11110000b, over sjmp k2 over: acall delay mov a, p1 anl a, #11110000b cjne a, #11110000b, over1 sjmp k2 over1: mov p1, #11111110b mov a, p1 anl a, #11110000b cjne a, #11110000b, row_0 mov p1, #11111101b mov a, p1 anl a, #11110000b cjne a, #11110000b, row_1 mov p1, #11111011b mov a, p1 anl a, #11110000b cjne a, #11110000b, row_2 mov p1, #11110111b mov a, p1 anl a, #11110000b cjne a, #11110000b, row_3 ljmp k2 row_0: mov dptr, #kcode0 sjmp find row_1: mov dptr, #kcode1 sjmp find row_2: mov dptr, #kcode2 sjmp find row_3: mov dptr, #kcode3 find: rrc a jnc match inc dptr sjmp find match: clr a movc a, @a+dptr lcall lcd_cout ljmp k1 Pause: mov r7, #10h mov r6, #01fh Pause1: djnz r6, Pause1 djnz r7, Pause1 ret delay: lcall LPause LPause: mov r5, #11 LPause1: acall Pause djnz r5, LPause1 ret ;ascii look up table for each row kcode0: .db '1', '2', '3', 'A' ;row 0 kcode1: .db '4', '5', '6', 'B' ;row 1 kcode2: .db '7', '8', '9', 'C' ;row 2 kcode3: .db '*', '0', '#', 'D' ;row 3 |
| Topic | Author | Date |
| keypad routine | 01/01/70 00:00 | |
| RE: keypad routine | 01/01/70 00:00 | |
| RE: keypad routine | 01/01/70 00:00 | |
| RE: keypad routine | 01/01/70 00:00 | |
| RE: keypad routine | 01/01/70 00:00 | |
| RE: keypad routine - schmatic helpful | 01/01/70 00:00 | |
Modification?? | 01/01/70 00:00 |



