📄 液晶.lst
字号:
C51 COMPILER V7.02a 襙__ 05/19/2007 08:51:53 PAGE 1
C51 COMPILER V7.02a, COMPILATION OF MODULE 襙__
OBJECT MODULE PLACED IN 液晶.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 液晶.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //lcd1602 drive program
2 //for 51 mcu
3 //designed by xiaorunyi
4 //2007-5-14 20:16
5 #include <reg51.h>
6 /*******************************************************************/
7 //lcd part
8 #define LINE1 0
9 #define LINE2 1
10 #define LINE1_HEAD 0x80
11 #define LINE2_HEAD 0xC0
12 #define LCD_DELAY_TIME 40
13 #define DATA_MODE 0x38
14 #define OPEN_SCREEN 0x0C
15 #define DISPLAY_ADDRESS 0x80
16 #define CLEARSCREEN LCD_en_command(0x01)
17 //common part
18 #define HIGH 1
19 #define LOW 0
20 #define TRUE 1
21 #define FALSE 0
22 #define ZERO 0
23 #define MSB 0x80
24 #define LSB 0x01
25
26 /*******************************************************************/
27 //change this part at different board
28 #define LCDIO P0
29 sbit LCD1602_RS=P1^2; //data command select 1 data 0 command pin 4
30 sbit LCD1602_RW=P1^1; //read write select 1 read 0 write pin 5
31 sbit LCD1602_EN=P1^0; //LCD enable signal pin 6
32
33 /********************************************************************/
34 void LCD_delay(void);//lcd delay function
35 void LCD_en_command(unsigned char command);//write command function
36 void LCD_en_dat(unsigned char temp);//write data function
37 void LCD_set_xy( unsigned char x, unsigned char y );//set display address function
38 void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character function
39 void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string function
40 void LCD_init(void);//lcd initize function
41
42 /********************************************************************/
43 void delay_nms(unsigned int n);//delay function
44
45 /********************************************************************/
46 void main(void)
47 {
48 1 LCD_init();
49 1 while(TRUE )
50 1 {
51 2 CLEARSCREEN;
52 2
53 2 delay_nms(2);
54 2 LCD_write_string(0,LINE1," LCD TEST ");
55 2 LCD_write_string(0,LINE2," XIAORUNYI ");
C51 COMPILER V7.02a 襙__ 05/19/2007 08:51:53 PAGE 2
56 2
57 2 delay_nms(200);
58 2
59 2 CLEARSCREEN;
60 2
61 2 delay_nms(2);
62 2 LCD_write_string(0,LINE1," lcd test ");
63 2 LCD_write_string(0,LINE2," xiaorunyi ");
64 2
65 2 delay_nms(200);
66 2 }
67 1 }
68 /********************************************************************/
69 /******************** LCD PART *************************************/
70 void LCD_delay(void)
71 {
72 1 unsigned char i;
73 1 for(i=LCD_DELAY_TIME;i>ZERO;i--)//be sure lcd reset
74 1 ;
75 1 }
76 /********************************************************************/
77 void LCD_en_command(unsigned char command)
78 {
79 1 LCD_delay();
80 1 LCD1602_RS=LOW;
81 1 LCD1602_RW=LOW;
82 1 LCD1602_EN=HIGH;
83 1 LCDIO=command;
84 1 LCD1602_EN=LOW;
85 1 }
86 /********************************************************************/
87 void LCD_en_dat(unsigned char dat)
88 {
89 1 LCD_delay();
90 1 LCD1602_RS=HIGH;
91 1 LCD1602_RW=LOW;
92 1 LCD1602_EN=HIGH;
93 1 LCDIO=dat;
94 1 LCD1602_EN=LOW;
95 1 }
96 /********************************************************************/
97 void LCD_set_xy( unsigned char x, unsigned char y )
98 {
99 1 unsigned char address;
100 1 if (y == LINE1)
101 1 address = LINE1_HEAD + x;
102 1 else
103 1 address = LINE2_HEAD + x;
104 1 LCD_en_command(address);
105 1 }
106 /********************************************************************/
107 void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
108 {
109 1 LCD_set_xy( x, y );
110 1 LCD_en_dat(dat);
111 1 }
112 /********************************************************************/
113 void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
114 {
115 1 LCD_set_xy( X, Y ); //set address
116 1 while (*s) // write character
117 1 {
C51 COMPILER V7.02a 襙__ 05/19/2007 08:51:53 PAGE 3
118 2 LCDIO=*s;
119 2 LCD_en_dat(*s);
120 2 s ++;
121 2 }
122 1 }
123 /********************************************************************/
124 void LCD_init(void)
125 {
126 1 CLEARSCREEN;//clear screen
127 1 LCD_en_command(DATA_MODE);//set 8 bit data transmission mode
128 1 LCD_en_command(OPEN_SCREEN);//open display (enable lcd display)
129 1 LCD_en_command(DISPLAY_ADDRESS);//set lcd first display address
130 1 CLEARSCREEN;//clear screen
131 1 }
132 /********************************************************************/
133 /*********************** OTHER PART *********************************/
134 void delay_nms(unsigned int n)
135 {
136 1 unsigned int i=0,j=0;
137 1 for (i=n;i>0;i--)
138 1 for (j=0;j<1140;j++);
139 1 }
140 /********************************************************************/
141
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 234 ----
CONSTANT SIZE = 66 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -