嵌入式基础

提取小时:

 #define Time_Addr 0xFFFFC0000 //实时钟芯片的IO映像基址是OxFFFFC0000
 #define TIME *(volatile int *)(Time_Addr+2) 
 int getHours() 
 {
 int time=TIME;
 return (time>>11)&0x1F;
 }

设置小时:

 #define TIME_Addr  0xFFFFC0000
 #define TIME *(volatile int *) (TIME_Addr+2)
 void SetHours(int hours)
 {
 int oldtime = TIME;
int newtime = oldtime & ~ (0x1F << 11);//将小时清零,保留分钟与秒钟
newtime |= (hours & 0x1F) << 11;//设置小时时间
TIME = newtime;
}

int getHours()
{
int time = TIME;
return (time>>11) & 0x1F;
}
posted @ 2022-12-22 09:01  棉被王Excalibur  阅读(15)  评论(0编辑  收藏  举报