日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

51/51單片機(jī)第9課:DS18B20溫度檢測(cè)系統(tǒng)

 xpxys99 2019-09-04

51/51單片機(jī)第9課:DS18B20溫度檢測(cè)系統(tǒng)

51/51單片機(jī)第9課:DS18B20溫度檢測(cè)系統(tǒng)

#include <reg51.h>//頭文件

#define uint unsigned int//宏定義

#define uchar unsigned char //宏定義

sbit DQ=P3^2;//18B20的2腳與單片機(jī)P3.2口相接

sbit P10=P1^0;//數(shù)碼管位選引腳P1.0

sbit P11=P1^1;//數(shù)碼管位選引腳P1.1

uchar temp;

code unsigned char sz []={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//0-9數(shù)組

void delay (uint t);//延時(shí)函數(shù)聲明

void delayms(uint a);//for語(yǔ)句延時(shí)函數(shù)聲明

void init();//18B20初始化程序聲明

void write (uchar dat);//寫1字節(jié)程序聲明

uchar read ();//讀1字節(jié)程序聲明

void display();//顯示程序聲明

uchar readtemp();//讀溫度程序聲明

void delay (uint t)//延時(shí)函數(shù)

{

while(t--);

}

void delayms(uint a) //for語(yǔ)句延時(shí)函數(shù)

{

uint x,y;

for(x=a;x>0;x--)

for(y=110;y>0;y--);

}

void init ()//18B20初始化程序

{

uchar n;

DQ=1;

delay(8);

DQ=0;

delay(80);

DQ=1;

delay(8);

n=DQ;

delay(4);

}

void write (uchar dat)//寫1字節(jié)程序

{

uchar i;

for (i=0;i<8;i++)

{

DQ=0;

DQ=dat&0x01;

delay (4);

DQ=1;

dat>>=1;//dat=dat>>1

}

delay(4);

}

uchar read ()//讀1字節(jié)程序

{

uchar i,value;

for (i=0;i<8;i++)

{

DQ=0;

value>>=1;

DQ=1;

if(DQ)

value|=0x80;

delay(4);

}

return value;

}

uchar readtemp()//讀溫度程序

{

uchar a,b;

init();

write (0xcc);

write (0x44);

delay (300);

init ();

write (0xcc);

write (0xbe);

a=read();

b=read();

b<<=4;

b+=(a&0xf0)>>4;

return b;

}

void display ()//顯示程序

{

P10=0;

P0=sz[temp/10];

delayms(2);

P10=1;

P11=0;

P0=sz[temp%10];

delayms(2);

P11=1;

}

void main()//主程序

{

while(1)

{

temp=readtemp();

display ();

}

}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多