code lcd
<pre class="bbcode_code" style="margin: 0px; padding: 6px; font-family: monospace; line-height: 12px; border: 1px inset; text-align: left; overflow: scroll; direction: ltr; background-color: #f2f6f8; color: #333333; height: 372px; background-repeat: repeat no-repeat;">ORG 00H
SJMP MAIN
ORG 30H
MAIN:
MOV A,#38H ;Khoi tao LCD 2 dong va ma tran 5x7
ACALL Command
ACALL Delay
MOV A,#0EH ;Hien thi vi tri con tro
ACALL Command
ACALL Delay
MOV A,#01H ;Xoa man hinh LCD
ACALL Command
ACALL Delay
Disp_line1:
MOV A,#01H ;Xoa man hinh LCD
ACALL Command
ACALL Delay
MOV A,#80H ;Dua con tro ve dau dong thu nhat
ACALL Command
MOV DPTR,#Line1
CALL Loop
SJMP Disp_line2
Disp_line2:
MOV A,#0C0H ; Dua con tro ve dau dong thu 2
CALL Command
CALL Delay
MOV DPTR,#Line2
CALL Loop
; chon 1 trong 2 lenh duoi
; SJMP Disp_line1 ;chon lenh nay neu muon hien thi xong thi chay lai
SJMP $ ;chon lenh nay neu muon hien thi xong thi dung
Loop:
MOV A,R0
MOVC A,@A+DPTR
ACALL Display ; Goi chuong trinh hien thi
ACALL Delay
MOV A,#06H ; Dich con tro sang phai
ACALL Command
ACALL Delay
INC R0
CJNE R0,#16,Loop
MOV R0,#0
ACALL Delay
RET
Command:
ACALL Ready
MOV P2,A
CLR P3.0 ;RS=0 de gui data
CLR P3.1 ;R/W=0 de ghi data
SETB P3.2 ;E=1 chot du lieu
CLR P3.2 ;E=0
RET
Display:
ACALL Ready
MOV P2,A
SETB P3.0
CLR P3.1
SETB P3.2
CLR P3.2
RET
Delay:
MOV R3,#100
Here2:
MOV R4, # 255 ; set R4 = 255
Here:
DJNZ R4, Here ; Doi o day cho den khi R4 = 0
DJNZ R3, Here2
RET
Ready:
SETB P2.7 ;Kiem tra co ban o cong 2.7
CLR P3.0 ;RS=0 De truy cap thanh ghi lenh
SETB P3.1 ;R/W=1 Doc thanh ghi lenh
Back:
CLR P3.2 ;E=0 Chot du lieu
SETB P3.2 ;E=1
JB P2.7,Back ;Doi den khi co ban ang 0
RET
Line1: DB ' PIG_07 ' ;Cac ky tu hien o hang 1 cua LCD
Line2: DB ' K43.DDK - TNUT ' ;Cac ky tu hien o hang 2 cua LCD
;Chu y: neu cac ky tu dien vao khong du thi phai dien them dau cach
; sao cho moi dong du 16 ky tu, neu khong se hien thi sai
END</pre>
Bạn đang đọc truyện trên: AzTruyen.Top