?? lcd1602.lst
字號:
C51 COMPILER V6.23a LCD1602 10/25/2008 20:27:53 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE LCD1602
OBJECT MODULE PLACED IN LCD1602.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD1602.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <AT89X52.H>
2 #include <intrins.h>
3 //#define LCD1602VAR
4 #include "LCD1602.H"
5 #define NOP() _nop_();_nop_();_nop_();_nop_();_nop_();
6 #if CustomCharCount
7 unsigned char code CustomChar[CustomCharCount][8]=
8 {
9 {0x08,0x0F,0x12,0x0F,0x0A,0x1F,0x02,0x02},//年0
10 {0x00,0x0F,0x09,0x0F,0x09,0x0F,0x09,0x11},//月1
11 {0x00,0x0F,0x09,0x09,0x0F,0x09,0x09,0x0F},//日2
12 {0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00},//一3
13 {0x00,0x00,0x0E,0x00,0x00,0x1F,0x00,0x00},//二4
14 {0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x00},//三5
15 {0x1F,0x13,0x1D,0x11,0x1D,0x13,0x1F,0x00},//四6
16 {0x00,0x1F,0x08,0x1F,0x09,0x0A,0x0A,0x1F} //五7
17 };
18 #endif
19 /*************************************************
20 * 函數說明:讀取AC地址 *
21 * 輸出參數: unsigned char AC: 表示AC地址
22 **************************************************/
23 #if LCD_EN_readBFAC
24 unsigned char LCDreadBFAC(void)
25 {
26 1 unsigned char redata;
27 1 #if LCD_DL<8
28 1 unsigned char temp;
29 1 #endif
30 1
31 1 LCD_RS=0;//選擇指令寄存器
32 1 NOP();
33 1 LCD_RW=1;//讀取指令寄存器
34 1 NOP();
35 1 #if LCD_DL>4
LCD_Data_Port=0xff;
LCD_EN=1;
NOP();
redata=LCD_Data_Port;
#else
41 1 LCD_Data_Port=LCD_Data_Port | 0xf0;
42 1 LCD_EN=1;
43 1 NOP();
44 1 redata=LCD_Data_Port;
45 1 LCD_EN=0;
46 1 redata=redata & 0xf0;
47 1 NOP();
48 1
49 1 LCD_EN=1;
50 1 NOP();
51 1 temp=LCD_Data_Port;
52 1 LCD_EN=0;
53 1 temp=temp>>4;
54 1 temp=temp & 0xf;
55 1 redata=redata | temp;
C51 COMPILER V6.23a LCD1602 10/25/2008 20:27:53 PAGE 2
56 1 #endif
57 1
58 1 return (redata);
59 1 }
60 #endif
61
62 /*************************************************
63 * 函數說明:等等LCD16B20空閑 *
64 **************************************************/
65 #if LCD_EN_waitForReady
66 void LCDwaitForReady(void)
67 {
68 1 unsigned char i,re;
69 1 i=100;
70 1 do
71 1 {
72 2 re=LCDreadBFAC();
73 2 if((re & 0x80)==0)
74 2 break;
75 2 } while(i--!=0);
76 1 }
77 #endif
78
79
80 /********************************************************
81 * 函數說明:向LCD發送指令函數 *
82 * 輸入: 需要發送的指令 *
83 ********************************************************/
84 #if LCD_EN_SendCommand
85 void LCDSendCommand(unsigned char Command)
86 {
87 1 #if LCD_DL<8
88 1 unsigned char order;
89 1 #endif
90 1
91 1 LCDwaitForReady();
92 1 LCD_RS=0;//選擇指令寄存器
93 1 NOP();
94 1 LCD_RW=0;//MCU向LCD寫入命令數據
95 1 NOP();
96 1
97 1 #if LCD_DL>4
LCD_Data_Port=Command;
NOP();
LCD_EN=1;
NOP();
LCD_EN=0;
#else
104 1 {
105 2 order=Command;
106 2 order=order & 0xf0;
107 2 LCD_Data_Port=LCD_Data_Port & 0xf;
108 2 LCD_Data_Port=LCD_Data_Port | order;
109 2 NOP();
110 2 LCD_EN=1;
111 2 NOP();
112 2 LCD_EN=0;
113 2 order=Command;
114 2 order=order & 0xf;
115 2 order=order << 4;
116 2 LCD_Data_Port=LCD_Data_Port & 0xf;
117 2 LCD_Data_Port=LCD_Data_Port | order;
C51 COMPILER V6.23a LCD1602 10/25/2008 20:27:53 PAGE 3
118 2 NOP();
119 2 LCD_EN=1;
120 2 NOP();
121 2 LCD_EN=0;
122 2 }
123 1 #endif
124 1 }
125 #endif
126
127
128 /*********************************************************************
129 * 函數說明:LCD清屏,DD RAM的內容被清除,光標回到左上角原點,AC=0 *
130 **********************************************************************/
131 #if LCD_EN_clear
132 void LCDclear(void)
133 {
134 1 LCDSendCommand(0x1);
135 1 }
136 #endif
137
138
139 /*******************************************************************************
140 * 函數說明:LCD軟復位,DD RAM的內容不變,但光標和光標所在的字符回到左上角原點 *
141 ********************************************************************************/
142 #if LCD_EN_goHome
void LCDgoHome(void)
{
LCDSendCommand(0x2);
}
#endif
148
149 /********************************************************
150 * 函數說明:輸入方式設置,設置光標、畫面移動方式 *
151 * 輸入參數: bit I_D:表示讀寫之后AC情況,I_D=1 *
152 * 表示AC+1;I_D=0表示AC-1; *
153 * bit S: 表示畫面是否移動,S=1表示 *
154 * 畫面平移;S=0表示畫面不動 *
155 ********************************************************/
156 /*
157 當S=1且數據寫入DD RAM中時候,顯示將全部左邊移動(I_D=1),或者全部右邊移動(I_D=0),即光標不移動
158 當S=0,畫面不動,光標移動(左邊移動:I_D=0,右邊移動:I_D=1)
159 */
160 #if LCD_EN_setInputModel
161 void LCDsetInputModel(bit I_D,bit S)
162 {
163 1 unsigned char order;
164 1 order=0x4;
165 1 if(I_D)
166 1 order=order+0x2;
167 1 if(S)
168 1 order=order+0x1;
169 1 LCDSendCommand(order);
170 1 }
171 #endif
172
173
174 /***************************************************************
175 * 函數說明:顯示模式設置,設置畫面、光標以及光標是否閃爍開關 *
176 * 輸入參數: bit D: 表示畫面是否顯示 *
177 * bit C: 表示光標是否顯示 *
178 * bit B: 表示光標是否閃爍 *
179 ****************************************************************/
C51 COMPILER V6.23a LCD1602 10/25/2008 20:27:53 PAGE 4
180 #if LCD_EN_setDisplayModel
181 void LCDsetDisplayModel(bit D,bit C,bit B)
182 {
183 1 unsigned char order;
184 1 order=0x8;
185 1 if(D)
186 1 order=order+0x4;
187 1 if(C)
188 1 order=order+0x2;
189 1 if(B)
190 1 order=order+0x1;
191 1 LCDSendCommand(order);
192 1 }
193 #endif
194
195
196 //畫面和光標一起右邊移動n個字符位置
197 #if LCD_EN_shiftRight
void LCDshiftRight(unsigned char n) //shift by n characters Right
{
unsigned char i;
for(i=0;i<n;i++)
LCDSendCommand(0x1e);
}
#endif
205 //-----------------------------------------------------------------
206 //畫面和光標一起左邊移動n個字符位置
207
208 #if LCD_EN_shiftLeft
void LCDshiftLeft(unsigned char n) //shift by n characters Left
{
unsigned char i;
for(i=0;i<n;i++)
LCDSendCommand(0x18);
}
#endif
216 //-----------------------------------------------------------------
217 //光標往右邊移動n個字符位置
218 #if LCD_EN_cursorRight
void LCDcursorRight(unsigned char n) //shif cursor right by n
{
unsigned char i;
for(i=0;i<n;i++)
LCDSendCommand(0x14);
}
#endif
226 //------------------------------------------------------------------
227 //光標往左邊移動n個字符位置
228 #if LCD_EN_cursorLeft
void LCDcursorLeft(unsigned char n) //Shift cursor left by n
{
unsigned char i;
for(i=0;i<n;i++)
LCDSendCommand(0x10);
}
#endif
236 //------------------------------------------------------------------
237
238
239 /*******************************************************************
240 * 函數說明:設置數據接口位數是4為還是8位,顯示行數是一行還是二行, *
241 字體格式是5*7還是5*10 *
C51 COMPILER V6.23a LCD1602 10/25/2008 20:27:53 PAGE 5
242 * 輸入參數: bit DL: 表示數據接口長度,DL=1,表示8位;DL=0,表示4為 *
243 * bit N: 表示顯示行數,N=1,表示兩行;N=0,表示一行 *
244 * bit F: 表示字體格式,F=1,表示5*10;F=0,表示5*7 *
245 ********************************************************************/
246 #if LCD_EN_setFunction
247 void LCDsetFunction(bit DL,bit N,bit F)
248 {
249 1 unsigned char order;
250 1 order=0x20;
251 1 if(DL)
252 1 order=order+0x10;
253 1 if(N)
254 1 order=order+0x8;
255 1 if(F)
256 1 order=order+0x4;
257 1 LCDSendCommand(order);
258 1 }
260
261
262 /**************************************************
263 * 函數說明:設置CG RAM地址 *
264 * 輸入參數: unsigned char CG: 表示CG RAM地址 *
265 ***************************************************/
266 #if CustomCharCount
267 void LCDsetCGRAMAddress(unsigned char CG)
268 {
269 1 unsigned char order;
270 1 order=0x40;
271 1 order=order+CG;
272 1 LCDSendCommand(order);
273 1 }
274 #endif
275
276
277
278 /*************************************************
279 * 函數說明:MCU向LCD16B20寫入數據 *
280 * 輸入參數: unsigned char DATA *
281 **************************************************/
282 #if LCD_EN_writeData
283 void LCDwriteData(unsigned char DATA)
284 {
285 1 #if LCD_DL<8
286 1 unsigned char d;
287 1 #endif
288 1
289 1 LCDwaitForReady();
290 1 LCD_RS=1;//選擇數據寄存器
291 1 NOP();
292 1 LCD_RW=0;//MCU向LCD寫入
293 1 NOP();
294 1 #if LCD_DL>4
LCD_Data_Port=DATA;
NOP();
LCD_EN=1;
NOP();
LCD_EN=0;
#else
301 1 d=DATA & 0xf0;
302 1 LCD_Data_Port=LCD_Data_Port & 0xf;
303 1 LCD_Data_Port=LCD_Data_Port | d;
C51 COMPILER V6.23a LCD1602 10/25/2008 20:27:53 PAGE 6
304 1 NOP();
305 1 LCD_EN=1;
306 1 NOP();
307 1 LCD_EN=0;
308 1
309 1 d=DATA & 0xf;
310 1 d=d<<4;
311 1 d=d & 0xf0;
312 1 LCD_Data_Port=LCD_Data_Port & 0xf;
313 1 LCD_Data_Port=LCD_Data_Port | d;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -