📄 lcd.lst
字号:
C51 COMPILER V8.05a LCD 01/11/2009 22:55:15 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE LCD
OBJECT MODULE PLACED IN lcd.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lcd.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <main.h>
2
3 /*
4
5 LCD_
6 RS <P4.0>
7 WR <P4.1>
8 E <P4.2>
9 要求:P4.0,4.1,4.2设置为推拉输出;
10 P5口设置为带弱上拉的漏极输出,3.3V电平标准即可
11
12 */
13
14 unsigned char code dig[]={"0123456789"};
15
16 void lcd_delay()
17 { unsigned char delayTime;
18 1 for(delayTime=100;delayTime>0;delayTime--);
19 1 }
20
21 /* 返回值Status: 当前地址计数器的值. */
22 unsigned char LCDBusyWait() //等待LCD就绪
23 {
24 1 unsigned char Status;
25 1 P4&=0xfe; //11111110,LCD_RS=0
26 1 lcd_delay();
27 1
28 1 P4|=0x02;//00000010,LCD_RW=1
29 1 lcd_delay();
30 1
31 1 P5 = 0xFF;
32 1 P4|=0x04;//00000100,LCD_E=1
33 1
34 1 lcd_delay();
35 1 Status=P5;
36 1 P4&=0xfB;//11111011,LCD_E=0
37 1
38 1 while(Status & 0x80)
39 1 {
40 2 lcd_delay();
41 2 P4|=0x04;//00000100,LCD_E=1
42 2 lcd_delay();
43 2 Status=P5;
44 2 lcd_delay();
45 2 P4&=0xfB;//11111011,LCD_E=0
46 2
47 2 }
48 1 P4&=0xfd;//11111101,LCD_RW=0
49 1
50 1 return Status;
51 1 }
52
53 void WriteLCD_Data(unsigned char Data) //向LCD写入一个字节的数据
54 {
55 1 LCDBusyWait();
C51 COMPILER V8.05a LCD 01/11/2009 22:55:15 PAGE 2
56 1 P4|=0x01;//00000001,LCD_RW=0,LCD_RS=1
57 1
58 1 lcd_delay();
59 1 P5 = Data;
60 1 lcd_delay();
61 1 P4|=0x04;//00000100,LCD_E=1
62 1
63 1 lcd_delay();
64 1 P4&=0xfB;//11111011,LCD_E=0
65 1
66 1 }
67
68 void WriteLCD_Command(unsigned char Command) //向LCD写入一个字节的命令
69 {
70 1 LCDBusyWait();
71 1 P4&=0xFE;//11111110,LCD_RS=0
72 1
73 1 lcd_delay();
74 1 P5 = Command;
75 1 lcd_delay();
76 1 P4|=0x04;//00000100,LCD_E=1
77 1
78 1 lcd_delay();
79 1 P4&=0xfB;//11111011,LCD_E=0
80 1
81 1 }
82
83 //改变地址,实现了逐行显示
84 unsigned char ChangeAddress(unsigned char StartAddress)
85 {
86 1 switch(StartAddress)
87 1 {
88 2 case 0x87:WriteLCD_Command(0x90);StartAddress=0x90;break;
89 2 case 0x8F:WriteLCD_Command(0x98);StartAddress=0x98;break;
90 2 case 0x97:WriteLCD_Command(0x88);StartAddress=0x88;break;
91 2 default:StartAddress+=1;
92 2 }
93 1 return StartAddress;
94 1 }
95
96 /*****************************显示字符串***************************************/
97
98 void WriteLCD(unsigned char StartAddress,unsigned char Size,unsigned char Charactors[])
99 {
100 1 unsigned char *i=Charactors; //字符串的首地址
101 1 WriteLCD_Command(StartAddress);
102 1 if(Size) //Size不为0
103 1 {
104 2 // bit Over=0;
105 2 while(i<(Charactors+Size)) //判断字符串结尾
106 2 {
107 3
108 3 WriteLCD_Data(*i);
109 3 i++;
110 3 //WriteLCD_Data(*i);
111 3 //i++;
112 3 StartAddress=ChangeAddress(StartAddress); //改变地址,实现了逐行显示
113 3 }
114 2 }
115 1 else //Size为0
116 1 {
117 2 while(*i) //判断字符串结尾,*i为0代表结束
C51 COMPILER V8.05a LCD 01/11/2009 22:55:15 PAGE 3
118 2 {
119 3 WriteLCD_Data(*i);
120 3 i++;
121 3 WriteLCD_Data(*i);
122 3 i++;
123 3 StartAddress=ChangeAddress(StartAddress);
124 3 }
125 2 }
126 1 }
127 /****************************显示数字********************************/
128
129 void Show_num(unsigned char address,unsigned int num)
130 {
131 1 unsigned char k,j,i=0;
132 1 unsigned char w_data[10];
133 1 WriteLCD_Command(address);
134 1 //WriteLCD(0x90,0," ");
135 1 do
136 1 {
137 2 w_data[i++]=num%10;
138 2 num=num/10;
139 2 j=i;
140 2 }while(num!=0);
141 1
142 1 for(k=j;k>0;k--)
143 1 {
144 2 WriteLCD_Data(dig[w_data[k-1]]);
145 2 }
146 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 332 ----
CONSTANT SIZE = 11 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 18
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 + -