#基于单片机的数字温度计设计60543 - 图文

2026/4/27 2:31:52

单片机课程设计报告

{

j=RdBit(); d=(j<<7)|(d>>1); }

return d; }

/*---------------- 写入字节数据 ----------------*/ void WrByte(uchar d) {

uint i; uchar j; bit btmp;

for(j=0;j<8;j++) //各位由低向高写入DS18B20 {

btmp=d&0x01; d=d>>1;

if(btmp) //写1 {

DQ=0; //延时15us i++; i++;

DQ=1; //写1时隙不低于60u i=8;

while(i>0) i--; }

else //写0 {

DQ=0; i=8;

20

单片机课程设计报告

while(i>0) i--; //保持低电平60us到120us DQ=1; //释放总线 i++; i++; } } }

/*---------------- 启动温度转换 ----------------*/ void Convert() {

uint i;

Delay(125); //延时1ms TxReset(); //初始化DS18B20 RxWait(); //等待DS18B20应答 Delay(125); //延时

WrByte(0xcc); //跳过ROM命令 WrByte(0x44); //温度转换命令 for(i=0;i<250;i++) //延时1s Display(); }

/*----------------- 读取温度值 -----------------*/ void RdTemp(void) {

short int temp; uint x; bit flag = 1;

TxReset(); //初始化DS18B20 RxWait(); //等待DS18B20应答 Delay(125); //延时

21

单片机课程设计报告

WrByte(0xcc); //跳过ROM命令 WrByte(0xbe); //读暂存存储器命令

templow = RdByte(); //温度值低字节,低4位为小数 temphigh = RdByte(); //温度值高字节

temp = (temphigh << 8) | templow; //温度为16位补码 if(temp<0) //负温度 {

flag = 0; temp = ~temp + 1; }

tempzheng = temp >> 4; //温度值整数 x = temp & 0x000f;

tempxiao = (x*10)/16; //温度值小数 if(flag) //正温度

disp[0] = tempzheng/100; //百位 else //负温度

disp[0] = 16; //负号

disp[1] = (tempzheng0)/10; //十位 disp[2] = tempzheng; //个位 disp[3] = tempxiao; //小数 }

/*-------------------- 延时 -------------------*/ void Delay(uint x) {

uint i;

for(i=x;i>0;i--); }

/*---------------- 数码管显示 -----------------*/ void Display()

22

单片机课程设计报告

{

uchar i,j; j=0x08;

for(i=0;i<4;i++) {

P1=j; //数码管位码输出 LOCK=1; //打开锁存 if(i==2)

P0=led[disp[i]]|0x01; //显示小数点

else P0=led[disp[i]]; //数码管段码输出

LOCK=0; //关闭锁存 j=j>>1; //调整位码 Delay(125); P0=0x00; } }

23


#基于单片机的数字温度计设计60543 - 图文.doc 将本文的Word文档下载到电脑
搜索更多关于: #基于单片机的数字温度计设计60543 - 图文 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219