//作者:pcdian //定义液晶的一些功能位
//RS 为数据、指令寄存器选择位
//RW 为读写选择位
//E 为使能位
RS BIT p2.5
RW BIT P2.6
E BIT P2.7
ORG 0000H
SJMP START
ORG 000BH
LJMP Timer_IT
ORG 0030H
START:MOV SP,#60H
MOV TMOD,#01H
MOV TH0,#0A6H
MOV TL0,#00H
SETB EA
SETB ET0
CLR TR0
MAIN:MOV P0,#01H //清屏
ACALL ENABLE
MOV P0,#38H //显示模式设置为16字*2行
ACALL ENABLE
MOV P0,#0CH //不显示光标
ACALL ENABLE
MOV P0,#06H //显示方向正向且屏不移动
ACALL ENABLE
DISPLAY:ACALL DISPLAY_C0
//我
MOV P0,#80H
ACALL ENABLE
MOV P0,#00H
ACALL WRITE
MOV P0,#81H
ACALL ENABLE
MOV P0,#01H
ACALL WRITE
MOV P0,#82H
ACALL ENABLE
MOV P0,#02H
ACALL WRITE
MOV P0,#0C0H
ACALL ENABLE
MOV P0,#03H
ACALL WRITE
MOV P0,#0C1H
ACALL ENABLE
MOV P0,#04H
ACALL WRITE
MOV P0,#0C2H
ACALL ENABLE
MOV P0,#05H
ACALL WRITE
LCALL DELAY1S
MOV P0,#01H
ACALL ENABLE
ACALL DISPLAY_C1
//们
MOV P0,#83H
ACALL ENABLE
MOV P0,#00H
ACALL WRITE
MOV P0,#84H
ACALL ENABLE
MOV P0,#01H
ACALL WRITE
MOV P0,#85H
ACALL ENABLE
MOV P0,#02H
ACALL WRITE
MOV P0,#0C3H
ACALL ENABLE
MOV P0,#03H
ACALL WRITE
MOV P0,#0C4H
ACALL ENABLE
MOV P0,#04H
ACALL WRITE
MOV P0,#0C5H
ACALL ENABLE
MOV P0,#05H
ACALL WRITE
LCALL DELAY1S
MOV P0,#01H
ACALL ENABLE
ACALL DISPLAY_C2
//的
MOV P0,#86H
ACALL ENABLE
MOV P0,#00H
ACALL WRITE
MOV P0,#87H
ACALL ENABLE
MOV P0,#01H
ACALL WRITE
MOV P0,#88H
ACALL ENABLE
MOV P0,#02H
ACALL WRITE
MOV P0,#0C6H
ACALL ENABLE
MOV P0,#03H
ACALL WRITE
MOV P0,#0C7H
ACALL ENABLE
MOV P0,#04H
ACALL WRITE
MOV P0,#0C8H
ACALL ENABLE
MOV P0,#05H
ACALL WRITE
LCALL DELAY1S
MOV P0,#01H
ACALL ENABLE
ACALL DISPLAY_C3
//0
MOV P0,#89H
ACALL ENABLE
MOV P0,#00H
ACALL WRITE
MOV P0,#8AH
ACALL ENABLE
MOV P0,#01H
ACALL WRITE
MOV P0,#0C9H
ACALL ENABLE
MOV P0,#02H
ACALL WRITE
MOV P0,#0CAH
ACALL ENABLE
MOV P0,#03H
ACALL WRITE
LCALL DELAY1S
MOV P0,#01H
ACALL ENABLE
ACALL DISPLAY_C4
//7
MOV P0,#8BH
ACALL ENABLE
MOV P0,#00H
ACALL WRITE
MOV P0,#8CH
ACALL ENABLE
MOV P0,#01H
ACALL WRITE
MOV P0,#0CBH
ACALL ENABLE
MOV P0,#02H
ACALL WRITE
MOV P0,#0CCH
ACALL ENABLE
MOV P0,#03H
ACALL WRITE
//3
MOV P0,#8DH
ACALL ENABLE
MOV P0,#04H
ACALL WRITE
MOV P0,#8EH
ACALL ENABLE
MOV P0,#05H
ACALL WRITE
MOV P0,#0CDH
ACALL ENABLE
MOV P0,#06H
ACALL WRITE
MOV P0,#0CEH
ACALL ENABLE
MOV P0,#07H
ACALL WRITE
LCALL DELAY1S
MOV P0,#01H
ACALL ENABLE
LJMP DISPLAY
DISPLAY_C0:MOV DPTR,#TAB0
MOV R2,#48
ACALL DISPLAY_C
RET
DISPLAY_C1:MOV DPTR,#TAB1
MOV R2,#48
ACALL DISPLAY_C
RET
DISPLAY_C2:MOV DPTR,#TAB2
MOV R2,#48
ACALL DISPLAY_C
RET
DISPLAY_C3:MOV DPTR,#TAB3
MOV R2,#32
ACALL DISPLAY_C
RET
DISPLAY_C4:MOV DPTR,#TAB4
MOV R2,#64
ACALL DISPLAY_C
RET
DISPLAY_C:MOV P0,#40H
ACALL ENABLE
MOV R3,#0
DISPLAY_CC:MOV A,R3
MOVC A,@A+DPTR
MOV P0,A
LCALL WRITE
INC R3
DJNZ R2,DISPLAY_CC
RET
ENABLE:
CLR RS
CLR RW
CLR E
ACALL DELAY
SETB E
RET
WRITE:
SETB RS
CLR RW
CLR E
ACALL DELAY
SETB E
RET
DELAY1S:SETB TR0
CJNE R0,#20,DELAY1S
CLR TR0
MOV R0,#0
RET
DELAY:MOV R5,#08H
L1:MOV R4,#0FAH
L0:DJNZ R4,L0
DJNZ R5,L1
RET
Timer_IT:MOV TH0,#0A6H
MOV TL0,#00H
INC R0
RETI
TAB0: //我
DB 0x00,0x07,0x01,0x01,0x01,0x1F,0x01,0x01
DB 0x19,0x01,0x01,0x01,0x01,0x1F,0x01,0x01
DB 0x00,0x08,0x04,0x04,0x00,0x1F,0x00,0x04
DB 0x01,0x07,0x19,0x01,0x01,0x01,0x05,0x02
DB 0x18,0x00,0x00,0x01,0x06,0x00,0x00,0x00
DB 0x14,0x18,0x10,0x08,0x09,0x05,0x03,0x01
TAB1: //们
DB 0x01,0x01,0x02,0x02,0x06,0x04,0x0c,0x14
DB 0x08,0x04,0x06,0x04,0x10,0x10,0x10,0x10
DB 0x00,0x00,0x1e,0x02,0x02,0x02,0x02,0x02
DB 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00
DB 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00
DB 0x02,0x02,0x02,0x02,0x02,0x0a,0x04,0x00
TAB2: //的
DB 0x02,0x02,0x04,0x0f,0x08,0x08,0x08,0x0f
DB 0x02,0x02,0x02,0x13,0x14,0x14,0x18,0x12
DB 0x00,0x00,0x00,0x1e,0x02,0x02,0x02,0x02
DB 0x08,0x08,0x08,0x08,0x0f,0x08,0x08,0x00
DB 0x11,0x11,0x10,0x10,0x10,0x10,0x00,0x00
DB 0x02,0x12,0x12,0x02,0x02,0x14,0x08,0x00
TAB3: //0
DB 0x00,0x00,0x03,0x04,0x08,0x08,0x08,0x08
DB 0x00,0x00,0x18,0x04,0x02,0x02,0x02,0X02
DB 0x08,0x08,0x08,0x08,0x04,0x03,0x00,0x00
DB 0x02,0x02,0x02,0x02,0x04,0x18,0x00,0x00
TAB4: //7
DB 0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00
DB 0x00,0x00,0x1E,0x1E,0x06,0x06,0x06,0X06
DB 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
DB 0x06,0x06,0x06,0x06,0x06,0x06,0x00,0x00
//3
DB 0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F
DB 0x00,0x00,0x1E,0x1E,0x06,0x06,0x06,0X1E
DB 0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00
DB 0x1E,0x06,0x06,0x06,0x1E,0x1E,0x00,0x00
END
四、总结:
虽然LCD1602可以利用自建字符显示中文,但最多不能超过8个字符位。所以实际应用中,无法同时显示“我们的073”。该段程序没来得及优化,没有充分利用单片机做重复的事情的优点;并且使代码量增大,可读较差(重复的,看起来头晕);注释少也致使可读
性差!
因篇幅问题不能全部显示,请点此查看更多更全内容