📄 smgsy.lst
字号:
241 2 case 2:
C51 COMPILER V7.20 SMGSY 06/14/2005 20:23:34 PAGE 5
242 2 temp=0xfb;
243 2 break;
244 2 case 3:
245 2 temp=0xf7;
246 2 break;
247 2 case 4:
248 2 temp=0xef;
249 2 break;
250 2 case 5:
251 2 temp=0xdf;
252 2 break;
253 2 case 6:
254 2 { temp=0xbf;
255 3 break;}
256 2 case 7:
257 2 temp=0x7f;
258 2 break;
259 2 default:
260 2 temp=0x55;
261 2 }
262 1 return(temp);
263 1 }
264 /***************************************************************************
265 延时程序
266 /***************************************************************************/
267 void DelayMs(Uint number) {
268 1 Uchar temp;
269 1 for(;number!=0;number--) {
270 2 for(temp=112;temp!=0;temp--) {
271 3 }
272 2 }
273 1 }
274 /************************************************************
275 24c02演示程序
276 /*************************************************************/
277 void Start() {
278 1 SDA24=1;
279 1 SCL24=1;
280 1 SDA24=0;
281 1 SCL24=0;
282 1 }
283
284 /***************************************************************************/
285 void Stop() {
286 1 SCL24=0;
287 1 SDA24=0;
288 1 SCL24=1;
289 1 SDA24=1;
290 1 }
291
292 /***************************************************************************/
293 void Ack() {
294 1 SDA24=0;
295 1 SCL24=1;
296 1 SCL24=0;
297 1 SDA24=1;
298 1 }
299
300 /***************************************************************************/
301 void NoAck() {
302 1 SDA24=1;
303 1 SCL24=1;
C51 COMPILER V7.20 SMGSY 06/14/2005 20:23:34 PAGE 6
304 1 SCL24=0;
305 1 }
306
307 /***************************************************************************/
308 bit TestAck() {
309 1 bit ErrorBit;
310 1 SDA24=1;
311 1 SCL24=1;
312 1 ErrorBit=SDA24;
313 1 SCL24=0;
314 1 return(ErrorBit);
315 1 }
316
317 /***************************************************************************/
318 void Write8Bit(Uchar input) {
319 1 Uchar temp;
320 1 for(temp=8;temp!=0;temp--) {
321 2 SDA24=(bit)(input&0x80);
322 2 SCL24=1;
323 2 SCL24=0;
324 2 input=input<<1;
325 2 }
326 1 }
327 /***************************************************************************/
328 void Write24c02(Uchar *Wdata,Uchar RomAddress,Uchar number) {
329 1 Start();
330 1 Write8Bit(WriteDeviceAddress);
331 1 TestAck();
332 1 Write8Bit(RomAddress);
333 1 TestAck();
334 1 for(;number!=0;number--) {
335 2 Write8Bit(*Wdata);
336 2 TestAck();
337 2 Wdata++;
338 2 }
339 1 Stop();
340 1 DelayMs(10);
341 1 }
342
343 /***************************************************************************/
344 Uchar Read8Bit() {
345 1 Uchar temp,rbyte=0;
346 1 for(temp=8;temp!=0;temp--) {
347 2 SCL24=1;
348 2 rbyte=rbyte<<1;
349 2 rbyte=rbyte|((Uchar)(SDA24));
350 2 SCL24=0;
351 2 }
352 1 return(rbyte);
353 1 }
354
355 /***************************************************************************/
356 void Read24c02(Uchar *RamAddress,Uchar RomAddress,Uchar bytes) {
357 1 //unsigned char temp, rbyte;
358 1 Start();
359 1 Write8Bit(WriteDeviceAddress);
360 1 TestAck();
361 1 Write8Bit(RomAddress);
362 1 TestAck();
363 1 Start();
364 1 Write8Bit(ReadDviceAddress);
365 1 TestAck();
C51 COMPILER V7.20 SMGSY 06/14/2005 20:23:34 PAGE 7
366 1 while(bytes!=1) {
367 2 *RamAddress=Read8Bit();
368 2 Ack();
369 2 RamAddress++;
370 2 bytes--; }
371 1 *RamAddress=Read8Bit();
372 1 NoAck();
373 1 Stop();
374 1 }
375 /*=======================================================
376 液晶屏上显示字符串
377 =======================================================*/
378 void ePutstr(Uchar x,Uchar y, Uchar code *ptr) reentrant{
379 1 Uchar i,l=0;
380 1 while (*ptr++ >0){l++;}; //统计字符的个数
381 1 ptr=ptr-(l+1); //使指针重新指向首个字符
382 1 for (i=0;i<l;i++) { DispOneChar(x++,y,*ptr++);
383 2 if ( x == 31 ) { x = 0; y ^= 0; }
384 2 }
385 1 }
386
387
388 /*=======================================================
389 显示光标定位
390 =======================================================*/
391 void Disp_XY( char posx,char posy) {
392 1
393 1 Uchar temp;
394 1
395 1 temp = posx & 0x0f;
396 1 posy &= 0x1;
397 1 if ( posx>15 ) temp |= 0x40;
398 1 if (posy==1) temp |=0x40;
399 1 temp |= 0x80;
400 1 LcdWriteCommand(temp,0);
401 1 }
402
403 /*=======================================================
404 按指定位置显示数出一个字符
405 =======================================================*/
406 void DispOneChar(Uchar x,Uchar y,Uchar Wdata) reentrant {
407 1
408 1 Disp_XY( x, y ); // 定位显示地址
409 1 LcdWriteData( Wdata ); // 写字符
410 1 }
411
412 /*=======================================================
413 初始化程序, 必须按照产品资料介绍的初始化过程进行
414 =======================================================*/
415 void LcdReset( void ) reentrant {
416 1
417 1 LcdWriteCommand( 0x38, 0); // 显示模式设置(不检测忙信号)
418 1 DelayMs(10);
419 1 LcdWriteCommand( 0x38, 0); // 共三次
420 1 DelayMs(10);
421 1 LcdWriteCommand( 0x38, 0);
422 1 DelayMs(10);
423 1
424 1 LcdWriteCommand( 0x38, 1); // 显示模式设置(以后均检测忙信号)
425 1 LcdWriteCommand( 0x08, 1); // 显示关闭
426 1 LcdWriteCommand( 0x01, 1); // 显示清屏
427 1 LcdWriteCommand( 0x06, 1); // 显示光标移动设置
C51 COMPILER V7.20 SMGSY 06/14/2005 20:23:34 PAGE 8
428 1 LcdWriteCommand( 0x0c, 1); // 显示开及光标设置
429 1 }
430
431 /*=======================================================
432 写控制字符子程序: E=1 RS=0 RW=0
433 =======================================================*/
434 void LcdWriteCommand( Uchar CMD,Uchar AttribC ) reentrant{
435 1
436 1 if (AttribC) WaitForEnable(); // 检测忙信号?
437 1 RS=0; RW=0; _nop_();
438 1 DataPort=CMD; _nop_();
439 1 // 送控制字子程序
440 1 Elcm=1;_nop_();_nop_();Elcm=0; // 操作允许脉冲信号
441 1 }
442
443 /*=======================================================
444 当前位置写字符子程序: E =1 RS=1 RW=0
445 =======================================================*/
446 void LcdWriteData( char dataW ) reentrant {
447 1
448 1 WaitForEnable();
449 1 // 检测忙信号
450 1
451 1 RS=1; RW=0; _nop_();
452 1
453 1 DataPort=dataW; _nop_();
454 1
455 1 Elcm=1; _nop_(); _nop_(); Elcm=0; // 操作允许脉冲信号
456 1
457 1 }
458
459 /*=======================================================
460 正常读写操作之前必须检测LCD控制器状态: CS=1 RS=0 RW=1
461 DB7: 0 LCD控制器空闲; 1 LCD控制器忙
462 ========================================================*/
463 void WaitForEnable( void ) {
464 1
465 1 DataPort = 0xff;
466 1
467 1 RS=0; RW=1; _nop_(); Elcm=1; _nop_(); _nop_();
468 1
469 1 while( DataPort & Busy );
470 1 Elcm=0;
471 1 }
472
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1248 ----
CONSTANT SIZE = 124 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 33
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -