读取DS18B20温度,通过LCD1602显示出来,并输出控制汇总 下载本文

电路原理图

程序

1.main.c

#include #include\#include\void LcdDisplay(int); sbit K1=P2^0; sbit K2=P2^1; sbit K3=P2^2; sbit K4=P2^3; extern int th=20; extern int tl=-10; sbit beep=P1^0;

void main() {

LcdInit();

LcdWriteCom(0xc7); LcdWriteData('C'); while(1) { if(K1==0) {

Delay1ms(500); if(K1==0); th++; } if(K2==0) {

Delay1ms(500); if(K2==0); th--; } if(K3==0) {

Delay1ms(500);

if(K3==0); tl++; } if(K4==0) {

Delay1ms(500); if(K4==0); tl--; }

LcdDisplay(Ds18b20ReadTemp()); }

}

void LcdDisplay(int temp) {

int i,tt,rr,mm;

unsigned char datas[] = {0, 0, 0, 0},datas2[] = {0, 0, 0};

float tp;

if(temp< 0)

{ LcdWriteCom(0xc0);

LcdWriteData('-');

0},datas1[] = {0, 0,

i=1;

temp=temp-1; temp=~temp; tp=temp;

temp=tp*0.0625*10+0.5; mm=-temp;

} else {

LcdWriteCom(0xc0); LcdWriteData('+'); }

datas[0] = temp / 1000; tp=temp;

temp=tp*0.0625*10+0.5; mm=temp;

datas[1] = temp % 1000 / 100; datas[2] = temp % 100 / 10; datas[3] = temp% 10; if(th < 0)

{

LcdWriteCom(0x89);

LcdWriteData('-'); tt=-th;

} else {

LcdWriteCom(0x89); LcdWriteData('+'); }

datas1[0] = tt / 100; datas1[1] = tt% 100 / 10; datas1[2] = tt % 10; LcdWriteCom(0x87); LcdWriteData('H'); LcdWriteCom(0x88); LcdWriteData(':'); LcdWriteCom(0x8a);

tt=th;

LcdWriteData('0'+datas1[0]); LcdWriteCom(0x8b);

LcdWriteData('0'+datas1[1]); LcdWriteCom(0x8c);

LcdWriteData('0'+datas1[2]);