S3C 2440 RTC 实时时钟 (miniarm 2440 )

rtc.h

 

#ifndef RTC_H #define RTC_H #include "2440addr.h" //实时时钟 数据 均为BCD编码 typedef struct tag_RtcTime { //year 默认从0x2000开始,如果要设置为2010年 // year 应赋值为0x10; U16 year; char month; char day; char week; char hour; char minite; char second; }RTC_TIME; void RtcSetTime(RTC_TIME rt); RTC_TIME RtcReadTime(void); #endif

 

 

rtc.c

 

 #include "rtc.h" void RtcSetTime(RTC_TIME rt) { rRTCCON = 0x01; //使能写 rBCDYEAR = rt.year; rBCDMON = rt.month; rBCDDATE = rt.week; rBCDDAY = rt.day; rBCDHOUR = rt.hour; rBCDSEC = rt.second; rBCDMIN = rt.minite; rRTCCON &=~0x01; } RTC_TIME RtcReadTime(void) { RTC_TIME rt; //.............. return rt; }

 

 

测试程序 main.c

 

#include "uart.h" #include "rtc.h" void delay(U32 tt) { U32 i; for(;tt>0;tt--) { for(i=0;i<10000;i++){} } } int Main(void) { //char buffer[50]={0}; RTC_TIME rt; rt.year=0x10; rt.month=0x01; rt.day=0x05; rt.week=0x02; rt.hour=0x22; rt.second=0x00; rt.minite=0x01; RtcSetTime(rt); UartInit(9600); //rRTCCON = 0x01; //使能写 while(1) { UartSendStr("RTC Test/r/n"); //sprintf(buffer,"%04x-%02x-%02x-%02x-%02x-%02x/r/n", // rBCDYEAR+0x2000,rBCDMON,rBCDDAY,rBCDHOUR,rBCDMIN,rBCDSEC); // UartSendStr(buffer); // UartPrintf("%x/r/n",255); UartPrintf("%04x-%02x-%02x/r/n",rBCDYEAR+0x2000,rBCDMON,rBCDDAY); delay(2000); } return 0; }

你可能感兴趣的:(c,struct,测试,buffer,2010,delay)