??? 07/17/11 17:12 Modified: 07/17/11 17:13 Read: times |
#182873 - a keyboard question AT89C51 |
hi every one i have made a simulation of akeyboard using AT89C51 microcontroller but the problem is whenever i connect the columns of the keyboard to port 2 the keyboard doesnot work i tried connecting the columns to port P0 with out connecting apull up resistor to the port and it worked great so any one tell what is wrong with it
thise is the program i made (assembly) using keil and the simulation using isis ...insert code hereORG 00H MOV P,#0FFH ;make port 0 input K1: MOV P1,#0 ;ground all rows MOV A,P2 ;read all columns check if all keys open ANL A,#00001111B ;mask lower four bits CJNE A,#00001111B,K1 ;check till all keys are released K2: ACALL DELAY ;wait for debounce MOV A,P2 ;read columns ANL A,#00001111B ;mask CJNE A,#00001111B,OVER ;see if any key pressed SJMP K2 ;no key pressed OVER: ACALL DELAY ;wait for debounce MOV A,P2 ;read all columns ANL A,#00001111B ;mask CJNE A,#00001111B,OVER1 ;see if any key pressed SJMP K2 ;no key pressed OVER1: MOV P1,#11111110B ;ground first row MOV A,P2 ;read columns ANL A,#00001111B ;mask lower four bits CJNE A,#00001111B,ROW_0 ;check if any key pressed MOV P1,#11111101B ;no key pressed check second row MOV A,P2 ANL A,#00001111B CJNE A,#00001111B,ROW_1 MOV P1,#11111011B ;no key pressed check third row MOV A,P2 ANL A,#00001111B CJNE A,#00001111B,ROW_2 MOV P1,#11110111B ;no key pressed check fourth row MOV A,P2 ANL A,#00001111B CJNE A,#00001111B,ROW_3 LJMP K2 ;do it again ROW_0: MOV DPTR,#KCODE0 ;load key row 0 SJMP FIND ;find which one is pressed ROW_1: MOV DPTR,#KCODE1 ;load key row 1 SJMP FIND ;find which one is pressed ROW_2: MOV DPTR,#KCODE2 ;load key row 2 SJMP FIND ;find which key is pressed ROW_3: MOV DPTR,#KCODE3 ;load key row 3 FIND: RRC A JNC MATCH INC DPTR SJMP FIND MATCH: CLR A ;if key is grounded then thise the key pressed MOVC A,@A+DPTR MOV P3,A ;move ascii code for the pressed key LJMP K1 ;do it infintely ORG 300H KCODE0: DB '0','1','2','3' ;ROW 0 KCODE1: DB '4','5','6','7' ;ROW 1 KCODE2: DB '8','9','A','B' ;ROW 2 KCODE3: DB 'C','D','E','F' ;ROW 3 DELAY: MOV TMOD,#01H ;thise is the delay subroutine MOV TL0,#0FFH MOV TH0,#0B7H SETB TR0 WAIT: JNB TF0,WAIT CLR TR0 CLR TF0 RET END |
Topic | Author | Date |
a keyboard question AT89C51 | 01/01/70 00:00 | |
image of circuit | 01/01/70 00:00 | |
use P0 not P | 01/01/70 00:00 | |
Parity flag | 01/01/70 00:00 | |
How do you write a number to the parity flag? | 01/01/70 00:00 | |
PSW | 01/01/70 00:00 | |
Don't say, "make port 0 input" | 01/01/70 00:00 | |
port 2 not port 0 | 01/01/70 00:00 | |
Too simplified view on input/output | 01/01/70 00:00 | |
Incorrect - look again! | 01/01/70 00:00 |