|
单片机LCD1602显示仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
- typedef unsigned int uint;
- typedef unsigned char uchar;
- uchar xdata LCD_CW _at_ 0xfcfc;
- uchar xdata LCD_DW _at_ 0xfdfd;
- uchar xdata LCD_CR _at_ 0xfefe;
- #define WHILE_BUSY while(LCD_CR & 0x80)
- void print(uchar *str,uchar addr)
- {
- WHILE_BUSY;//不能少!!!
- LCD_CW = 0x80 | addr;
- while(*str!='\0')
- {
- WHILE_BUSY;
- LCD_DW=*str;
- str++;
- }
- }
- void main()
- {
- LCD_CW=0x0c;
- WHILE_BUSY;
- LCD_CW=0x38;
- print("LCD Disp Program",0x00);//0x00~0x0f表示第一行0到15字符
- print("Happy New Year! ",0x41);//0x40~0x4f表示第二行0到15字符
- while(1);
- }
复制代码- LCD_CW EQU 0FCFCH
- LCD_DW EQU 0FDFDH
- LCD_CR EQU 0FEFEH
-
- ORG 0000H
- LJMP LCD_INIT
- ORG 0030H
- LCD_INIT:
- MOV SP,#60H
- MOV R3,#0CH
- CALL LCD_WCMD
- MOV R3,#38H
- CALL LCD_WCMD
- MOV R1,#HELLO
- MOV R3, #80H
- CALL LCD_WCMD
- CALL PRINT
- MOV R3, #0C1H
- MOV R1,#HELLO
- CALL LCD_WCMD
- CALL PRINT
- LJMP $
- PRINT:
-
- PRINT_LOOP:
- MOV A,R1
- MOVC A,@A+DPTR
- MOV R3, A
- CALL LCD_WDAT
- INC R1
- JNZ PRINT_LOOP
- RET
- LCD_WDAT:
- MOV A, 'D'
- MOV DPTR,#LCD_DW
- MOVX @DPTR,A
- CALL WHILE_BUSY
- RET
- LCD_WCMD:
- MOV A, R3
- MOV DPTR,#LCD_CW
- MOVX @DPTR, A
- CALL WHILE_BUSY
- RET
- WHILE_BUSY:
- MOV DPTR,#LCD_CR
- MOVX A, @DPTR
- MOV 29H,A
- JB 29H.7, WHILE_BUSY
- RET
-
- HELLO:
- DB "HAPPY NEW YEAR! ",0
-
- END
复制代码 以上是两种语言编写,可选用一种
基于编址技术的LCD1602显示程序.rar
(92.93 KB, 下载次数: 14)
|
评分
-
查看全部评分
|