📄 lcd_24064.lst
字号:
191 1 }
192
193
194 /************************************************\
195 |* 写命令子函数3---双参数指令 *|
196 |* 入口参数: data1 待写入的参数1 *|
197 |* data2 待写入的参数2 *|
198 |* cmd 待写入的命令 *|
199 |* 出口参数: 空 *|
200 |* 调用函数: Write_Data () *|
201 |* Write_Cmd_Non () *|
202 |* 说明: *|
203 |* *|
204 \************************************************/
205 void Write_Cmd_Double (uchar data1,uchar data2,uchar cmd)
206 {
207 1 Write_Data (data1);
208 1 Write_Data (data2);
209 1 Write_Cmd_Non (cmd);
210 1 }
211
212
213 /************************************************\
214 |* LCD初始化子函数 *|
215 |* 入口参数: 空 *|
216 |* 出口参数: 空 *|
217 |* 调用函数: Write_Cmd_Double () *|
218 |* Write_Cmd_Non () *|
219 |* 说明: *|
220 |* *|
221 \************************************************/
222 void Lcd_Init (void)
223 {
224 1 Write_Cmd_Double ( 0x00,0x00,0x40 ); //设置文本显示区首地址为0x0000
225 1 Write_Cmd_Double ( 0x1e,0x00,0x41 ); //设置文本显示区宽度为30字节(30*8=240)
226 1 Write_Cmd_Double ( 0x00,0x08,0x42 ); //设置图形显示区首地址为0x0800
227 1 Write_Cmd_Double ( 0x1e,0x00,0x43 ); //设置图形显示区宽度为30字节
228 1
229 1 Write_Cmd_Non ( 0xa7 ); //光标形状为8点(列)*N行,N的值为0-7H(参数中低半字节)
230 1 Write_Cmd_Non ( 0x80 ); //显示方式设置(使用内部CGROM,逻辑或合成)
231 1 Write_Cmd_Non ( 0x9c ); //设置显示开关,开文本显示 显示开关(开文本和图形显示方式,禁止
-光标显示和闪烁)
232 1 }
233
234
235 /************************************************\
236 |* LCD清屏子函数 *|
237 |* 入口参数: 空 *|
238 |* 出口参数: 空 *|
239 |* 调用函数: Write_Cmd_Double () *|
240 |* Write_Cmd_Non () *|
C51 COMPILER V7.50 LCD_24064 08/12/2007 23:57:47 PAGE 5
241 |* Read_State () *|
242 |* Write_Data () *|
243 |* 说明: *|
244 |* *|
245 \************************************************/
246 void Lcd_Clr (void)
247 {
248 1 uint count;
249 1 Write_Cmd_Double ( 0x00,0x00,0x24 ); //设置显示RAM的地址为0x0000
250 1 Write_Cmd_Non ( 0xb0 ); //设为自动写状态
251 1 for (count=0;count<0x2000;count++)
252 1 {
253 2 while( ( Read_State () & 0x0c ) != 0x0c ) ;
254 2 Write_Data (0x00);
255 2 }
256 1 Write_Cmd_Non ( 0xb2 ); //退出自动写状态
257 1 Write_Cmd_Double ( 0x00,0x00,0x24 ); //设置显示RAM的地址为0x0000
258 1 }
259
260
261
262 /************************************************\
263 |* 字符串显示子函数 *|
264 |* 入口参数: add 待写入的地址 (0~239) *|
265 |* sentence[] 待写入的字符串 *|
266 |* 出口参数: 空 *|
267 |* 调用函数: Write_Cmd_Double () *|
268 |* Write_Cmd_Non () *|
269 |* Write_Cmd_Single () *|
270 |* strlen() *|
271 |* Write_Data () *|
272 |* 说明: *|
273 |* *|
274 \************************************************/
275 void Write_Eng(uchar add,uchar sentence[])
276 {
277 1 uchar count;
278 1 Write_Cmd_Non (0x94); //应用文本显示 关图形显示 光标显示和光标闪烁
279 1 Write_Cmd_Non (0x84); //启用CGROM和文本属性
280 1
281 1 Write_Cmd_Double ( add,0x00,0x24 ); //设置显示地址
282 1 for(count=0;count<strlen(sentence);count++)
283 1 {
284 2 Write_Cmd_Single ( sentence[count]-32,0xc0 );
285 2
286 2 }
287 1
288 1 Write_Cmd_Double ( add,0x08,0x24 ); //置显示地址 为文本属性
289 1 for(count=0;count<strlen(sentence);count++)
290 1 {
291 2 Write_Cmd_Single ( sentence_dat[count],0xc0 ); //正显闪烁
292 2 }
293 1 }
294
295
296 /************************************************\
297 |* 建立CGRAM字库子函数 *|
298 |* 可以建立128个8*8点阵(字符或图标等) *|
299 |* 字符代码规定在0x80~0xff *|
300 |* 入口参数: 空 *|
301 |* 出口参数: 空 *|
302 |* 调用函数: Write_Cmd_Double () *|
C51 COMPILER V7.50 LCD_24064 08/12/2007 23:57:47 PAGE 6
303 |* Write_Cmd_Non () *|
304 |* Read_State () *|
305 |* Write_Data () *|
306 |* 说明: *|
307 |* *|
308 \************************************************/
309 void Setup_Cgram ( void )
310 {
311 1 uint count;
312 1 Write_Cmd_Double ( 0x03,0x00,0x22 ); //设置CGRAM偏置地址03 对应的字符代码为0x80的点阵的RAM地址为0x1c00~
-0x1c07
313 1 Write_Cmd_Double ( 0x00,0x1c,0x24 ); //设置RAM地址为0x1c00 准备将字库(32*4)写入其中
314 1
315 1 Write_Cmd_Non ( 0xb0 ); //设为自动写状态
316 1 for(count=0;count<128*8;count++)
317 1 {
318 2 while( ( Read_State () & 0x0c ) != 0x0c ) ;
319 2 Write_Data ( DotTbl16[count] );
320 2 }
321 1 Write_Cmd_Non ( 0xb2 ); //退出自动写状态
322 1 }
323
324
325 /************************************************\
326 |* 写单个汉字子函数 *|
327 |* *|
328 |* *|
329 |* 入口参数: 空 *|
330 |* 出口参数: 空 *|
331 |* 调用函数: Write_Cmd_Double () *|
332 |* Write_Cmd_Non () *|
333 |* Read_State () *|
334 |* Write_Data () *|
335 |* 说明: *|
336 |* *|
337 \************************************************/
338 void write_word ( uchar add , uchar word_code )
339 {
340 1 Write_Cmd_Double ( add,0x00,0x24 );
341 1 Write_Cmd_Single ( word_code,0xc0 );
342 1 Write_Cmd_Single ( word_code+2,0xc0 );
343 1 Write_Cmd_Double ( add+30,0x00,0x24 );
344 1 Write_Cmd_Single ( word_code+1,0xc0 );
345 1 Write_Cmd_Single ( word_code+3,0xc0 );
346 1 }
347
348 void write_sentence (uchar add )
349 {
350 1 uchar count;
351 1 for(count=0;count<32;count++)
352 1 {
353 2 if ( (add%30+count*2)%30==0 ) add+=30;
354 2 write_word ( add+count*2 , 0x80+count*4);
355 2 }
356 1 }
357
358 void main( void )
359 {
360 1 System_Init ();
361 1 Port_Init ();
362 1 Lcd_Init ();
363 1 Lcd_Clr ();
C51 COMPILER V7.50 LCD_24064 08/12/2007 23:57:47 PAGE 7
364 1
365 1 Write_Eng(0 ,"Hello! I'm Elbe! QQ:6036725 ");
366 1
367 1 Setup_Cgram ();
368 1 write_sentence (30);
369 1
370 1 while(1);
371 1
372 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 604 ----
CONSTANT SIZE = 1145 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 8
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 + -