找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2285|回復(fù): 0
收起左側(cè)

時鐘溫室度計1602顯示

[復(fù)制鏈接]
ID:105206 發(fā)表于 2017-6-10 09:50 | 顯示全部樓層 |閱讀模式
干貨,上代碼。
  1. #include <reg52.h>
  2. #include"1602.h"        
  3. #include"delay.h"
  4. #include "ds1302.h"
  5. #include "key.h"
  6. #include"dh11.h"

  7. #include <intrins.h>

  8. sbit BEEP=P3^7;

  9. extern uchar S1num,flag,second,minute,hour,week,day,month,year;//秒、分、時、星期、日、月、年
  10. extern bit keyflag;

  11. /////////////////////////////////////////////////////
  12. extern uchar RHL,RHH,CL,CH;  
  13. extern uint m,n;
  14. /////////////////////////////////////////////////////////
  15. uchar num;
  16. //uchar fan;
  17. ////////////////////////////////////////////////////////////////
  18. uchar code line1_data[] = {"  :  :       "};                         //定義第2行顯示的字符
  19. extern bit k4flag;
  20. extern uchar second1,minute1,hour1;
  21. /////////////////////////////////////////////////////
  22. void beep()
  23. {
  24.         BEEP=!BEEP;
  25.         Delay_ms(200);
  26.         BEEP=!BEEP;
  27.         Delay_ms(200);
  28. }

  29. /*****************讀出秒的十進制數(shù)***************************/
  30. uchar readsecond()
  31. {
  32.         uchar dat;
  33.         dat=read_1302add(0x81);
  34.         second=((dat&0x70)>>4)*10+(dat&0x0f);
  35.         return second;
  36. }
  37. /*****************讀出分的十進制數(shù)***************************/
  38. uchar readminute()
  39. {
  40. uchar dat;
  41. dat=read_1302add(0x83);
  42. minute=((dat&0x70)>>4)*10+(dat&0x0f);
  43. return minute;
  44. }
  45. /*****************讀出小時的十進制數(shù)***************************/
  46. uchar readhour()
  47. {
  48. uchar dat;
  49. dat=read_1302add(0x85);
  50. hour=((dat&0x70)>>4)*10+(dat&0x0f);
  51. return hour;
  52. }
  53. /*****************讀出天的十進制數(shù)***************************/
  54. uchar readday()
  55. {
  56. uchar dat;
  57. dat=read_1302add(0x87);
  58. day=((dat&0x70)>>4)*10+(dat&0x0f);
  59. return day;
  60. }
  61. /*****************讀出月的十進制數(shù)***************************/
  62. uchar readmonth()
  63. {
  64. uchar dat;
  65. dat=read_1302add(0x89);
  66. month=((dat&0x70)>>4)*10+(dat&0x0f);
  67. return month;
  68. }
  69. /*****************讀出周的十進制數(shù)***************************/
  70. //uchar readweek()
  71. //{
  72. //uchar dat;
  73. //dat=read_1302add(0x8b);
  74. //week=((dat&0x70)>>4)*10+(dat&0x0f);
  75. //return week;
  76. //}
  77. /*****************讀出年的十進制數(shù)***************************/
  78. uchar readyear()
  79. {
  80.         uchar dat;
  81.         dat=read_1302add(0x8d);
  82.         year=((dat&0xf0)>>4)*10+(dat&0x0f);
  83.         return year;
  84. }


  85. /************************讀出所有時間**********************/
  86. void readtime()
  87. {
  88.         readsecond();
  89.         readminute();
  90.         readhour();
  91. //        readday();
  92. //        readmonth();
  93. //        readweek();
  94. //        readyear();
  95. }

  96. void Init_Timer0(void)
  97. {
  98. TMOD |= 0x01;          //使用模式1,16位定時器,使用"|"符號可以在使用多個定時器時不受影響                     
  99. TH0=0xb0;              //給定初值,這里使用定時器最大值從0開始計數(shù)一直到65535溢出
  100. TL0=0xc3;
  101. EA=1;            //總中斷打開
  102. ET0=1;           //定時器中斷打開
  103. // TR0=1;           //定時器開關(guān)打開
  104. }


  105. void main()
  106. {
  107.         uchar i;
  108.     Init_Timer0();

  109.         LCD_Init();           //初始化液晶
  110.         Delay_ms(20);          //延時有助于穩(wěn)定
  111.         LCD_Clear();          //清屏
  112.         init_1302();
  113.         LCD_Write_Com(0x40|0x80);                  //設(shè)置顯示位置為第2行第0列            
  114.         i = 0;
  115.   while(line1_data[i] != '\0')                  //在第2行0~3列顯示"****"
  116.   {                                                                     
  117.           LCD_Write_Data(line1_data[i]);         //顯示第2行字符   
  118.              i++;                                       //指向下一字符
  119.         }
  120.         Delay_ms(1000);
  121.         while(1)
  122.         {        
  123.                
  124.                 if(k4==0)
  125.                 {
  126.                         Delay_ms(10);
  127.                         if(k4==0)
  128.                         {
  129.                                 while(!k4);
  130.                                 k4flag=~k4flag;
  131.                         }
  132.                 }
  133.                 if(k4flag==1)
  134.                 {
  135.                         
  136.                         TR0=1;
  137.                         if(((second1==0)&minute1==0)&hour1==0)
  138.                    {
  139.                         
  140.                            beep();
  141.                    }
  142.                         
  143.                 }
  144.                
  145.                 else TR0=0;
  146.                
  147.         


  148.                
  149.                 keyscan();
  150.                 if(keyflag==0)
  151.                 {
  152.                         
  153.                         readtime();   //讀取年,月,日,時,分,秒
  154. //                        write_DTC();
  155.                         write_second();  //寫秒
  156.                         write_minute();        //寫分
  157.                         write_hour();        //寫時
  158. //                        write_day();    //寫日
  159. //                        write_month();  //寫月
  160. //                        write_year();   //寫年
  161. //                        write_week();
  162.                         
  163. //                        write_second1();  //寫秒
  164. //                        write_minute1();        //寫分
  165. //                        write_hour1();        //寫時
  166.                         
  167.                         disp_nz();
  168.                
  169.              }
  170.                 Delay_ms(100);
  171.                 receive();
  172.                
  173.      }
  174. }
復(fù)制代碼

時鐘溫室度.rar

90.42 KB, 下載次數(shù): 6, 下載積分: 黑幣 -5

回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表