?? ds1302.lst
字號:
388 1 unsigned char a=0;
389 1 unsigned char b=0;
390 1 unsigned char t=0;
391 1
392 1 Init_DS18B20();
393 1 WriteOneChar(0xCC); // 跳過讀序號列號的操作
394 1 WriteOneChar(0x44); // 啟動溫度轉(zhuǎn)換
395 1
396 1 delay_18B20(100); // this message is wery important
397 1
398 1 Init_DS18B20();
399 1 WriteOneChar(0xCC); //跳過讀序號列號的操作
C51 COMPILER V8.02 DS1302 04/09/2008 00:26:08 PAGE 8
400 1 WriteOneChar(0xBE); //讀取溫度寄存器等(共可讀9個寄存器) 前兩個就是溫度
401 1
402 1 delay_18B20(100);
403 1
404 1 a=ReadOneChar(); //讀取溫度值低位
405 1 b=ReadOneChar(); //讀取溫度值高位
406 1 temp_value=b<<4;
407 1 temp_value+=(a&0xf0)>>4;
408 1 }
409 void temp_to_str() //溫度數(shù)據(jù)轉(zhuǎn)換成液晶字符顯示
410 {
411 1 TempBuffer[0]=temp_value/10+'0'; //十位
412 1 TempBuffer[1]=temp_value%10+'0'; //個位
413 1 TempBuffer[2]=0xdf; //溫度符號
414 1 TempBuffer[3]='C';
415 1 TempBuffer[4]='\0';
416 1 }
417 void Delay1ms(unsigned int count)
418 {
419 1 unsigned int i,j;
420 1 for(i=0;i<count;i++)
421 1 for(j=0;j<120;j++);
422 1 }
423
424 /*延時子程序*/
425 void mdelay(uint delay)
426 { uint i;
427 1 for(;delay>0;delay--)
428 1 {for(i=0;i<62;i++) //1ms延時.
429 2 {;}
430 2 }
431 1 }
432
433
434 void outkey() //跳出調(diào)整模式,返回默認(rèn)顯示
435 { uchar Second;
436 1 if(out==0||wireless_1==1)
437 1 { mdelay(8);
438 2 count=0;
439 2 hide_sec=0,hide_min=0,hide_hour=0,hide_day=0,hide_week=0,hide_month=0,hide_year=0;
440 2 Second=Read1302(DS1302_SECOND);
441 2 Write1302(0x8e,0x00); //寫入允許
442 2 Write1302(0x80,Second&0x7f);
443 2 Write1302(0x8E,0x80); //禁止寫入
444 2 done=0;
445 2 while(out==0);
446 2 while(wireless_1==1);
447 2 }
448 1 }
449 //////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
450 void Upkey()//升序按鍵
451 {
452 1 Up=1;
453 1 if(Up==0||wireless_2==1)
454 1 {
455 2 mdelay(8);
456 2 switch(count)
457 2 {case 1:
458 3 temp=Read1302(DS1302_SECOND); //讀取秒數(shù)
459 3 temp=temp+1; //秒數(shù)加1
460 3 up_flag=1; //數(shù)據(jù)調(diào)整后更新標(biāo)志
C51 COMPILER V8.02 DS1302 04/09/2008 00:26:08 PAGE 9
461 3 if((temp&0x7f)>0x59) //超過59秒,清零
462 3 temp=0;
463 3 break;
464 3 case 2:
465 3 temp=Read1302(DS1302_MINUTE); //讀取分?jǐn)?shù)
466 3 temp=temp+1; //分?jǐn)?shù)加1
467 3 up_flag=1;
468 3 if(temp>0x59) //超過59分,清零
469 3 temp=0;
470 3 break;
471 3 case 3:
472 3 temp=Read1302(DS1302_HOUR); //讀取小時數(shù)
473 3 temp=temp+1; //小時數(shù)加1
474 3 up_flag=1;
475 3 if(temp>0x23) //超過23小時,清零
476 3 temp=0;
477 3 break;
478 3 case 4:
479 3 temp=Read1302(DS1302_WEEK); //讀取星期數(shù)
480 3 temp=temp+1; //星期數(shù)加1
481 3 up_flag=1;
482 3 if(temp>0x7)
483 3 temp=1;
484 3 break;
485 3 case 5:
486 3 temp=Read1302(DS1302_DAY); //讀取日數(shù)
487 3 temp=temp+1; //日數(shù)加1
488 3 up_flag=1;
489 3 if(temp>0x31)
490 3 temp=1;
491 3 break;
492 3 case 6:
493 3 temp=Read1302(DS1302_MONTH); //讀取月數(shù)
494 3 temp=temp+1; //月數(shù)加1
495 3 up_flag=1;
496 3 if(temp>0x12)
497 3 temp=1;
498 3 break;
499 3 case 7:
500 3 temp=Read1302(DS1302_YEAR); //讀取年數(shù)
501 3 temp=temp+1; //年數(shù)加1
502 3 up_flag=1;
503 3 if(temp>0x85)
504 3 temp=0;
505 3 break;
506 3 default:break;
507 3 }
508 2
509 2 while(Up==0);
510 2 while(wireless_2==1);
511 2 }
512 1 }
513
514 //////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
515 void Downkey()//降序按鍵
516 {
517 1 Down=1;
518 1 if(Down==0||wireless_3==1)
519 1 {
520 2 mdelay(8);
521 2 switch(count)
C51 COMPILER V8.02 DS1302 04/09/2008 00:26:08 PAGE 10
522 2 {case 1:
523 3 temp=Read1302(DS1302_SECOND); //讀取秒數(shù)
524 3 temp=temp-1; //秒數(shù)減1
525 3 down_flag=1; //數(shù)據(jù)調(diào)整后更新標(biāo)志
526 3 if(temp==0x7f) //小于0秒,返回59秒
527 3 temp=0x59;
528 3 break;
529 3 case 2:
530 3 temp=Read1302(DS1302_MINUTE); //讀取分?jǐn)?shù)
531 3 temp=temp-1; //分?jǐn)?shù)減1
532 3 down_flag=1;
533 3 if(temp==-1)
534 3 temp=0x59; //小于0秒,返回59秒
535 3 break;
536 3 case 3:
537 3 temp=Read1302(DS1302_HOUR); //讀取小時數(shù)
538 3 temp=temp-1; //小時數(shù)減1
539 3 down_flag=1;
540 3 if(temp==-1)
541 3 temp=0x23;
542 3 break;
543 3 case 4:
544 3 temp=Read1302(DS1302_WEEK); //讀取星期數(shù)
545 3 temp=temp-1; //星期數(shù)減1
546 3 down_flag=1;
547 3 if(temp==0)
548 3 temp=0x7;;
549 3 break;
550 3 case 5:
551 3 temp=Read1302(DS1302_DAY); //讀取日數(shù)
552 3 temp=temp-1; //日數(shù)減1
553 3 down_flag=1;
554 3 if(temp==0)
555 3 temp=31;
556 3 break;
557 3 case 6:
558 3 temp=Read1302(DS1302_MONTH); //讀取月數(shù)
559 3 temp=temp-1; //月數(shù)減1
560 3 down_flag=1;
561 3 if(temp==0)
562 3 temp=12;
563 3 break;
564 3 case 7:
565 3 temp=Read1302(DS1302_YEAR); //讀取年數(shù)
566 3 temp=temp-1; //年數(shù)減1
567 3 down_flag=1;
568 3 if(temp==-1)
569 3 temp=0x85;
570 3 break;
571 3 default:break;
572 3 }
573 2
574 2 while(Down==0);
575 2 while(wireless_3==1);
576 2 }
577 1 }
578
579 void Setkey()//模式選擇按鍵
580 {
581 1 Set=1;
582 1 if(Set==0||wireless_4==1)
583 1 {
C51 COMPILER V8.02 DS1302 04/09/2008 00:26:08 PAGE 11
584 2 mdelay(8);
585 2 count=count+1; //Setkey按一次,count就加1
586 2 done=1; //進(jìn)入調(diào)整模式
587 2 while(Set==0);
588 2 while(wireless_4==1);
589 2 }
590 1
591 1 }
592
593 void keydone()//按鍵功能執(zhí)行
594 { uchar Second;
595 1 if(flag==0) //關(guān)閉時鐘,停止計時
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -