FL2440无操作系统应用程序编写测试005——RTC

来源:互联网 发布:广联达的三个软件 编辑:程序博客网 时间:2024/05/22 00:46
Subject:FL2440无操作系统应用程序编写测试005——RTC

Date:  9-Nov-2011

By:       Calvinlee1984@163.com

 

1.RTC POWER原理图

 

2. 实时时钟信号源接线图

 

 

3. RTC控制框图

 

4.寄存器设置

static void RTC_Time_Set( void )

{

        //使能RTC读写

       rRTCCON = (0x1<<0) ;        //RTC read and write enable

      

 

        //年

        rBCDYEAR = 0x11 ;      //year

       

 

        //月

        rBCDMON  = 0x11 ;    //month

       

 

        //日

        rBCDDATE = 0x09 ;      //date

       

 

        //时

        rBCDHOUR = 0x21 ;     //hour

       

 

        //分

        rBCDMIN  = 0x40 ;     //minute

       

 

        //秒

        rBCDSEC  = 0x23 ;      //Second

       

 

        //禁止RTC读写

        rRTCCON &= ~(0x1<<0) ;          //RTC read and write disable

      

}

 

5.代码分析 RTC.c

#include "2440addr.h"

#include "def.h"

#include "UART.h"

 

//RTC时间设置     

static void RTC_Time_Set( void )

{

        //使能RTC读写

       rRTCCON = 1 ;            //RTC read and write enable       

 

        rBCDYEAR = 0x11 ;      //年

        rBCDMON  = 0x11 ;    //月

        rBCDDATE = 0x09 ;      //日 

        rBCDHOUR = 0x13 ;     //小时

        rBCDMIN  = 0x40 ;     //分

        rBCDSEC  = 0x23 ;      //秒

 

       //禁止RTC读写

       rRTCCON &= ~1 ;        //RTC read and write disable

}

 

//RTC时间显示

void RTC_Time_Display(void)

{

       U16 year ;

       U8 month,day,hour, minute, second ;

       U8 i,TmpSec=0;

       RTC_Time_Set();   //RTC时间设置

 

       while(UART0_GetKey() != ESC_KEY)

    {

               //使能RTC读写

               rRTCCON = 1 ;            //RTC read and write enable

 

               //读取时间数据

               year = 0x2000+rBCDYEAR ; //年

               month = rBCDMON  ;         //月

               day = rBCDDATE  ;            //日 

               hour = rBCDHOUR  ;          //小时

               minute = rBCDMIN  ;         //分

               second = rBCDSEC  ;         //秒

       

               //禁止RTC读写

               rRTCCON &= ~1 ;        //RTC read and write disable

       

               if(TmpSec!= second)    //每秒更新一次

               {

                      //按指定格式将时间数据输出至终端

                  UART0_Printf( "%04x-%02x-%02x %02x:%02x:%02x", year, month, day, hour, minute, second );

 

                  TmpSec = second;

                 

                  for(i=0;i<19;i++)

                         UART0_SendChar(BACK_KEY);          //覆盖原有显示数据

                  }

           }

}

 

6.  测试程序及结果

#include "UART.h"

#include "RTC.h"

 

int Main(void)

{

       UART0_Port_Init(115200);  //UART0端口初始化

       RTC_Time_Display();          //实时时间显示

       while(1){

              ;                   

       }

       return 0; 

}

 

 

原创粉丝点击