溫度值精確到0.1度,lcd1602顯示
仿真電路圖如下
c程序如下:
#include
#define uchar unsigned char
#define uint unsigned int
sbit DQ=P3^7;//ds18b20與單片機(jī)連接口
sbit RS=P3^0;
sbit RW=P3^1;
sbit EN=P3^2;
unsigned char code str1[]={"temperature: "};
unsigned char code str2[]={" "};
uchar data disdata[5];
uint tvalue;//溫度值
uchar tflag;//溫度正負(fù)標(biāo)志
/*************************lcd1602程序**************************/
void delay1ms(unsigned int ms)//延時1毫秒(不夠精確的)
{unsigned int i,j;
for(i=0;i for(j=0;j<100;j++); } void wr_com(unsigned char com)//寫指令// { delay1ms(1); RS=0; RW=0; EN=0; P2=com; delay1ms(1); EN=1; delay1ms(1); EN=0; } void wr_dat(unsigned char dat)//寫數(shù)據(jù)// { delay1ms(1);; RS=1; RW=0; EN=0; P2=dat; delay1ms(1); EN=1; delay1ms(1); EN=0; } void lcd_init()//初始化設(shè)置// {delay1ms(15); wr_com(0x38);delay1ms(5); wr_com(0x08);delay1ms(5); wr_com(0x01);delay1ms(5); wr_com(0x06);delay1ms(5); wr_com(0x0c);delay1ms(5); } void display(unsigned char *p)//顯示// { while(*p!='