iicled.lst
来自「VB环境下的串口通讯设计」· LST 代码 · 共 555 行 · 第 1/2 页
LST
555 行
262
263 //读多字节数据
264 //供外部调用函数
265 void AT24C64_R(void *mcu_address,uint AT24C64_address,uint count)
266 {
267 1 s1=0;s2=0;nG=1;
268 1 while(count--)
269 1 {
270 2 I2C_Start();
271 2 /*I2C_Send_Byte( 0xa0 + AT24C64_address / 256
272 2 *2 );*/ /* 24C16 USE */
273 2 I2C_Send_Byte( 0xa0 );//写命令设备地址为10100000最后一位为0"写标志"
274 2 I2C_Send_Byte( AT24C64_address/256 );//写存储器页地址
275 2 I2C_Send_Byte( AT24C64_address % 256 );//写存储器字节地址
276 2 I2C_Start();
277 2 /*I2C_Send_Byte( 0xa1 + AT24C64_address /256 *2 );*/
278 2 I2C_Send_Byte( 0xa1 );//写命令设备地址为10100001最后一位为1"读标志"
279 2 *(uchar*)mcu_address = I2C_Receive_Byte();//读单字节数据到MCU指针指向的地址
280 2 I2C_Nack();//回应答信号
281 2 I2C_Stop();
282 2 ((uchar*)mcu_address)++;
283 2 AT24C64_address++;
284 2 }
285 1 s1=1;s2=1;nG=0;
286 1 }
287
288 //=====================================
289 void main()
290 {
291 1 int16 len;
292 1 uchar hh,hl,mh,ml;
293 1 McuInit();
294 1 GRE=1;
295 1 AT24C64_R(tab,0x00,96);
296 1 TR0=0;
297 1 //TR1=1;
298 1 EA=0;
299 1 while(1)
300 1 {
301 2 nG=0;
302 2 //======================================
303 2 len=0x400;
C51 COMPILER V8.05a IICLED 01/08/2008 18:30:43 PAGE 6
304 2 AT24C64_R(tab,0x00,96);//欢迎您
305 2 while(len>0){XianShiX();len--;}
306 2 //======================================
307 2 len=0x400;
308 2 AT24C64_R(tab,0x60,96);//欢迎光临
309 2 while(len>0){XianShiX();len--;}
310 2 //======================================
311 2
312 2 len=0x400;
313 2 AT24C64_R(tab,0xc0,96); //出入平安
314 2 while(len>0){XianShiX();len--;}
315 2
316 2 //======================================
317 2 hl=read_time(0x85);
318 2 hh=hl>>4;
319 2 hl=hl&0x0f;
320 2 ml=read_time(0x83);
321 2 mh=ml>>4;
322 2 ml=ml&0x0f;
323 2 tab_time(hh,hl,mh,ml); //查表并设置时间
324 2 len=0x400;
325 2 while(len>0){XianShiX();len--;}
326 2 //======================================
327 2 len=0x400;
328 2 AT24C64_R(tab,0x120,96);//温世坚
329 2 while(len>0){XianShiX();len--;}
330 2 AT24C64_R(tab,0x00,96);
331 2
332 2 }
333 1
334 1 }
335
336
337
338 void McuInit(void)
339 {
340 1 s1=0;s2=0;nG=1;
341 1 EA=0;
342 1 LED1=0;
343 1 LED2=0;
344 1 GRE=0;
345 1 delay(250);
346 1 LED1=1;
347 1 LED2=0;
348 1 GRE=0;
349 1 delay(100);
350 1 LED1=0;
351 1 LED2=1;
352 1 GRE=0;
353 1 delay(90);
354 1 LED1=0;
355 1 LED2=0;
356 1 GRE=1;
357 1 delay(60);
358 1 LED1=1;
359 1 LED2=0;
360 1 GRE=1;
361 1 delay(40);
362 1 LED1=1;
363 1 LED2=1;
364 1 GRE=0;
365 1 //========================
C51 COMPILER V8.05a IICLED 01/08/2008 18:30:43 PAGE 7
366 1 delay(20);
367 1 LED1=0;
368 1 LED2=1;
369 1 GRE=0;
370 1 delay(20);
371 1 LED1=1;
372 1 LED2=0;
373 1 GRE=0;
374 1 delay(20);
375 1 LED1=0;
376 1 LED2=0;
377 1 GRE=1;
378 1 delay(20);
379 1 LED1=1;
380 1 LED2=1;
381 1 GRE=0;
382 1 delay(20);
383 1 LED1=1;
384 1 LED2=0;
385 1 GRE=1;
386 1 delay(20);
387 1 LED1=0;
388 1 LED2=1;
389 1 GRE=1;
390 1 delay(20);
391 1 LED1=1;
392 1 LED2=1;
393 1 GRE=1;
394 1 delay(20);
395 1 LED1=0;
396 1 LED2=0;
397 1 GRE=0;
398 1
399 1 ET0 = 0; //允许定时器0中断
400 1 TMOD = 0X01; //定时器工作方式选择
401 1 TL0 = 0x00;
402 1 TH0 = 0x00; //定时器赋予初值
403 1 TR0 = 0; //启动定时器
404 1 TR1=0;
405 1 EX0=0;
406 1 EX1=0;
407 1 EA =0 ; //开总中断
408 1 nG=0;
409 1
410 1 }
411
412 void tab_time(uchar hh,uchar hl,uchar mh,uchar ml)
413 {
414 1 uchar code timer[10][16]=
415 1 {//数字0-9的点阵表
416 1 {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/
417 1
418 1 {0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"1",1*/
419 1
420 1 {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",2*/
421 1
422 1 {0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"3",3*/
423 1
424 1 {0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00},/*"4",4*/
425 1
426 1 {0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",5*/
427 1
C51 COMPILER V8.05a IICLED 01/08/2008 18:30:43 PAGE 8
428 1 {0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"6",6*/
429 1
430 1 {0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",7*/
431 1
432 1 {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",8*/
433 1
434 1 {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00}/*"9",9*/
435 1
436 1 };
437 1 uchar xdata ttt[6][16]=
438 1 { //00:00 时间显示形式
439 1 {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/
440 1
441 1 {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",1*/
442 1
443 1 {0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00,0x00,0x00},/*":",2*/
444 1
445 1 {0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},/*":",3*/
446 1
447 1 {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",4*/
448 1
449 1 {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00}/*"0",5*/
450 1
451 1 };
452 1 uchar i,j;
453 1 for(i=0;i<16;i++)
454 1 {
455 2 ttt[0][i]=timer[hh][i];
456 2 ttt[1][i]=timer[hl][i];
457 2 ttt[4][i]=timer[mh][i];
458 2 ttt[5][i]=timer[ml][i];
459 2 }
460 1 for(i=0;i<6;i++)
461 1 for(j=0;j<16;j++)
462 1 tab[j][i]=ttt[i][j];
463 1 }
464
465
466 //====================================================================================================
467
468 //--------------------------------------------------------------------------------*/
469 /*-------------------------------------------------------------------------------
470
471 名称:read_time
472 参数:指令码com
473 功能:读取年、月、日、星期、时、分、秒的函数
474
475 --------------------------------------------------------------------------------*/
476 uchar read_time(uchar com){
477 1 uchar i;
478 1 temp=com;
479 1
480 1 SCLK=0;
481 1 RESET=0;
482 1 RESET=1;
483 1
484 1
485 1 for(i=0;i<8;i++){
486 2 IO=bit0;
487 2 //_nop_();_nop_();
488 2 SCLK=1;
489 2 //_nop_();
C51 COMPILER V8.05a IICLED 01/08/2008 18:30:43 PAGE 9
490 2 SCLK=0;
491 2 temp>>=1;
492 2 }
493 1
494 1
495 1
496 1
497 1 temp=0;
498 1
499 1 IO=1;//置1再读
500 1 bit7=IO;
501 1
502 1
503 1 for(i=0;i<7;i++){
504 2 temp>>=1;
505 2 SCLK=1;
506 2 SCLK=0;
507 2 bit7=IO;
508 2 }
509 1 RESET=0;
510 1 SCLK=1;
511 1 return temp;
512 1 }
513
514
515
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1328 ----
CONSTANT SIZE = 256 ----
XDATA SIZE = 96 96
PDATA SIZE = ---- ----
DATA SIZE = 5 15
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?