一起玩转单片机系列(一)51单片机篇(深入浅出)
LCM_WR EQU P2.2
LCM_RD EQU P2.1
LCM_CE EQU P2.3
LCM_CD EQU P2.0
LCM_INT1 EQU P3.3
LCM_RST EQU P2.4
LCM_CMD EQU 30H
LCM_DATA EQU 31H
LCM_DATAL EQU 32H
LCM_DATAH EQU 33H
LCM_DATA1 EQU 34H
LCM_DATA2 EQU 35H
LCM_XL EQU 36H
LCM_YL EQU 37H
LCM_ADDRL EQU 38H
LCM_ADDRH EQU 39H
LCM_COUNT1 EQU 3AH
LCM_COUNT2 EQU 3BH
LCM_X EQU 3CH
LCM_Y EQU 3DH
LCM_ADL EQU 40H
LCM_ADH EQU 41H
;************************************************
ORG 0000H
AJMP MAIN
MAIN:
NOP
CLR LCM_RST ;显示屏复位
NOP
SETB LCM_RST
NOP
LCALL LCM_INIT
;************************************************
LOOP1: ;第一部分显示6个字符
;LCALL RAM_CLR
MOV DPTR,#TAB1
MOV LCM_XL,#6
MOV LCM_YL,#16
MOV LCM_ADDRL,#00H ;字符地址
MOV LCM_ADDRH,#00H
LCALL GPH_DISP
LOOP2: MOV DPTR,#TAB2 ;第二部分显示30个字符
MOV LCM_XL,#30
MOV LCM_YL,#16
MOV LCM_ADDRL,#224 ;字符地址
MOV LCM_ADDRH,#01H
LCALL GPH_DISP
LOOP3: MOV DPTR,#TAB3 ;第三部分显示24个字符
MOV LCM_XL,#24
MOV LCM_YL,#16
MOV LCM_ADDRL,#192 ;字符地址
MOV LCM_ADDRH,#03H
LCALL GPH_DISP
LOOP4: MOV DPTR,#TAB4 ;第四部分显示13个字符
MOV LCM_XL,#13
MOV LCM_YL,#16
MOV LCM_ADDRL,#167 ;字符地址
MOV LCM_ADDRH,#05H
LCALL GPH_DISP
LJMP LOOP1
;****************初始化*********************
LCM_INIT:
CLR LCM_CE
SETB LCM_WR
SETB LCM_RD
MOV LCM_DATAL,#00H
MOV LCM_DATAH,#00H
MOV LCM_CMD,#40H
LCALL WR_TD ;设置液晶屏文本首地址
MOV LCM_DATAL,#00H
MOV LCM_DATAH,#00H
MOV LCM_CMD,#42H
LCALL WR_TD ;设置液晶屏图像首地址
MOV LCM_DATAL,#1EH
MOV LCM_DATAH,#00H
MOV LCM_CMD,#41H
LCALL WR_TD ;设置文本宽度30个字节
MOV LCM_DATAL,#1EH
MOV LCM_DATAH,#00H
MOV LCM_CMD,#43H
LCALL WR_TD ;设置图像宽度 30个字节
MOV LCM_CMD,#88H
LCALL SEND_I ;文本和图像逻辑“或”
MOV LCM_DATAL,#03H
MOV LCM_DATAH,#00H
MOV LCM_CMD,#22H
LCALL WR_TD ;CGRAM偏置地址设置
MOV LCM_CMD,#9CH
LCALL SEND_I ;启用图形显示,启用文本显示
RET
GPH_DISP: ;在LCM_ADDR处画一幅LCM_XL*LCM_YL的图形
MOV LCM_COUNT1,LCM_YL
GPH_DISP1:
MOV LCM_COUNT2,LCM_XL
MOV LCM_DATAL,LCM_ADDRL
MOV LCM_DATAH,LCM_ADDRH
MOV LCM_CMD,#24H
LCALL WR_TD
GPH_DISP2:
CLR A
MOVC A,@A+DPTR
MOV LCM_DATA,A
MOV LCM_CMD,#0C0H
LCALL WR_OD ;数据写,地址加1
INC DPTR
DJNZ LCM_COUNT2,GPH_DISP2
MOV A,LCM_ADDRL ADD A,#1EH
MOV LCM_ADDRL,A MOV A,LCM_ADDRH
ADDC A,#00H
MOV LCM_ADDRH,A
DJNZ LCM_COUNT1,GPH_DISP1
LCALL DELAY1
RET
;************************************************
AUTOWR_ON: ;启用自动写方式
MOV LCM_CMD,#0B0H
LCALL SEND_I
RETAUTOWR_OFF: ;关闭自动写方式
MOV LCM_CMD,#0B2H
LCALL SEND_I
RET
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WR_TD: ;用LCM_DATAL,LCM_DATAH写数据,LCM_CMD写命令
MOV LCM_DATA,LCM_DATAL
LCALL SEND_D
MOV LCM_DATA,LCM_DATAH
LCALL SEND_D
LCALL SEND_I
RET
WR_OD: ;用LCM_DATA写数据,LCM_CMD写命令
LCALL SEND_D
LCALL SEND_I
RET
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
AUTO_WR: ;用LCM_DATA自动写数据
LCALL RD_STA
JNB ACC.3,AUTO_WR
CLR LCM_CD
SETB LCM_RD
MOV A,LCM_DATA
MOV P1,A
CLR LCM_WR
NOP
SETB LCM_WR
RET
SEND_I: ;用LCM_CMD写命令
LCALL RD_STA
JNB ACC.0,SEND_I
JNB ACC.1,SEND_I
SETB LCM_CD
SETB LCM_RD
MOV A,LCM_CMD
MOV P1,A
CLR LCM_WR
NOP
SETB LCM_WR
RET
SEND_D: ;用LCM_DATA写数据
LCALL RD_STA
JNB ACC.0,SEND_D
JNB ACC.1,SEND_D
CLR LCM_CD
SETB LCM_RD
MOV A,LCM_DATA
MOV P1,A
CLR LCM_WR
NOP
SETB LCM_WR
RET
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
RAM_CLR: ;清屏子程序
MOV LCM_DATAL,#00H
MOV LCM_DATAH,#00H
MOV LCM_CMD,#24H
LCALL WR_TD
LCALL AUTOWR_ON
MOV LCM_DATA,#00H
MOV LCM_COUNT1,#90H
RAM_CLR1:
MOV LCM_COUNT2,#14H
RAM_CLR2:
LCALL AUTO_WR
DJNZ LCM_COUNT2,RAM_CLR2
DJNZ LCM_COUNT1,RAM_CLR1
LCALL AUTOWR_OFF
RET
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;!!!!!!!!!!!!!!!!!!!!!读状态!!!!!!!!!!!!!!!!!!!!!
RD_STA:
MOV P1,#0FFH
SETB LCM_CD
SETB LCM_WR
CLR LCM_RD
NOP
MOV A,P1
SETB LCM_RD
RET
;*********************DELAY**********************
DELAY1: MOV R7,#0AH
DEL11: MOV R6,#0FFH
DEL12: MOV R5,#0FFH
DEL13: DJNZ R5,DEL13
DJNZ R6,DEL12
DJNZ R7,DEL11
RET
;************************************************
TAB1:
;-- 文字: 某 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 008H,020H,008H,020H,000H,000H,008H,020H,008H,020H,000H,000H,07FH,0FEH,07FH,0FEH
DB 000H,000H,008H,020H,008H,020H,000H,000H,00FH,0E0H,00FH,0E0H,000H,000H,008H,020H
;-- 文字: 某 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 008H,020H,000H,000H,008H,020H,008H,020H,000H,000H,00FH,0E0H,00FH,0E0H,000H,000H
DB 001H,000H,001H,000H,000H,000H,0FFH,0FEH,0FFH,0FEH,030H,000H,003H,080H,003H,080H
;-- 文字: : --
;-- Impact12
; 此字体下对应的点阵为:宽x高=16x16 --
DB 030H,000H,005H,040H,005H,040H,000H,000H,019H,030H,019H,030H,030H,000H,061H,00EH
DB 061H,00EH,030H,000H,001H,004H,001H,004H,000H,000H,001H,000H,001H,000H,000H,000H
TAB2:
;-- 文字: 第 --
;-- Impact12
; 此字体下对应的点阵为:宽x高=16x16 --
DB 010H,040H,000H,000H,001H,000H,01FH,0F0H,000H,004H,009H,000H,000H,000H,009H,000H
DB 040H,040H,006H,040H,010H,000H,002H,010H,000H,000H,008H,040H,001H,000H,01FH,07EH
;-- 文字: 一 --
;-- Impact12
; 此字体下对应的点阵为:宽x高=16x16 --
DB 000H,000H,041H,000H,010H,010H,07FH,084H,009H,080H,000H,000H,009H,080H,020H,040H
DB 038H,050H,010H,000H,041H,020H,07FH,0FCH,00CH,040H,001H,080H,028H,0A0H,000H,000H
;-- 文字: 次 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 025H,000H,010H,010H,008H,004H,011H,004H,000H,000H,011H,004H,030H,040H,008H,048H
DB 010H,000H,02FH,0FCH,000H,018H,008H,040H,001H,000H,045H,010H,000H,000H,025H,0FEH
;-- 文字: 见 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 011H,010H,012H,024H,013H,0FEH,000H,000H,013H,0FEH,020H,040H,008H,048H,03FH,07CH
DB 020H,080H,000H,060H,018H,040H,003H,000H,09FH,0F8H,000H,000H,02AH,044H,011H,010H
;-- 文字: 到 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 021H,024H,022H,004H,000H,000H,022H,004H,000H,040H,008H,040H,024H,044H,001H,000H
DB 001H,080H,010H,040H,002H,040H,000H,088H,000H,000H,00AH,048H,011H,010H,07FH,0A4H
;-- 文字: 你 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 034H,048H,000H,000H,034H,048H,000H,07CH,0FFH,0FEH,044H,044H,003H,0F0H,001H,000H
DB 030H,040H,004H,060H,01FH,0F8H,000H,004H,014H,040H,011H,010H,025H,024H,068H,040H
;-- 文字: , --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 000H,000H,068H,040H,0E0H,040H,008H,040H,084H,044H,0E2H,010H,001H,000H,057H,0FEH
DB 008H,040H,010H,080H,07FH,0FEH,010H,040H,011H,010H,004H,024H,0A2H,050H,000H,000H
;-- 文字: 你 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 0A2H,050H,020H,040H,008H,048H,07FH,044H,023H,0F0H,001H,000H,090H,040H,010H,080H
DB 010H,080H,000H,000H,020H,0C0H,012H,090H,004H,024H,023H,048H,000H,000H,023H,048H
;-- 文字: 让 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 020H,040H,00EH,028H,008H,044H,022H,010H,001H,000H,010H,040H,020H,080H,01FH,0FCH
DB 000H,000H,0E0H,0A0H,002H,080H,07FH,0A4H,022H,048H,000H,000H,022H,048H,020H,040H
;-- 文字: 我 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 038H,030H,00CH,044H,023H,0F0H,001H,000H,010H,040H,001H,000H,001H,084H,000H,000H
DB 041H,020H,004H,080H,004H,024H,024H,044H,000H,000H,024H,044H,020H,040H,0C8H,020H
;-- 文字: 知 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 00AH,044H,022H,010H,001H,000H,010H,040H,002H,010H,002H,084H,000H,000H,042H,010H
DB 004H,084H,004H,024H,024H,046H,030H,000H,024H,046H,020H,040H,008H,050H,011H,044H
;-- 文字: 道 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 023H,0F0H,001H,000H,010H,040H,004H,008H,00CH,094H,000H,000H,044H,008H,008H,084H
DB 005H,084H,028H,044H,030H,000H,028H,044H,028H,040H,009H,092H,011H,07CH,022H,010H
;-- 文字: 了 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 001H,000H,010H,040H,008H,07CH,070H,088H,000H,000H,018H,00EH,030H,086H,00EH,004H
DB 021H,040H,010H,000H,021H,040H,030H,040H,008H,00AH,020H,044H,050H,000H,001H,000H
;-- 文字: 什 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 010H,040H,01FH,0C6H,000H,080H,000H,000H,060H,004H,0C0H,07CH,070H,014H,020H,080H
DB 020H,000H,020H,080H,027H,0FEH,028H,006H,040H,040H,08FH,0FEH,005H,000H,010H,040H
;-- 文字: 么 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 000H,004H,000H,080H,000H,000H,000H,000H,000H,000H,020H,008H,000H,000H,000H,000H
DB 000H,000H,000H,000H,010H,002H,080H,000H,000H,000H,002H,000H,000H,000H,000H,000H
TAB3:
;-- 文字: 是 --
;-- Impact12
; 此字体下对应的点阵为:宽x高=16x16 --
DB 000H,000H,000H,000H,01FH,0F0H,010H,020H,020H,040H,000H,000H,006H,040H,010H,000H
DB 000H,010H,009H,000H,042H,008H,000H,000H,00FH,0F0H,000H,000H,010H,010H,010H,020H
;-- 文字: 一 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 020H,040H,000H,000H,038H,050H,010H,0FCH,000H,010H,009H,080H,021H,088H,000H,000H
DB 008H,010H,000H,000H,010H,010H,020H,020H,027H,0FCH,000H,000H,008H,048H,010H,084H
;-- 文字: 见 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 07CH,010H,011H,004H,031H,010H,000H,000H,00FH,0F0H,000H,000H,011H,010H,03DH,0FCH
DB 030H,040H,000H,000H,008H,048H,0FEH,0FCH,004H,010H,013H,0FEH,023H,0F8H,000H,000H
;-- 文字: 钟 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 008H,010H,000H,000H,011H,010H,041H,024H,0ABH,0F8H,000H,000H,008H,040H,038H,084H
DB 005H,0FEH,022H,004H,002H,008H,000H,000H,00FH,0F0H,000H,000H,011H,010H,07DH,024H
;-- 文字: 情 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 0A0H,040H,000H,000H,0FFH,0FEH,034H,0FCH,044H,010H,034H,048H,0E2H,008H,000H,000H
DB 000H,000H,000H,004H,011H,010H,091H,024H,0AFH,0FEH,000H,000H,008H,040H,054H,084H
;-- 文字: 。 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 024H,010H,068H,040H,022H,008H,000H,000H,0FFH,0FEH,07FH,0FEH,011H,010H,011H,024H
DB 020H,000H,000H,000H,008H,048H,050H,084H,019H,010H,0A2H,050H,023H,0F8H,000H,000H
;-- 文字: 我 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 001H,000H,000H,000H,012H,090H,0FDH,0FCH,023H,0F8H,000H,000H,00EH,028H,090H,0FCH
DB 008H,090H,023H,048H,022H,0A8H,000H,000H,009H,000H,000H,000H,002H,080H,010H,020H
;-- 文字: 想 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 022H,008H,000H,000H,038H,030H,000H,000H,014H,0D0H,022H,048H,020H,0A0H,030H,000H
DB 009H,0F8H,000H,000H,004H,080H,010H,020H,023H,0F8H,030H,000H,0C8H,020H,001H,000H
;-- 文字: 对 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 024H,090H,024H,044H,020H,0A0H,030H,000H,009H,000H,000H,000H,004H,084H,010H,020H
DB 022H,008H,048H,000H,008H,050H,008H,084H,022H,010H,024H,046H,029H,020H,000H,000H
;-- 文字: 你 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 015H,000H,000H,000H,008H,084H,010H,020H,023H,0F8H,048H,000H,009H,092H,028H,082H
DB 042H,010H,028H,044H,031H,022H,030H,000H,023H,000H,000H,000H,030H,086H,014H,020H
;-- 文字: 说 --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 022H,008H,030H,000H,008H,00AH,028H,012H,080H,010H,021H,040H,022H,022H,030H,000H
DB 040H,0FEH,000H,000H,0C0H,07CH,018H,020H,022H,028H,000H,000H,028H,006H,067H,0F0H
;-- 文字: : --;-- Impact12; 此字体下对应的点阵为:宽x高=16x16 --
DB 000H,050H,020H,080H,004H,01EH,000H,000H,000H,000H,000H,000H,000H,000H,010H,020H
DB 022H,010H,000H,000H,010H,002H,000H,000H,000H,020H,000H,000H,008H,000H,000H,000H
TAB4:
;-- 文字: I --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
;-- 文字: --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
;-- 文字: L --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 000H,000H,000H,000H,000H,000H,000H,07CH,000H,0E0H,000H,0C6H,000H,0E7H,0FCH,000H
;-- 文字: --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 0EEH,038H,0E7H,010H,010H,000H,040H,001H,0EFH,000H,042H,042H,000H,044H,044H,042H
;-- 文字: O --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 010H,010H,000H,040H,003H,0FFH,080H,042H,048H,000H,044H,082H,042H,010H,010H,000H
;-- 文字: --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 040H,007H,0FFH,0C0H,044H,048H,000H,028H,082H,042H,010H,010H,000H,040H,007H,0FFH
;-- 文字: V --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 0C0H,024H,078H,000H,028H,082H,042H,010H,010H,000H,040H,003H,0FFH,080H,024H,048H
;-- 文字: E --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 000H,010H,082H,042H,010H,010H,000H,040H,001H,0FFH,000H,028H,048H,000H,010H,082H
;-- 文字: --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 042H,010H,010H,000H,040H,000H,0FEH,000H,028H,040H,000H,010H,082H,042H,000H,010H
;-- 文字: Y --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 000H,040H,000H,07CH,000H,018H,042H,000H,010H,082H,042H,000H,010H,000H,042H,000H
;-- 文字: O --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 038H,000H,010H,042H,000H,010H,044H,042H,018H,07CH,000H,0FEH,000H,010H,000H,010H
;-- 文字: U --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 0FCH,000H,038H,038H,03CH,018H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
;-- 文字: ! --;-- Impact12; 此字体下对应的点阵为:宽x高=8x16 --
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
END