欢迎各位大神指点,本人虚心接受。
程序功能:实时采集当前环境温度值,并显示于数码管上。文章源自微观生活(93wg.com)微观生活-https://93wg.com/3799.html
define uchar unsigned char #define uint unsigned int sbit DS=P2^2; //define interface uint temp; // variable of temperature uchar flag1; // sign of the result positive or negative sbit dula=P2^6; sbit wela=P2^7; unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd, 0x87,0xff,0xef}; void delay //delay { uint i; while { i=200; while i--; count--; } } void dsreset //send reset and initialization co妹妹and { uint i; DS=0; i=103; whilei--; DS=1; i=4; whilei--; } bit tmpreadbit //read a bit { uint i; bit dat; DS=0;i++; //i++ for delay DS=1;i++;i++; dat=DS; i=8;whilei--; return ; } uchar tmpread //read a byte date { uchar i,j,dat; dat=0; for { j=tmpreadbit; dat=|; //读出的数据最低位在最前面,这样恰好一个字节在DAT里 } return; } void tmpwritebyte //write a byte to ds18b20 { uint i; uchar j; bit testb; for { testb=dat&0x01; dat=dat>>1; if //write 1 { DS=0; i++;i++; DS=1; i=8;whilei--; } else { DS=0; //write 0 i=8;whilei--; DS=1; i++;i++; } } } void tmpchange //DS18B20 begin change { dsreset; delay; tmpwritebyte; // address all drivers on bus tmpwritebyte; // initiates a single temperature conversion } uint tmp //get the temperature { float tt; uchar a,b; dsreset; delay; tmpwritebyte; tmpwritebyte; a=tmpread; b=tmpread; temp=b; temp<<=8; //two byte compose a int variable temp=temp|a; tt=temp*0.0625; temp=tt*10+0.5; return temp; } void display//显示程序 { uchar A1,A2,A2t,A3; A1=temp/100; A2t=temp%100; A2=A2t/10; A3=A2t%10; dula=0; P0=table[A1];//显示百位 dula=1; dula=0; wela=0; P0=0x7e; wela=1; wela=0; delay; dula=0; P0=table1[A2];//显示十位 dula=1; dula=0; wela=0; P0=0x7d; wela=1; wela=0; delay; P0=table[A3];//显示个位 dula=1; dula=0; P0=0x7b; wela=1; wela=0; delay; } void main { uchar a; do { tmpchange; for { display); } } while; }
以上就是微观生活(93wg.com)关于“基于51单片机开发的温度计程序”的详细内容,希望对大家有所帮助!文章源自微观生活(93wg.com)微观生活-https://93wg.com/3799.html 文章源自微观生活(93wg.com)微观生活-https://93wg.com/3799.html
继续阅读
评论