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

unsigned char Ds18b20Init();

void Ds18b20WriteByte(unsigned char com); unsigned char Ds18b20ReadByte(); void Ds18b20ChangTemp(); void Ds18b20ReadTempCom(); int Ds18b20ReadTemp(); #endif 4.lcd.c #include\

void Lcd1602_Delay1ms(uint c) {

uchar a,b; for (; c>0; c--) { for (b=19;b>0;b--) {

for(a=1;a>0;a--);

}

//延时 }

}

#ifndef LCD1602_4PINS //当没有定义这个LCD1602_4PINS时

void LcdWriteCom(uchar com) //写入一个字节命令 { } #else

void LcdWriteCom(uchar com) {

LCD1602_E = 0;

LCD1602_E = 1; Lcd1602_Delay1ms(5); LCD1602_E = 0; LCD1602_E = 0; LCD1602_RS = 0; LCD1602_RW = 0;

LCD1602_DATAPINS = com; Lcd1602_Delay1ms(1);

LCD1602_RS = 0; LCD1602_RW = 0;

LCD1602_DATAPINS = com; //由于4位的接线是接到P0

口的高四位,所以传送高四位不用改 } #endif

//写入一个字节数据

LCD1602_E = 1; Lcd1602_Delay1ms(5); LCD1602_E = 0;

LCD1602_DATAPINS = com << 4; //发送低四位 Lcd1602_Delay1ms(1); LCD1602_E = 1; Lcd1602_Delay1ms(5); LCD1602_E = 0; Lcd1602_Delay1ms(1);

#ifndef LCD1602_4PINS

void LcdWriteData(uchar dat) {

LCD1602_E = 0; LCD1602_RS = 1;

LCD1602_RW = 0;

LCD1602_DATAPINS = dat; Lcd1602_Delay1ms(1);

LCD1602_E = 1; } #else

void LcdWriteData(uchar dat) {

LCD1602_E = 0; LCD1602_RS = 1; LCD1602_RW = 0;

//由于4位的接线是接到P0

Lcd1602_Delay1ms(5); LCD1602_E = 0;

LCD1602_DATAPINS = dat;

口的高四位,所以传送高四位不用改

Lcd1602_Delay1ms(1); LCD1602_E = 1; //写入时序 Lcd1602_Delay1ms(5); LCD1602_E = 0;

LCD1602_DATAPINS = dat << 4; //写入低四位 Lcd1602_Delay1ms(1);

LCD1602_E = 1; //写入时序 Lcd1602_Delay1ms(5); LCD1602_E = 0;

}

#endif

#ifndef

LCD1602_4PINS

void LcdInit()

{

LcdWriteCom(0x38); LcdWriteCom(0x0c); LcdWriteCom(0x06); LcdWriteCom(0x01); LcdWriteCom(0x80);

} #else

void LcdInit() { LcdWriteCom(0x32); LcdWriteCom(0x28); LcdWriteCom(0x0c); LcdWriteCom(0x06);

LcdWriteCom(0x01);

//LCD初始化子程序