zoukankan      html  css  js  c++  java
  • 20155318 第十六周课堂实践——嵌入式基础

    20155318 第十六周课堂实践加分作业

    测试中错误部分的理解和学习

    根据下图,完成对时分秒的提取和设置

    课上提交的答案:

    错误原因:没有注意时间变量和地址问题,应在修改为:

    #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;
    }
    

    对上述代码需要注意的是*(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;
    }
    
  • 相关阅读:
    BERT 简介 P1_李宏毅
    GAN_P4 Learning from Unpaired Data_李宏毅
    GAN_P3_李宏毅
    Generation P1_李宏毅
    GAN_P2_Theory behind GAN_李宏毅
    李宏毅_Transformer p2
    李宏毅_Transformer p1
    强类型数据集 官方教程
    网页管理系统一
    读张子阳的用户验证自定义IPrincipal和IIdentity有感
  • 原文地址:https://www.cnblogs.com/lxy1997/p/8207300.html
Copyright © 2011-2022 走看看