??? 03/03/10 18:32 Read: times |
#173791 - Integrating Keypad and LCD CODE |
hey,
Just started doing keypad code this semester in college, so still getting to grips with this sort of code. Ive written LCD Code and Ive written Keypad code, but now i have to join them together and im finding it dificult. Below is my keypad code. $mod831 keyport equ P0 ; col1 equ P0.0 col2 equ P0.1 col3 equ P0.2 col4 equ P0.3 keyval equ 30H ;To store key number pressed bit 0H ;Flag key_init: mov keyport,#0FH ret get_key: mov keyval,#0 ;reset the number mov keyport,#7FH ;make Row1 low acall read_col ;read columns jb pressed, done ;check if flag is set mov keyval,#4 ;if not then read next row mov keyport,#0BFH ;make Row2 low acall read_col ;read columns jb pressed, done ;check if flag is set mov keyval,#8 ;if not then read next row mov keyport,#0DFH ;make row3 low acall read_col ;read columns jb pressed, done ;check if flag is set mov keyval,#12 ;if not read row4 mov keyport,#0EFH ;make row4 low acall read_col ;read columns done: ret read_col: ;read columns routine clr pressed ;reset the flag jb col1, nextcol ;check if first key is pressed jnb col1,$ ;if yes then wait for key release setb pressed ;set the flag ret nextcol: jb col2, nextcol1 ;check if second key is pressed jnb col2,$ ;if yes then wait for key release inc keyval ;its key number 2 setb pressed ;set the flag ret nextcol1: jb col3, nextcol2 ;check if third key is pressed jnb col3,$ ;if yes then wait for key release inc keyval ;its key 3 inc keyval setb pressed ;set the flag ret nextcol2: jb col4, exit ;check if fourth key pressed jnb col4,$ ;if yes then wait for key release inc keyval ;its key 4 inc keyval inc keyval setb pressed ;set the flag ret exit: ;if no key is pressed clr pressed ;clr the flag clr keyval ;reset the number ret end now my lcd code: $MOD831 DB0 EQU P2.0 DB1 EQU P2.1 DB2 EQU P2.2 DB3 EQU P2.3 DB4 EQU P2.4 DB5 EQU P2.5 DB6 EQU P2.6 DB7 EQU P2.7 EN EQU P3.7 RS EQU P3.6 RW EQU P3.5 DATA EQU P1 ORG 0100h defineConstants: clrLCDStr: DB 01h,0FFh initLCDStr: DB 38h,0Eh,06h,0FFh LCDcursorOnline1Left: DB 60h,0FFh LCDcursorOnline2Left: DB 0C0h,0FFh titleString2a: DB 'uP SYS',0FFh ORG 0200h MAIN: CLR RS CLR RW MOV LCDBUS,01h MOV SP,#2FH LCALL defDefaultLCDCtrlSigs LCALL initialiseLCD LCALL clrLCD mainLoop: LCALL mainSub1 SJMP mainLoop ; looping forever ; subroutines defDefaultLCDCtrlSigs: MOV LCDBUS,#00h CLR RS CLR RW SETB EN RET chkLCDBusy: MOV LCDBUS,#0FF SETB RW waitBusy0: MOV A,LCDBUS JB ACC.7,waitBusy0 exitChkLCDbusy: CLR RW RET wrCmdByte2LCD: MOV LCDBUS,A CLR EN SETB EN LCALL chkLCDBusy RET wrDatByte2LCD: MOV LCDBUS,A SETB RS CLR EN SETB EN CLR RS LCALL chkLCDBusy RET initialiseLCD: MOV DPTR, #initLCDStr LCALL wrCmdStr2LCD ret clrLCD: MOV DPTR, #clrLCDStr LCALL wrCmdStr2LCD ret wrCmdStr2LCD: MOV A,#00h MOVC A,@A+DPTR wrCmdStr2LCDLoop: LCALL wrCmdByte2LCD INC DPTR MOV A,#00h MOVC A,@A+DPTR CJNE A,#0FFh,wrCmdStr2LCDLoop RET wrDatStr2LCD: MOV A,#00h MOVC A,@A+DPTR wrDatStr2LCDLoop: LCALL wrDatByte2LCD INC DPTR MOV A,#00h MOVC A,@A+DPTR CJNE A,#0FFh,wrDatStr2LCDLoop RET mainSub1: ; MOV DPTR, #titleString1a ; LCALL wrDatStr2LCD ; LCALL delay3Sec ; LCALL clrLCD LCALL Move2LCDLine2 MOV DPTR, #titleString2a LCALL wrDatStr2LCD LCALL delay3Sec LCALL clrLCD RET Move2LCDLine2: CLR RS MOV DPTR,#LCDcursorOnline2Left LCALL WRCMDSTR2LCD RET delay3Sec: MOV R7,#30 LOOP1: MOV R6,#200 LOOP2: MOV R5,#250 LOOP3: DJNZ R5,LOOP3 DJNZ R6,LOOP2 DJNZ R7,LOOP1 RET My question is how do u combine the two together to print out digits from keypad to lcd. Any help is appreciated. P.S. Not sure if keypad code is working perfectly could test it out without using lcd. |
Topic | Author | Date |
Integrating Keypad and LCD CODE | 01/01/70 00:00 | |
if you want 'micro' to answer, use e-mail | 01/01/70 00:00 | |
C Code | 01/01/70 00:00 | |
Would the C code use the same logic?? | 01/01/70 00:00 | |
same logic as what? | 01/01/70 00:00 | |
Where did all the comments go? | 01/01/70 00:00 | |
Clues | 01/01/70 00:00 | |
course lecturers have been know to lurk here![]() | 01/01/70 00:00 |