AT89S52并口驅(qū)動(dòng)LCD12864(ST7920芯片組)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
1.8-bit并口程序
;///////////////////////////////////////////////
;AT89S52與LCD12864接口實(shí)驗(yàn)
;LCD12864控制器為ST7920芯片組
;用12846顯示漢字
;RS-P2.4,R/W-P2.5,E-P2.6
;/RET-P2.3,PSB-P2.1,P0-DB0~DB7
;/////////////////////////////////////////////
RS EQU P2.4
RW EQU P2.5
E EQU P2.6
LDB EQU P0
LRET EQU P2.3
PSB EQU P2.1
COM EQU 40H;寫(xiě)入指令暫存器
DAT EQU 41H;顯示數(shù)據(jù)暫存器
ADDR EQU 42H;顯示地址寄存器
ORG 0000H
SJMP START
ORG 0030H
;主程序
START:MOV SP,50H
MOV P2,#10000111B
LCALL DEL40 ;
SETB LRET
LCALL RESET;LCD12864初始化
MOV ADDR,#80H;顯示第一頁(yè)數(shù)據(jù)
MOV DPTR,#DISA1
LCALL LINE
MOV ADDR,#90H
MOV DPTR,#DISA2
LCALL LINE
MOV ADDR,#88H
MOV DPTR,#DISA3
LCALL LINE
MOV ADDR,#98H
MOV DPTR,#DISA4
LCALL LINE
LCALL DEL2S
MOV ADDR,#80H;顯示第二頁(yè)數(shù)據(jù)
MOV DPTR,#DISA5
LCALL LINE
MOV ADDR,#90H
MOV DPTR,#DISA6
LCALL LINE
MOV ADDR,#88H
MOV DPTR,#DISA7
LCALL LINE
MOV ADDR,#98H
MOV DPTR,#DISA8
LCALL LINE
LCALL DEL2S
MOV ADDR,#80H;顯示第三頁(yè)數(shù)據(jù)
MOV DPTR,#DISB1
LCALL LINE
MOV ADDR,#90H
MOV DPTR,#DISB2
LCALL LINE
MOV ADDR,#88H
MOV DPTR,#DISB3
LCALL LINE
MOV ADDR,#98H
MOV DPTR,#DISB4
LCALL LINE
LCALL DEL2S
MOV ADDR,#80H;顯示第四頁(yè)數(shù)據(jù)
MOV DPTR,#DISB5
LCALL LINE
MOV ADDR,#90H
MOV DPTR,#DISB6
LCALL LINE
MOV ADDR,#88H
MOV DPTR,#DISB7
LCALL LINE
MOV ADDR,#98H
MOV DPTR,#DISB8
LCALL LINE
LCALL DEL2S
LJMP START
;函數(shù)WCOM 寫(xiě)LCD指令
WCOM: CLR RS
SETB RW
D2:MOV LDB,#0FFH
SETB E
MOV A,LDB
CLR E
JB ACC.7,D2
CLR RW
MOV A,COM
MOV LDB,A
SETB E
NOP
CLR E
RET
;函數(shù)WDAT 寫(xiě)顯示數(shù)據(jù)
WDAT: CLR RS
SETB RW
D3:MOV LDB,#0FFH
SETB E
MOV A,LDB
CLR E
JB ACC.7,D3
SETB RS
CLR RW
MOV A,DAT
MOV LDB,A
SETB E
NOP
CLR E
RET
;函數(shù)RESET LCD初始化程序
RESET:MOV COM,#00110000B;設(shè)置基本指令
LCALL WCOM
MOV COM,#00110000B;設(shè)置8bit并口
LCALL WCOM
MOV COM,#00001100B;開(kāi)顯示,關(guān)光標(biāo),關(guān)反白
LCALL WCOM
MOV COM,#00000001B;清屏,AC=0
LCALL WCOM
MOV COM,#00000110B;進(jìn)入點(diǎn)設(shè)定
LCALL WCOM
RET
;函數(shù)LINE 寫(xiě)入一行的顯示數(shù)據(jù)
LINE: MOV A,ADDR
MOV COM,A
LCALL WCOM
MOV R0,#10H
MOV R1,#00H
D1:MOV A,R1
MOVC A,@A+DPTR
MOV DAT,A
LCALL WDAT
INC R1
DJNZ R0,D1
RET
;函數(shù)DEL40 40MS延時(shí)D
DEL40:MOV R3,#10
E2:MOV R4,#100
E1:NOP
NOP
DJNZ R4,E1
DJNZ R3,E2
RET
;函數(shù)DEL2S 2S延時(shí)
DEL2S:MOV R2,#03
E5:MOV R5,#100
E4:MOV R6,#20
E3:MOV R7,#248
DJNZ R7,$
DJNZ R6,E3
DJNZ R5,E4
DJNZ R2,E5
RET
;顯示內(nèi)容區(qū)
DISA1:DB
DISA2:DB
DISA3:DB " 13210813637 "
DISA4:DB "128*64全點(diǎn)陣顯示"
DISA5:DB "圖形以及字符顯示"
DISA6:DB "2009年 7月 29 日"
DISA7:DB "設(shè)計(jì)者:趙玉慶 "
DISA8:DB "AT89C52 與ST7920"
DISB1:DB "昨夜星辰昨夜風(fēng),"
DISB2:DB "畫(huà)樓西畔桂堂東。"
DISB3:DB "身無(wú)彩鳳雙飛翼,"
DISB4:DB "心有靈犀一點(diǎn)通。"
DISB5:DB "隔座送鉤春酒暖,"
DISB6:DB "分曹射覆蠟燈紅。"
DISB7:DB "嗟余聽(tīng)鼓應(yīng)官去,"
DISB8:DB "走馬蘭臺(tái)類轉(zhuǎn)蓬。"
END