zoukankan      html  css  js  c++  java
  • 第十六周课堂测试补充

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

    地址的定义部分错误

    C语言中
    *(volatile unsigned int *)0x500
    的解释:
    如下;

    (unsigned int *)0x500
    :将地址0x500
    强制转化为int型指针

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

    详见嵌入式中的 *(volatile unsigned int *)理解

    修改测试代码如下:

    #define DATA_Addr  0xFFFFC0000
    #define DATA	*(volatile int *) DATA_Addr
    
    void SetHours(int hours)
    {
        unsigned short time;
        time = (unsigned short)(DATA);
        time &= 0x07FF;//将hous小时所在的比特位置0
        DATA = ((unsigned short))(hours<<11)|time;//将要设置的hours变量通过移位变换到time变量中hours所在的比特位置,再与time以或运算合并
        
    }
    int getHours()
    {
        unsigned short time;
        time = (unsigned short)(DATA);
        return (int)((time>>11)&0x001f);//直接将time向右移动11位清除掉分钟和秒的比特位上的数据,再将hours之前的位清零;
        
    }
    

    测试:

    对于秒部分的提取和置位的学习

    这里直接给出代码因为seconds与上面同理只是位置不同

    #define DATA_Addr  0xFFFFC0000
    #define DATA	*(volatile int *) DATA_Addr
    
    void SetSeconds(int seconds)
    {
        unsigned short time;
        time = (unsigned short)(DATA);
        time &= 0xffe0;
        DATA = ((unsigned short))(seconds)|time;
        
    }
    int getSeconds()
    {
        unsigned short time;
        time = (unsigned short)(DATA);
        return (int)(time&0x001f);
        
    }
    
  • 相关阅读:
    网线接线分类
    MongoDB修改用户密码
    win10计算器和商店英文改中文
    电脑微信双开
    ajax
    get和post的区别
    javascript中各种继承方式的优缺点
    原型
    高阶函数的封装
    深浅拷贝
  • 原文地址:https://www.cnblogs.com/xhwh/p/8182834.html
Copyright © 2011-2022 走看看