码迷,mamicode.com
首页 > 其他好文 > 详细

2017-2018-1 《信息安全系统设计基础》 20155322 十六周课上实践

时间:2018-01-05 23:31:32      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:time   def   .com   gets   image   gpo   blog   amp   时钟   

2017-2018-1 《信息安全系统设计基础》 20155322 十六周 课上实践

题目

技术分享图片

原理

实现

小时设置及提取

#define TIME_Addr  0xFFFFC0000                    //实时钟芯片的IO映像基址是OxFFFFC0000
#define TIME *(volatile int *) (TIME_Addr+2)      //时间存放在基址+2的寄存器中

void SetHours(int hours)
{
    int oldtime = TIME;
    int newtime = oldtime & ~ (0x1F << 11);
    newtime |= (hours & 0x1F) << 11;
    TIME = newtime;
}

int getHours()
{
    int time;
    time = (time>>11) & 0x1F;
    return time;
}

秒的设置及提取

#define TIME_Addr  0xFFFFC0000                  //实时钟芯片的IO映像基址是OxFFFFC0000
#define TIME *(volatile int *) (TIME_Addr+2)    //时间存放在基址+2的寄存器中

void SetSeconds(int seconds) 
{
    int oldtime=TIME;
    int newtime=oldtime&~0x1F;
    newtime|=seconds&0x1F;
    TIME=newtime;

}
int getSeconds() 
{
    int time;
    time=time&0x1F;
    return time ;
}

2017-2018-1 《信息安全系统设计基础》 20155322 十六周课上实践

标签:time   def   .com   gets   image   gpo   blog   amp   时钟   

原文地址:https://www.cnblogs.com/blackay03/p/8207237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!