📄 1602 c2.lst
字号:
C51 COMPILER V6.23a 1602_C2 06/01/2008 23:44:20 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE 1602_C2
OBJECT MODULE PLACED IN 1602 C2.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 1602 C2.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //lcd1602 drive program
2 //for 51 mcu
3 //designed by zhaoliang
4 //2005-6-14 20:16
5
6 #include <at89x51.h>
7 /********************************************************************/
8 //lcd part
9 #define LINE1 0
10 #define LINE2 1
11 #define LINE1_HEAD 0x80
12 #define LINE2_HEAD 0xC0
13 #define LCD_DELAY_TIME 40
14 #define DATA_MODE 0x38
15 #define OPEN_SCREEN 0x0C
16 #define DISPLAY_ADDRESS 0x80
17 #define CLEARSCREEN LCD_en_command(0x01)
18 //common part
19 #define HIGH 1
20 #define LOW 0
21 #define TRUE 1
22 #define FALSE 0
23 #define ZERO 0
24 #define MSB 0x80
25 #define LSB 0x01
26
27 /*******************************************************************/
28 //change this part at different board
29 #define LCD1602_RW P2_0 //定义引脚
30 #define LCD1602_RS P2_1
31 #define LCD1602_EN P2_2
32 #define LCDIO P1
33
34 /********************************************************************/
35 void LCD_delay(void);//lcd delay function
36 void LCD_en_command(unsigned char command);//write command function
37 void LCD_en_dat(unsigned char temp);//write data function
38 void LCD_set_xy( unsigned char x, unsigned char y );//set display address function
39 void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character function
40 void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string function
41 void LCD_init(void);//lcd initize function
42
43 /********************************************************************/
44 void delay_nms(unsigned int n);//delay function
45
46 /********************************************************************/
47 void main(void)
48 {
49 1 LCD_init();
50 1 while(TRUE )
51 1 {
52 2 CLEARSCREEN;
53 2
54 2 delay_nms(2);
55 2 LCD_write_string(0,LINE1," LCD TEST ");
C51 COMPILER V6.23a 1602_C2 06/01/2008 23:44:20 PAGE 2
56 2 LCD_write_string(0,LINE2," SUCCESSFUL ");
57 2
58 2 delay_nms(200);
59 2
60 2 CLEARSCREEN;
61 2
62 2 delay_nms(2);
63 2 LCD_write_string(0,LINE1," lcd test ");
64 2 LCD_write_string(0,LINE2," successful ");
65 2
66 2 delay_nms(200);
67 2 }
68 1 }
69 /********************************************************************/
70 /******************** LCD PART *************************************/
71 void LCD_delay(void)
72 {
73 1 unsigned char i;
74 1 for(i=LCD_DELAY_TIME;i>ZERO;i--)//be sure lcd reset
75 1 ;
76 1 }
77 /********************************************************************/
78 void LCD_en_command(unsigned char command)
79 {
80 1 LCDIO=command;
81 1 LCD1602_RS=LOW;
82 1 LCD1602_RW=LOW;
83 1 LCD1602_EN=LOW;
84 1 LCD_delay();
85 1 LCD1602_EN=HIGH;
86 1 }
87 /********************************************************************/
88 void LCD_en_dat(unsigned char dat)
89 {
90 1 LCDIO=dat;
91 1 LCD1602_RS=HIGH;
92 1 LCD1602_RW=LOW;
93 1 LCD1602_EN=LOW;
94 1 LCD_delay();
95 1 LCD1602_EN=HIGH;
96 1 }
97 /********************************************************************/
98 void LCD_set_xy( unsigned char x, unsigned char y )
99 {
100 1 unsigned char address;
101 1 if (y == LINE1)
102 1 address = LINE1_HEAD + x;
103 1 else
104 1 address = LINE2_HEAD + x;
105 1 LCD_en_command(address);
106 1 }
107 /********************************************************************/
108 void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
109 {
110 1 LCD_set_xy( x, y );
111 1 LCD_en_dat(dat);
112 1 }
113 /********************************************************************/
114 void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
115 {
116 1 LCD_set_xy( X, Y ); //set address
117 1 while (*s) // write character
C51 COMPILER V6.23a 1602_C2 06/01/2008 23:44:20 PAGE 3
118 1 {
119 2 LCDIO=*s;
120 2 LCD_en_dat(*s);
121 2 s ++;
122 2 }
123 1 }
124 /********************************************************************/
125 void LCD_init(void)
126 {
127 1 CLEARSCREEN;//clear screen
128 1 LCD_en_command(DATA_MODE);//set 8 bit data transmission mode
129 1 LCD_en_command(OPEN_SCREEN);//open display (enable lcd display)
130 1 LCD_en_command(DISPLAY_ADDRESS);//set lcd first display address
131 1 CLEARSCREEN;//clear screen
132 1 }
133 /********************************************************************/
134 /*********************** OTHER PART *********************************/
135 void delay_nms(unsigned int n)
136 {
137 1 unsigned int i=0,j=0;
138 1 for (i=n;i>0;i--)
139 1 for (j=0;j<1140;j++);
140 1 }
141 /********************************************************************/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 232 ----
CONSTANT SIZE = 68 ----
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 + -