You are on page 1of 3

/*------------------------------------------------------*/ /* M-Project: 8051 vs LCD 16x2 (8bit) */ /* Date: 13/12/2011 */ /* Hw: AT89C52 /* LCD 16x2 (8bit) */ /* Crystal 12MHz

*/ /*------------------------------------------------------*/ /*-----------------Pig.07k43@gmail.com------------------*/ ORG 00H SJMP MAIN ORG 30H MAIN: MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL A,#38H Command Delay A,#0EH Command Delay A,#01H Command Delay

*/

;Khoi tao LCD 2 dong va ma tran 5x7 ;Hien thi vi tri con tro ;Xoa man hinh LCD

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 MOVCA,@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 SETB P3.2 JB RET P3.2 ;E=1 P2.7,Back ;E=0 Chot du lieu ;Doi den khi co ban ang 0

Line1: DB ' VDK 8051

' ;Cac ky tu hien o hang 1 cua LCD

Line2: DB ' LOP CDT K35 ' ;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