#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
#include"./delay/delay.h"
sbit DS = P2^7;
extern void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str);
extern void InitLcd1602();
bit ack = 0;
void DS18B20_init()
{
DS = 0;
delay_us(200);
delay_us(200);
DS = 1;
delay_us(30);
if(DS == 0)
{
ack = 1;
}
else
{
ack = 0;
}
delay_us(200);
}
void DS18B20_write_byte(unsigned char byte)
{
unsigned char i;
for(i = 0;i < 8; i++)
{
DS = 1;
DS = 0;
_nop_();
_nop_();
DS = byte & 0x01;
byte >>= 1;
delay_us(30);
}
delay_us(30);
DS = 1;
}
bit DS18B20_read_byte()
{
bit temp;
DS = 1;
DS = 0;
_nop_();
_nop_();
DS = 1;
temp = DS;
delay_us(30);
return temp;
}
unsigned char DS18B20_read_string()
{
unsigned char i,j,k ;
for(i = 0; i < 8; i++)
{
j = DS18B20_read_byte();
k = (j << 7)|(k >> 1);
}
return k;
}
void main()
{
unsigned char LSB;
unsigned int temp,MSB;
float temp_f;
unsigned char disbuf[20];
InitLcd1602();
while(1)
{
/*if(ack == 1)
{
LED = 0;
}*/
DS18B20_init();
DS18B20_write_byte(0xCC);
DS18B20_write_byte(0x44);
delay_ms(20);
DS18B20_init();
DS18B20_write_byte(0xCC);
DS18B20_write_byte(0xBE);
LSB = DS18B20_read_string();
MSB = DS18B20_read_string();
temp = (MSB<<8) + LSB;
temp_f = (float)temp * 0.0625;
sprintf(disbuf,"temp is %5.3f c",temp_f);
LcdShowStr(0,0,disbuf);
}
}
#include<intrins.h>
#include<stdio.h>
#include"./delay/delay.h"
sbit DS = P2^7;
extern void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str);
extern void InitLcd1602();
bit ack = 0;
void DS18B20_init()
{
DS = 0;
delay_us(200);
delay_us(200);
DS = 1;
delay_us(30);
if(DS == 0)
{
ack = 1;
}
else
{
ack = 0;
}
delay_us(200);
}
void DS18B20_write_byte(unsigned char byte)
{
unsigned char i;
for(i = 0;i < 8; i++)
{
DS = 1;
DS = 0;
_nop_();
_nop_();
DS = byte & 0x01;
byte >>= 1;
delay_us(30);
}
delay_us(30);
DS = 1;
}
bit DS18B20_read_byte()
{
bit temp;
DS = 1;
DS = 0;
_nop_();
_nop_();
DS = 1;
temp = DS;
delay_us(30);
return temp;
}
unsigned char DS18B20_read_string()
{
unsigned char i,j,k ;
for(i = 0; i < 8; i++)
{
j = DS18B20_read_byte();
k = (j << 7)|(k >> 1);
}
return k;
}
void main()
{
unsigned char LSB;
unsigned int temp,MSB;
float temp_f;
unsigned char disbuf[20];
InitLcd1602();
while(1)
{
/*if(ack == 1)
{
LED = 0;
}*/
DS18B20_init();
DS18B20_write_byte(0xCC);
DS18B20_write_byte(0x44);
delay_ms(20);
DS18B20_init();
DS18B20_write_byte(0xCC);
DS18B20_write_byte(0xBE);
LSB = DS18B20_read_string();
MSB = DS18B20_read_string();
temp = (MSB<<8) + LSB;
temp_f = (float)temp * 0.0625;
sprintf(disbuf,"temp is %5.3f c",temp_f);
LcdShowStr(0,0,disbuf);
}
}