??? 01/04/06 05:12 Read: times |
#106434 - try this Responding to: ???'s previous message |
Hello,
Working with the 8051 port pins can be tricky since some instructions read the output latch while some read the actual logic level at the pin. P1.4 must be the signal from 74C922 that indicates a keypress, and P0:3 has the BCD code. Try this mod to your program: CHECK: JNB P1.4, CHECK ; IF DAV IS SET, PROCEED TO GET KEY MOV A, P1 ; Get the port value into the accumulator ANL A, #0Fh ; Mask the BCD value MOV TEMP, A ; Save it to memory RET ; Return You used CLR P1.x instruction in your code, that is "read-modify-write" instruction that reads the port latch rather than the pin, modifies the specified bit and writes all 8 bits back! And the output latch is set to 0FFh. It is a good practice not to work directly with port pins unless its necessary, this "read-modify-write" can cause unibiquious bugs in your code. Now, every mechanical keypress has a tendency to jitter for a while before settling down to final value. If you read it immediately its possible that you will read it while its still up. You must wait for a while, say 10 milliseconds till you can be sure that the key is well settled and its value can be safely read. This is called key-debouncing, and it can avoid misinterpreting this jitter as multiple keystrokes. Try debouncing the key as: CHECK: JNB P1.4, CHECK ; IF DAV IS SET, PROCEED TO GET KEY ; Let the key settle down, wait for a while CALL DELAY ; 10 millisecond delay JNB P1.4, CHECK ; Now check if we still have the key MOV A, P1 ; Get the port value into the accumulator ANL A, #0Fh ; Mask the BCD value MOV TEMP, A ; Save it to memory RET ; Return Girish |
Topic | Author | Date |
8051 keypad input | 01/01/70 00:00 | |
try this![]() | 01/01/70 00:00 |