DS18B20 and digital tube program

Publisher:化羽2015Latest update time:2015-04-27 Source: 51heiKeywords:DS18B20 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#define uint unsigned int
#define uchar unsigned char
sbit DQ=P2^0;//P2^0
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//without decimal point
uchar code tab1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//with decimal point
sbit wei0=P0^0;//P3^2
sbit wei1=P0^1;//P3^3
//sbit wei2=P1^2;
//sbit wei3=P1^3;
uchar disdata[2];
uint tvalue;
uchar tflag;
void delay(uint i)
{
  while(i--);
}
void ds1820rst()//Reset
{
  DQ=1;
  delay(4); DQ   =
  0;
  delay(100);    DQ       =    1
  ;
  delay(40); }
uchar ds1820rd
()//Read data
{
  uchar i;  uchar dat=0;     for    ( i=8;   i   >0;i-- )    {    DQ     =     0    ; data    10    )    ;     DQ=1;     wdata>>=1;   } } read_temp()/*read temperature value and convert*/ { uchar a,b; ds1820rst();    ds1820wr(0xcc);//*skip reading serial number*/ ds1820wr(0x44);//*start temperature conversion*/ ds1820rst();    ds1820wr(0xcc);//*skip reading serial number*/ ds1820wr(0xbe);//*read temperature*/ a=ds1820rd(); b=ds1820rd(); tvalue=b; tvalue<<=8; tvalue=tvalue|a;     if(tvalue<0x0fff)    tflag=0;     else    {tvalue=~tvalue+1; tflag=1;    } tvalue=(tvalue*0.0625);//0.625 temperature value is enlarged 10 times, accurate to 1 decimal placereturn (tvalue); } void ds1820disp()//temperature value display {     disdata[0]=tvalue/10;//ten digitsdisdata    [1]=tvalue%10;//one digitwei0    =0;    P1=tab[disdata[0]];    delay(250);  wei0=1;  wei1=0;  P1=tab[disdata[1]];  delay(250);  wei1=1; } void main() {         while(1)      {     read_temp();//read temperatureds1820disp        ();//display       } }















































 
 













  




      

   


Keywords:DS18B20 Reference address:DS18B20 and digital tube program

Previous article:Review PS2 keyboard decoding
Next article:LCD12864 specified position reverse display program

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号