91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 26KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發布日期: 2023-02-08
  • 語言: 其他
  • 標簽: DS18B20??

資源簡介

DS18B20單總線讀取溫度,不占用其它端口

資源截圖

代碼片段和文件信息

/**********************BST-V51實驗開發板例程************************
*??平臺:BST-V51?+?Keil?U3?+?STC89C52
*??名稱:實時采集當前環境溫度值,并顯示于數碼管上
*??公司:深圳市亞博軟件開發有限公司
*??淘寶:bstmcu.taobao.com???????
*??日期:2012-8-14
*??晶振:11.0592MHZ
*??說明:免費開源,不提供源代碼分析.
******************************************************************/


#include?
#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[]={0x3f0x060x5b0x4f0x660x6d0x7d
????????????????????????0x070x7f0x6f0x770x7c0x390x5e0x790x71};
unsigned?char?code?table1[]={0xbf0x860xdb0xcf0xe60xed0xfd
????????????????????????0x870xff0xef};

void?delay(uint?count)??????//delay
{
??uint?i;
??while(count)
??{
????i=200;
????while(i>0)
????i--;
????count--;
??}
}
void?dsreset(void)???????//send?reset?and?initialization?command
{
??uint?i;
??DS=0;
??i=103;
??while(i>0)i--;
??DS=1;
??i=4;
??while(i>0)i--;
}

bit?tmpreadbit(void)???????//read?a?bit
{
???uint?i;
???bit?dat;
???DS=0;i++;??????????//i++?for?delay
???DS=1;i++;i++;
???dat=DS;
???i=8;while(i>0)i--;
???return?(dat);
}

uchar?tmpread(void)???//read?a?byte?date
{
??uchar?ijdat;
??dat=0;
??for(i=1;i<=8;i++)
??{
????j=tmpreadbit();
????dat=(j<<7)|(dat>>1);???//讀出的數據最低位在最前面,這樣剛好一個字節在DAT里
??}
??return(dat);
}

void?tmpwritebyte(uchar?dat)???//write?a?byte?to?ds18b20
{
??uint?i;
??uchar?j;
??bit?testb;
??for(j=1;j<=8;j++)
??{
????testb=dat&0x01;
????dat=dat>>1;
????if(testb)?????//write?1
????{
??????DS=0;
??????i++;i++;
??????DS=1;
??????i=8;while(i>0)i--;
????}
????else
????{
??????DS=0;???????//write?0
??????i=8;while(i>0)i--;
??????DS=1;
??????i++;i++;
????}

??}
}

void?tmpchange(void)??//DS18B20?begin?change
{
??dsreset();
??delay(1);
??tmpwritebyte(0xcc);??//?address?all?drivers?on?bus
??tmpwritebyte(0x44);??//??initiates?a?single?temperature?conversion
}

uint?tmp()???????????????//get?the?temperature
{
??float?tt;
??uchar?ab;
??dsreset();
??delay(1);
??tmpwritebyte(0xcc);
??tmpwritebyte(0xbe);
??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(uint?temp) //顯示程序
{
???uchar?A1A2A2tA3;
???A1=temp/100;
???A2t=temp%100;
???A2=A2t/10;
???A3=A2t%10;
???dula=0;
???P0=table[A1]; //顯示百位
???dula=1;
???dula=0;

???wela=0;
???P0=0xfe;
???wela=1;
???wela=0;
???delay(1);

???dula=0;
???P0=table1[A2]; //顯示十位
???dula=1;
???dula=0;

???wela=0;
???P0=0xfd;
???wela=1;
???wela=0;
???delay(1);

???dula=0;
???P0=table[A3]; //顯示個位
???dula=1;
???dula=0;

???wela=0;
???P0=0xfb;
???wela=1;
???wela=0;
???delay(1);
}


void?main()
{
?uchar?a;
??do
??{
????tmpcha

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????8241??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20
?????文件????????3200??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20.c
?????文件????????3833??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20.hex
?????文件??????????27??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20.lnp
?????文件????????6914??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20.LST
?????文件???????12942??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20.M51
?????文件????????8315??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20.OBJ
?????文件?????????976??2013-10-31?19:34??【實驗57】溫度計DS18B20\18b20.opt.bak
?????文件?????????484??2015-10-12?18:50??【實驗57】溫度計DS18B20\18b20.plg
?????文件????????2138??2012-02-15?20:28??【實驗57】溫度計DS18B20\18b20.Uv2.bak
?????文件???????55695??2015-10-12?19:35??【實驗57】溫度計DS18B20\18b20.uvopt
?????文件???????13228??2015-10-12?19:35??【實驗57】溫度計DS18B20\18b20.uvproj
?????文件?????????983??2012-02-15?20:28??【實驗57】溫度計DS18B20\18b20_Opt.Bak
?????文件????????2105??2010-06-29?12:56??【實驗57】溫度計DS18B20\18b20_Uv2.Bak

評論

共有 條評論