下载手机汽配人

求求基于51单片机的数字温度计设计?单片机AT89C51?测温传感器使DS18B20?图在下面!只要c语言程序

问 提问者:网友 2018-08-07
最佳回答
====================================================================== #include"reg51.h" //包含头文件 #include #define uchar unsigned char #define uint unsigned int float tt; //tt为采集的温度值 code uchar TAB[]={0xc0,0xf9,0xa4,0xb0,0x99, 0x92,0x82,0xf8,0x80,0x90}; //数码管段码 uchar str_TME[4]={0,0,0,0}; unsigned char MAX=30; unsigned char MIN=10; sbit DQ =P2^4; //定义通信端口 sbit fm =P2^7; //短延时函数 void delay(unsigned int i) { while(i--); } //1ms延时函数 void delay1(uchar ms) { uchar i; while(ms--) for(i=0;i<125;i++); } //DS18B20初始化函数 Init_DS18B20(void) { unsigned char x=0; DQ = 1; //DQ复位 delay(8); //稍做延时 DQ = 0; //单片机将DQ拉低 delay(80); //精确延时 大于 480us DQ = 1; //拉高总线 delay(14); x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败 delay(20); } //读一个字节 ReadOneChar(void) { unsigned char i=0; unsigned char dat=0; for (i=8;i>0;i--) { DQ=0; // 给脉冲信号 dat>>=1; DQ=1; // 给脉冲信号 if(DQ) dat|=0x80; delay(4); } return(dat); } //写一个字节 WriteOneChar(unsigned char dat) { unsigned char i=0; for (i=8;i>0;i--) { DQ=0; DQ=dat&0x01; delay(5); DQ=1; dat>>=1; } delay
回答者:网友
产品精选
搜索问答
还没有汽配人账号?立即注册

我要提问

汽配限时折扣

本页是网友提供的关于“求求基于51单片机的数字温度计设计?单片机AT89C51?测温传感器使DS18B20?图在下面!只要c语言程序”的解答,仅供您参考,汽配人网不保证该解答的准确性。