RTC_check.c
上传用户:jinguanrq
上传日期:2022-06-04
资源大小:724k
文件大小:7k
源码类别:

uCOS

开发平台:

C/C++

  1. //****-------------------------------------------------------------------------
  2. //* Embest Info&Tech Co.,LTD. 
  3. //* Technology & Software Support  Team                    -  Rijing  -
  4. //****-------------------------------------------------------------------------
  5. //+ 深圳市英蓓特信息技术有限责任公司
  6. //+ http://www.embedinfo.com http://www.embed.com.cn
  7. //+ Tel: 86-755-25631365     Fax:86-755-25616057
  8. //+ Email:support@embedinfo.com
  9. //****-------------------------------------------------------------------------
  10. //+ Create: Rijing Date: 2003.08.25
  11. //+
  12. //+ Modify: (1) Rijing upDate: 2003.08.25
  13. //+ () upDate: 
  14. //+ () upDate: 
  15. //+ () upDate: 
  16. //+
  17. //****-------------------------------------------------------------------------
  18. //+Demo:
  19. //+
  20. //****-------------------------------------------------------------------------
  21. #include "44blib.h"
  22. #include "44b.h"
  23. #include "rtc.h"
  24. extern char *date[8];
  25. char User_Getch(void);
  26. char USE_RTC(void);
  27. char check_RTC(void);
  28. void EV40_rtc_Disp(void);
  29. extern void Read_Rtc(void);
  30. char check_RTC(void)
  31. {
  32.     char RTC_alr = 0;
  33. /*   //check RTC code        
  34.     char yn = 0x59;
  35.    
  36.     while((yn ==0x0d)|(yn ==0x59)|(yn ==0x79)|(RTC_alr ==0))
  37.      {
  38.        Uart_Printf("n RTC Check(Y/N)? ");
  39.        
  40.        yn = Uart_Getch();
  41.        if((yn == 0x4E)|(yn == 0x6E)|(yn == 0x59)|(yn == 0x79))  Uart_SendByte(yn);
  42.        if((yn == 0x0d)|(yn == 0x59)|(yn == 0x79))
  43.          {
  44.            RTC_alr = Test_Rtc_Alarm();
  45.            Display_Rtc();
  46.          }
  47.        else break;
  48.        if (RTC_alr) break;
  49.      }
  50. */
  51.     //RTC_alr = Test_Rtc_Alarm();
  52.     Display_Rtc();
  53.     return RTC_alr;   
  54. }
  55.     
  56. char USE_RTC(void)
  57. {
  58. char yn,tmp,i,N09=1;
  59. char num0 = 0x30;//"0";
  60. char num9 = 0x39;//"9";
  61. char schar[] ={0,'-',' ',':'};
  62. char sDATE[12];//xxxx-xx-xx x
  63. char sTIME[8];//xx:xx:xx
  64. if(check_RTC())
  65.      {      
  66.   Uart_Printf("n RTC Working now. To set time(Y/N)? ");
  67. #if 1
  68.   Uart_Printf("n RTC Working now. To set time(Y/N)? ");
  69.           
  70.       yn = Uart_Getch();
  71.       if((yn == 0x4E)|(yn == 0x6E)|(yn == 0x59)|(yn == 0x79))  Uart_SendByte(yn);
  72.       if((yn == 0x0d)|(yn == 0x59)|(yn == 0x79))  //want to set time?
  73.        {
  74. ///////////////////////////////////////////////////////////////////////////////////         
  75.         do{
  76.           Uart_Printf("nCurrent day is (%04x,%02x,%02x, %s). To set day(yy-mm-dd w): "
  77.                        ,year,month,day,date[weekday]);
  78.   
  79.           Uart_GetString(sDATE);  
  80.           if(sDATE[0] == 0x32) 
  81.            {
  82.             if((sDATE[4] == schar[1] )&(sDATE[7] == schar[1] )&(sDATE[10] == schar[2] ))
  83.              {
  84.                if((sDATE[11] >0)|(sDATE[11] <8))
  85.                 {
  86.                   i=0; N09 = 0;
  87.                   while(i<12)
  88.                    {
  89.                      if((i !=4)|(i !=7)|(i !=10))
  90.                       {
  91.                         if((sDATE[i] < num0 )&(sDATE[i] > num9))
  92.                          { N09 = 1; 
  93.                            break;  }
  94.                       }
  95.                      i++;
  96.                    }
  97.                   if(N09 == 0)
  98.                     break;//all right
  99.                 }        // if date 1 - 7
  100.               }         // if "-" or " "
  101.            }           // if 32 (21th century)
  102.           
  103.           N09 = 1;
  104.           Uart_Printf("n Wrong value!!  To set again(Y/N)? ");        
  105.           
  106.           yn = Uart_Getch();  //want to set DATE again?
  107.           if((yn == 0x4E)|(yn == 0x6E)|(yn == 0x59)|(yn == 0x79))  Uart_SendByte(yn);
  108.          }while((yn == 0x0d)|(yn == 0x59)|(yn == 0x79));
  109.         if(N09 ==0)
  110.          {
  111.           rRTCCON  = 0x01;        // R/W enable, 1/32768, Normal(merge), No reset
  112.           rBCDYEAR = ((sDATE[2]<<4)|0x0f)&(sDATE[3]|0xf0);//->syear;
  113.           rBCDMON  = ((sDATE[5]<<4)|0x0f)&(sDATE[6]|0xf0);//->smonth;
  114.           rBCDDAY  = ((sDATE[8]<<4)|0x0f)&(sDATE[9]|0xf0);//->sday;
  115.           
  116.           tmp      = ((sDATE[11]&0x0f)+1);
  117.           if(tmp ==8) rBCDDATE = 1;// SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
  118.           else        rBCDDATE = tmp;
  119.           
  120.           rRTCCON  = 0x00;        // R/W disable
  121.           
  122.          }else Uart_Printf("nn Use Current DATE Settings.n");
  123. ///////////////////////////////////////////////////////////////////////////////////   
  124.         do{
  125.           Uart_Printf("nCurrent time is (%02x:%02x:%02x). To set time(hh:mm:ss): "
  126.                        ,hour,min,sec);
  127.           Uart_GetString(sTIME);
  128.           
  129.             if((sTIME[2] == schar[3] )&(sTIME[5] == schar[3]))
  130.              {
  131.                i=0; N09 = 0;
  132.                while(i<8)
  133.                 {
  134.                  if((i !=2)|(i !=5))
  135.                   {
  136.                    if((sTIME[i] < num0 )&(sTIME[i] > num9))
  137.                     { N09 = 1;
  138.                       break;  }
  139.                   }
  140.                  i++;
  141.                 }
  142.                if(N09 == 0)
  143.           {
  144.           tmp = ((sTIME[0]<<4)|0x0f)&(sTIME[1]|0xf0);
  145.           if((tmp >0)&(tmp <0x24))          
  146.            { 
  147.             sTIME[2] = tmp;//->shour;
  148.             
  149.             tmp  = ((sTIME[3]<<4)|0x0f)&(sTIME[4]|0xf0);          
  150.             if(tmp <=0x59)          
  151.              {
  152.                sTIME[5] = tmp;//->smin;
  153.                
  154.                tmp  = ((sTIME[6]<<4)|0x0f)&(sTIME[7]|0xf0);
  155.                if(tmp <=0x59) 
  156.                  break;//all right
  157.               }       //if min < 59
  158.             }        //if 0 < hour < 24
  159.           }         //if num 0-9
  160.                                              
  161.              }
  162.           N09 = 1;
  163.           Uart_Printf("n Wrong value!!  To set again(Y/N)? ");        
  164.         
  165.           yn = Uart_Getch();  //want to set Time again?
  166.           if((yn == 0x4E)|(yn == 0x6E)|(yn == 0x59)|(yn == 0x79))  Uart_SendByte(yn);
  167.          }while((yn == 0x0d)|(yn == 0x59)|(yn == 0x79));
  168.         if(N09 ==0)
  169.          {
  170.           rRTCCON  = 0x01;    // R/W enable, 1/32768, Normal(merge), No reset
  171.           rBCDHOUR = sTIME[2]; //->shour;     
  172.           rBCDMIN  = sTIME[5]; //->smin;
  173.           rBCDSEC  = ((sTIME[6]<<4)|0x0f)&(sTIME[7]|0xf0); //->ssec;
  174.           rRTCCON  = 0x00;    // R/W disable
  175.           
  176.          }else Uart_Printf("nn Use Current TIME Settings.n");
  177.          return 1;
  178.   
  179.       }else{
  180.       
  181.           Uart_Printf("n Use Current Settings...n");
  182.           return 1;
  183.       } /* end if want to set? */
  184. #endif
  185.      }else{
  186.      
  187.           Uart_Printf("n Please check RTC or maybe it's Wrong. n");
  188.           return 0;
  189.       } /* end if(check_RTC) */
  190.      
  191. }
  192. void EV40_rtc_Disp()
  193. {
  194. //while(rBCDSEC==0);
  195. if(rBCDYEAR == 0x99) 
  196.     year = 0x1999;
  197. else 
  198.     year = 0x2000 + rBCDYEAR;
  199.     month   = rBCDMON;
  200. day     = rBCDDAY;
  201. weekday = rBCDDATE;     
  202.     Uart_Printf("%04x,%02x,%02x,%s ",year,month,day,date[weekday]);
  203. //while(Uart_GetKey()!='R')
  204.  //{
  205.     hour=rBCDHOUR;
  206.     min=rBCDMIN;
  207.     sec=rBCDSEC;
  208.     
  209.         Uart_Printf(" %02x:%02x:%02xr",hour,min,sec);
  210.         
  211.     if((sec==59)&(hour==24)&(min==59))
  212.      {
  213.        sec = rBCDSEC;
  214.    while(sec)
  215.    {
  216.     sec = rBCDSEC;
  217.    }
  218.       // break;
  219.      }
  220.         // }
  221. }