一、规划原理
运用STC89C52单片机操控1602LCD(不带中文字库的);使用1602LCD(不带中文字库的)中的存储器(64个字节00H-3FH)自树立8个5×8点阵的字符然后显现中文字符。
二、LCD1602的指令集:
1、清屏
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
00000001 |
运转时刻(250Khz):1.64ms;
功用:清DDRAM和AC值。
2、归位
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
0000001* |
运转时刻(250Khz):1.64ms;
功用:AC=0,光标、画面回HOME位。
3、输入方法设置
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
000001I/DS |
运转时刻(250Khz):40us;
功用:设置光标、画面移动方法。
其间:I/D=1:数据读、写操作后,AC主动增一;
I/D=0:数据读、写操作后,AC主动减一;
S=1:数据读、写操作,画面平移;
S=0:数据读、写操作,画面不动;
4、显现开关操控
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
00001DCB |
运转时刻(250Khz):40us;
功用:设置显现、光标及闪耀开、关。
其间:D表明显现开关:D=1为开,D=0为关;
C表明光标开关:C=1为开,C=0为关;
B表明闪耀开关:B=1为开,B=0为关。
5、光标、画面位移
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
0001S/CR/L** |
运转时刻(250Khz):40us;
功用:光标、画面移动,不影响DDRAM。
其间:S/C=1:画面平移一个字符位;
S/C=0:光标平移一个字符位;
R/L=1:右移;R/L=0:左移。
6、功用设置
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
001DLNF** |
运转时刻(250Khz):40us;
功用:工作方法设置(初始化指令)。
其间:DL=1,8位数据接口;DL=0,四位数据接口;
N=1,两行显现;N=0,一行显现;
F=1,5´10点阵字符;F=0,5´7点阵字符。
7、CGRAM地址设置
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
01A5A4A3A2A1A0 |
运转时刻(250Khz):40us;
功用:设置CGRAM地址。A5~A0=0~3FH。
8、DDRAM地址设置
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
00 |
1A6A5A4A3A2A1A0 |
运转时刻(250Khz):40us;
功用:设置DDRAM地址。
N=0,一行显现A6~A0=0~4FH;
N=1,两行显现,首行A6~A0=00H~2FH,
次行A6~A0=40H~67H。
9、读BF及AC值
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
01 |
BFAC6AC5AC4AC3AC2AC1AC0 |
功用:读忙BF值和地址计数器AC值。
其间:BF=1:忙;BF=0:准备好。
此刻,AC值含义为最近一次地址设置(CGRAM或DDRAM)界说。
10、写数据
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
10 |
数据 |
运转时刻(250Khz):40us;
功用:依据最近设置的地址性质,数据写入DDRAM或CGRAM内。
11、读数据
RSR/W |
DB7DB6DB5DB4DB3DB2DB1DB0 |
11 |
数据 |
运转时刻(250Khz):40us;
功用:依据最近设置的地址性质,从DDRRAM或CGRAM数据读出。
三、程序:
//液晶显现中文-版别0.0
//作者: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”。该段程序没来得及优化,没有充分使用单片机做重复的工作的长处;而且使代码量增大,可读较差(重复的,看起来头晕);注释少也致使可读性差!