article from: http://blog.sina.com.cn/s/blog_684e87fa0101005b.html
//====================================================================
// File Name : RTC.c
// Function : S3C24X0 RTC Test
// Program : Kang, Weon Tark
// Date : May 22, 2002
// Version : 0.0
// History
// 0.0 : Programming start (March 29,2002) -> KWT
// RTC Test -> May 15, 2002 SOP
//====================================================================
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
//==================================================================================
void RTC_Time_Set( void )
{
rRTCCON = 1 ;
//RTC read and write enable
rBCDYEAR = 0x05 ;
//年
rBCDMON = 0x06 ;
//月
rBCDDATE = 0x19 ;
//日
rBCDDAY = 0x02 ;
//星期
rBCDHOUR = 0x15 ;
//小时
rBCDMIN = 0x21 ;
//分
rBCDSEC = 0x30 ;
//秒
rRTCCON &= ~1 ;
//RTC read and write disable
}
//==================================================================================
void RTC_Display(void)
{
U16 year ;
U8 month, day ;
// week
U8 hour, minute, second ;
RTC_Time_Set() ;
Uart_Printf( "RTC TIME Display, press ESC key to exit !\n" ) ;
while( Uart_GetKey() != ESC_KEY )
{
rRTCCON = 1 ; //RTC read and write enable
year = 0x2000 rBCDYEAR ;
//年
month = rBCDMON ;
//月
day = rBCDDATE ;
//日
// week = rBCDDAY ;
//星期
hour = rBCDHOUR ;
//小时
minute = rBCDMIN ;
//分
second = rBCDSEC ;
//秒
rRTCCON &= ~1 ;
//RTC read and write disable
Uart_Printf( "RTC time : x-x-x x:x:x\n", year, month, day, hour, minute, second );
Delay( 900 ) ;
}
}
讲解上面程序的Uart_Printf()函数,在2440lib.c中有定义
void Uart_Printf(char *fmt,...)
//...表示可变参数(多个可变参数组成一
个列表,后面有专门的指针指向他),不限定个数和类型,
{
va_list ap
;//初始化指向可变参数列表的指针
char string[256];
va_start(ap,fmt);
//将第一个可变参数的地址付给ap,即ap指向可变参数列
表的开始
vsprintf(string,fmt,ap);
//将参数fmt、ap指向的可变参数一起转换成格式
化字符串,放string数组中,其作用同
sprintf(),只是参数类型不同
Uart_SendString(string);
//把格式化字符串从开发板串口送出去
va_end(ap);
//ap付值为0,没什么实际用处,主要是为程序健壮性
}
紧接着会遇到
void Uart_SendByte(int data)
//这个函数是发送整型数据,参数为data
{
if(whichUart==0
)
//这个是选中串口0
{
if(data=='\n')
//然后判断数据是否为空
{
while(!(rUTRSTAT0 & 0x2));
Delay(10);
//because the slow response of hyper_terminal
WrUTXH0('\r');
//下一行
}
while(!(rUTRSTAT0 & 0x2));
//Wait until THR is empty.
Delay(10);
WrUTXH0(data);
}
else if(whichUart==1)
{
if(data=='\n')
{
while(!(rUTRSTAT1 & 0x2));
Delay(10);
//because the slow response of hyper_terminal
rUTXH1 = '\r';
}
while(!(rUTRSTAT1 & 0x2));
//Wait until THR is empty.
Delay(10);
rUTXH1 = data;
}
else if(whichUart==2)
{
if(data=='\n')
{
while(!(rUTRSTAT2 & 0x2));
Delay(10);
//because the slow response of hyper_terminal
rUTXH2 = '\r';
}
while(!(rUTRSTAT2 & 0x2));
//Wait until THR is empty.
Delay(10);
rUTXH2 = data;
}
}