Cơ bản quét bàn phím 4x4 matrix hiển thị LCD 16x2
https://www.youtube.com/watch?v=66Oa3yP6PaQ
https://www.facebook.com/download/1587336481488507/4X4SCAN_LCD.rar
. Bạn chú ý ví dụ trên chỉ là đọc phím sau đó xuất ra màn hình chứ chưa phải là máy tính để tính toán nhé!
HANG DATA P1
COT DATA P2
RS BIT P3.0
EN BIT P3.1
LCD_DATA DATA P3
TEMP DATA 30H
ORG 0
;------------- KHOI TAO LCD ------------
MAIN10:
MOV LCD_DATA,#20H
CLR RS
SETB EN
NOP
CLR EN
LCALL DELAY100MS
;----- KHOI TAO TRUYEN 4 BIT DATA -------------
MOV A,#28H
LCALL WRITE4CMD
MOV A,#0CH
LCALL WRITE4CMD
MOV A,#01H
LCALL WRITE4CMD
MOV A,#06H
LCALL WRITE4CMD
;----------- XONG KHOI TAO CAU HINH --------------------
;---------- LINE 1 -------------
MOV A,#80H
LCALL WRITE4CMD
MOV A,#'B'
LCALL WRITE4DT
MOV A,#'a'
LCALL WRITE4DT
MOV A,#'n'
LCALL WRITE4DT
MOV A,#' '
LCALL WRITE4DT
MOV A,#'d'
LCALL WRITE4DT
MOV A,#'a'
LCALL WRITE4DT
MOV A,#'n'
LCALL WRITE4DT
MOV A,#'g'
LCALL WRITE4DT
MOV A,#' '
LCALL WRITE4DT
MOV A,#'a'
LCALL WRITE4DT
MOV A,#'n'
LCALL WRITE4DT
MOV A,#' '
LCALL WRITE4DT
MOV A,#'s'
LCALL WRITE4DT
MOV A,#'o'
LCALL WRITE4DT
MOV A,#':'
LCALL WRITE4DT
;----------------------------
;----------- CHO NHA? PHIM BAM ---------------
MAIN1:
MOV HANG,#00
MOV A,COT
ANL A,#0FH
CJNE A,#0FH,MAIN1
MAIN12:
CALL DELAY20MS
MOV A,COT
ANL A,#0FH
CJNE A,#0FH,DUOCNHAN
SJMP MAIN12
DUOCNHAN:
CALL DELAY20MS
MOV A,COT
ANL A,#0FH
CJNE A,#0FH,KIEMTRACOT
SJMP MAIN12
KIEMTRACOT:
MOV HANG,#0FEH
MOV A,COT
ANL A,#0FH
CJNE A,#0FH,SCAN_R0
MOV HANG,#0FDH
MOV A,COT
ANL A,#0FH
CJNE A,#0FH,SCAN_R1
MOV HANG,#0FBH
MOV A,COT
ANL A,#0FH
CJNE A,#0FH,SCAN_R2
MOV HANG,#0F7H
MOV A,COT
ANL A,#0FH
CJNE A,#0FH,SCAN_R3
LJMP MAIN12
SCAN_R0:
MOV DPTR,#MAHANG0
LCALL SCAN
LJMP MAIN1
SCAN_R1:
MOV DPTR,#MAHANG1
LCALL SCAN
LJMP MAIN1
SCAN_R2:
MOV DPTR,#MAHANG2
LCALL SCAN
LJMP MAIN1
SCAN_R3:
MOV DPTR,#MAHANG3
LCALL SCAN
LJMP MAIN1
SCAN:
RRC A
JNC MATCH
INC DPTR
SJMP SCAN
MATCH:
MOV A,#0CEH
LCALL WRITE4CMD
CLR A
MOVC A,@A+DPTR
LCALL WRITE4DT
RET
WRITE4CMD:
MOV TEMP,A
ANL A,#0F0H
MOV LCD_DATA,A
CLR RS
SETB EN
NOP
CLR EN
CALL DELAY5MS
MOV A,TEMP
SWAP A
ANL A,#0F0H
MOV LCD_DATA,A
CLR RS
SETB EN
NOP
CLR EN
CALL DELAY5MS
RET
WRITE4DT:
MOV TEMP,A
ANL A,#0F0H
MOV LCD_DATA,A
SETB RS
SETB EN
NOP
CLR EN
CALL DELAY5MS
MOV A,TEMP
SWAP A
ANL A,#0F0H
MOV LCD_DATA,A
SETB RS
SETB EN
NOP
CLR EN
CALL DELAY5MS
RET
DELAY5MS:
PUSH 007H
PUSH 006H
PUSH 005H
MOV R7,#5
DL2: MOV R6,#5
DL3: MOV R5,#98
DL4: DJNZ R5,DL4
DJNZ R6,DL3
DJNZ R7,DL2
POP 005H
POP 006H
POP 007H
RET
DELAY20MS:
PUSH 007H
PUSH 006H
PUSH 005H
MOV R7,#5
D1: MOV R6,#10
D2: MOV R5,#80
D3: NOP
NOP
NOP
DJNZ R5,D3
DJNZ R6,D2
DJNZ R7,D1
POP 005H
POP 006H
POP 007H
RET
DELAY100MS:
MOV R4,#5
DL1:
CALL DELAY20MS
DJNZ R4,DL1
RET
ORG 300H
MAHANG0: DB 'C','0','=','+'
MAHANG1: DB '1','2','3','-'
MAHANG2: DB '4','5','6','X'
MAHANG3: DB '7','8','9','/'
END
0 nhận xét:
Đăng nhận xét