FL2440无操作系统应用程序编写测试005——RTC
2011-11-09 13:43
260 查看
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;
}
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;
}
相关文章推荐
- FL2440无操作系统应用程序编写测试003——LED
- FL2440无操作系统应用程序编写测试010——TFTLCD
- FL2440无操作系统应用程序编写测试001——2440init.s分析修改
- FL2440无操作系统应用程序编写测试002——UART
- FL2440无操作系统应用程序编写测试011——IIS_AUDIO
- FL2440无操作系统应用程序编写测试004——PWM_TIMER
- FL2440无操作系统应用程序编写测试006——ADC
- FL2440无操作系统应用程序编写测试008——TOUCH SCREEN
- FL2440无操作系统应用程序编写测试009——WATCHDOG TIMER
- FL2440无操作系统应用程序编写测试007——KEY_INTERRUPT
- FL2440无操作系统应用程序编写测试012——DMA
- 30天自制操作系统------用C语言编写应用程序
- rtc应用程序编写
- 从零开始搭建环境编写操作系统 AT&T GCC (一)搭建环境和测试环境
- 编写一个单文档界面应用程序,该程序可以测试在鼠标左键按下时鼠标光标的位置是否处在某规定的矩形框内,如果不在该矩形内则计算机的扬声器会发出“叮”的声音,反之则会在用户区显示光标的位置。
- framebuffer实验:编写应用程序测试lcd驱动
- Linux下fl2440之led驱动编写以及测试
- 编写一个Android应用程序测试HelloService
- iOS应用程序测试打包
- 习题4:编写一个控制台应用程序,定义一个类MyClass,类中包含有public、private以及protected数据成员及方法。