欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 這個單片機DS1302程序如何做成定時開關?求思路 [打印本頁]

作者: chafferer。。    時間: 2021-3-15 14:19
標題: 這個單片機DS1302程序如何做成定時開關?求思路


由于本論壇禁止直接求程序,禁止伸手黨,所以向大家請教一下大致的實現方法與思路,理清頭緒后我自己來寫程序去實現

  1. #include<reg52.h>
  2. #include<intrins.h>
  3. #include<string.h>
  4. #include"DS1302.h"

  5. uchar Adjust_Index=-1;
  6. uchar MonthsDays[]={0,31,0,31,30,31,30,31,31,30,31,30,31};
  7. //****************************************************************************
  8. void Write_Byte(uchar x)
  9. {
  10.         uchar i;
  11.         for(i=0;i<8;i++)
  12.         {
  13.          IO=x&1;
  14.          SCLK=1;
  15.          _nop_();_nop_();_nop_();_nop_();_nop_();
  16.          SCLK=0;
  17.          x>>=1;
  18.         }
  19. }
  20. //***********************************************************************
  21. uchar Get_Byte()
  22. {
  23.   uchar i,b,t;
  24.   for(i=0;i<8;i++)
  25.          {
  26.           b>>=1;t=IO;b|=t<<7;
  27.           SCLK=1;
  28.           _nop_();_nop_();_nop_();_nop_();_nop_();
  29.           SCLK=0;
  30.          }
  31.          t=b/16*10+b%16;
  32.          return t;
  33. }
  34. //*************************************************************************
  35. uchar Read_Data(uchar addr)
  36. {
  37.          uchar t;
  38.          RST=0;SCLK=0;RST=1;
  39.          Write_Byte(addr);
  40.          _nop_();_nop_();_nop_();_nop_();_nop_();
  41.          t=Get_Byte();
  42.          SCLK=1;RST=0;
  43.          return t;
  44. }
  45. //*****************************************************************************
  46. void Write_DS1302(uchar addr,uchar dat)
  47. {
  48.          SCLK=0;RST=1;
  49.          Write_Byte(addr);
  50.          Write_Byte(dat);
  51.          SCLK=1;RST=0;
  52. }
  53. //****************************************************************************
  54. void Set_Time()
  55. {
  56.    uchar i;
  57.    Write_DS1302(0x8e,0x00);
  58.    for(i=0;i<7;i++)
  59.        Write_DS1302(0x80+2*i,(DateTime[i]/10<<4|DateTime[i]%10));
  60.            Write_DS1302(0x8e,0x80);
  61. }
  62. //*****************************************************************************
  63. void Get_Time()
  64. {
  65.    uchar i;
  66.    for(i=0;i<7;i++)
  67.     DateTime[i]=Read_Data(0x81+2*i);
  68. }
  69. //********************************************************************************
  70. void DateTime_Adjust(char x)
  71.   {
  72.    uchar y;
  73.    switch(Adjust_Index)
  74.      {
  75.            case 0://Ãëμ÷Õû
  76.            if(x==1&&DateTime[0]<59)DateTime[0]++;
  77.            if(x==-1&&DateTime[0]>0)DateTime[0]--;
  78.                  break;
  79.            case 1://·Ö0-59
  80.              if(x==1&&DateTime[1]<59)DateTime[1]++;
  81.                  if(x==-1&&DateTime[1]>0)DateTime[1]--;
  82.                  break;
  83.               case 2://ê±0-23
  84.              if(x==1&&DateTime[2]<23)DateTime[2]++;
  85.                  if(x==-1&&DateTime[2]>0)DateTime[2]--;
  86.                  break;
  87.            case 3: //èÕ
  88.                    y=2000+DateTime[6];
  89.                    if((y%4==0&&y%100!=0)||(y%400==0))
  90.                    MonthsDays[2]=29;
  91.                    else
  92.                    MonthsDays[2]=28;
  93.               if(x==1&&DateTime[3]<MonthsDays[DateTime[4]])DateTime[3]++;
  94.                   if(x==-1&&DateTime[3]>0)DateTime[3]--;
  95.                   break;
  96.            case 4: //ÔÂ
  97.                      if(x==1&&DateTime[4]<12)DateTime[4]++;
  98.                          if(x==-1&&DateTime[4]>0)DateTime[4]--;
  99.                          y=2000+DateTime[6];
  100.                    if((y%4==0&&y%100!=0)||(y%400==0))
  101.                    MonthsDays[2]=29;
  102.                    else
  103.                    MonthsDays[2]=28;
  104.               if(DateTime[3]<MonthsDays[DateTime[4]])
  105.                      DateTime[3]=MonthsDays[DateTime[4]];
  106.                          break;
  107.                 case 5://DÇÆú
  108.                   if(x==1&&DateTime[5]<7)DateTime[5]++;
  109.                   if(x==-1&&DateTime[5]>1)DateTime[5]--;
  110.                   break;
  111.                 case 6:        //Äê
  112.                   if(x==1&&DateTime[6]<99)DateTime[6]++;
  113.                   if(x==-1&&DateTime[6]>0)DateTime[6]--;
  114.                   y=2000+DateTime[6];
  115.                    if((y%4==0&&y%100!=0)||(y%400==0))
  116.                    MonthsDays[2]=29;
  117.                    else
  118.                    MonthsDays[2]=28;
  119.               if(DateTime[3]<MonthsDays[DateTime[4]])
  120.                      DateTime[3]=MonthsDays[DateTime[4]];
  121.                   break;                                                      
  122.          }
  123.   }
復制代碼



作者: chafferer。。    時間: 2021-3-15 14:20
想要用這個做成定時開關
作者: glinfei    時間: 2021-3-15 16:07
1、設置成鬧鐘,鬧鐘到你就輸出開關,也就是不斷檢查DateTime值是否等于鬧鐘值,如需要可以設置成某天的某個時刻,也可以天天到時開;2、設置成倒計時的定時器,那就直接算好DateTime值等于啥時開。
作者: chafferer。。    時間: 2021-3-15 16:14
glinfei 發表于 2021-3-15 16:07
1、設置成鬧鐘,鬧鐘到你就輸出開關,也就是不斷檢查DateTime值是否等于鬧鐘值,如需要可以設置成某天的某 ...

要怎么改才能讓它動起來,顯示當前時間
作者: man1234567    時間: 2021-3-16 10:29
買個鬧鐘,設定鬧鐘時間,單片機上接個話筒,接收到鬧鐘聲音就打開指定開關
或者在本壇里找帶鬧鐘的DS1302+12864時鐘程例伸手可得。
作者: 天ノ憶    時間: 2021-3-16 12:00
man1234567 發表于 2021-3-16 10:29
買個鬧鐘,設定鬧鐘時間,單片機上接個話筒,接收到鬧鐘聲音就打開指定開關
或者在本壇里找帶鬧鐘 ...

厲害,你這思路我想了一上午都想不出來
作者: 笨笨兔    時間: 2021-3-16 15:10
樓主 :你還是仔細看 DS1302 的技術手冊,資料看明白了,程序怎么寫自然就清楚了。
         尤其是寄存器。




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1