标题: 单片机C语言读位程序问题 高八位第八位是通过什么读的? [打印本页]

作者: cwz666    时间: 2022-4-9 17:30
标题: 单片机C语言读位程序问题 高八位第八位是通过什么读的?
uint tmp()               //get the temperature
{
  float tt;
  uchar a,b;
  dsreset();
  delay(1);
  tmpwritebyte(0xcc);
  tmpwritebyte(0xbe);
  a=tmpread();读取温度低8位
  b=tmpread();读取温度高8位
  temp=b;
  temp<<=8;             //two byte  compose a int variable
  temp=temp|a;
  tt=temp*0.0625;
  temp=tt*10+0.5;
  return temp;
}
高八位第八位是通过什么读的?


作者: zhxiufan    时间: 2022-4-9 20:22
亲,高八位是tmpread()这个函数读出来的,你看这个函数就知道了
作者: wulin    时间: 2022-4-9 20:39
                        temp=ReadTemperature(); //读取温度
                        if(temp&0x8000)//读高八位的最高位
                        {
                                negative=1;                        //负号标志
                                temp=~temp+1;                //取反加1
                        }
                        else negative=0;                //正数

                        TempH=temp>>4;                //分解出整数
                        TempL=temp&0x0F;        //分解出小数
                        TempL=TempL*6.25;        //保留两位小数




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1