1. 程式人生 > >2017-2018-1 《信息安全系統設計基礎》 20155322 十六周課上實踐

2017-2018-1 《信息安全系統設計基礎》 20155322 十六周課上實踐

ret 信息安全 inf com ati hour 圖片 分享 ()

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 十六周課上實踐