• 第十六周课堂测试


    第十六周课堂测试

    课堂测试
    • 在作业本上完成附图作业,要认真看题目要求。
    • 提交作业截图
    • 作弊本学期成绩清零(有雷同的,不管是给别人传答案,还是找别人要答案都清零)

    #define Time_Addr 0xFFFFC0000 //实时钟芯片的IO映像基址是OxFFFFC0000
    #define TIME *(volatile int *)(Time_Addr+2) //时间存放在基址+2的寄存器中
    int getHours() 
    {
    int time=TIME;
    return (time>>11)&0x1F;
    }
    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;
    }
    
    • 提取hour时,采用的方法是先将hour右移11位,hour有5位,所以再与000000000000011111,即0X1F相与。

    • 需要注意的是*(volatile unsigned int *)0x500函数的运用,其含义是将地址0x500强制转化为int型指针,例如:

    *(unsigned int *)0x500=0x10 //对地址为0x500赋值为0x10

    课下作业—提取和置位秒

    秒的位置在0—4位,不需要进行移位操作,直接与0x1F相与

    • 提取秒:
    #define TIME_Addr  0xFFFFC0000
    #define TIME *(volatile int *) (TIME_Addr+2)//这里需要将地址+2
    int getSeconds()
    {
    int time = TIME;
    return time & 0x1F;
    }
    
    • 置位秒:
    #define TIME_Addr  0xFFFFC0000
    #define TIME *(volatile int *) (TIME_Addr+2)//这里需要将地址+2
    void SetSeconds(int seconds)
    {
    int oldtime = TIME;
    int newtime = oldtime & ~ 0x1F;
    newtime |= seconds & 0x1F;
    TIME = newtime;
    }
    
  • 相关阅读:
    CF601B Solution
    CF847F Solution
    CF877D Solution
    CF1472F Solution
    CF1472G Solution
    CF1355E Solution
    CF912D Solution
    CF1167F Solution
    shell脚本自动备份MySQL数据库
    centos7 crontab笔记
  • 原文地址:https://www.cnblogs.com/rh123456/p/8302292.html
Copyright © 2020-2023  润新知