1、DS18B20 温度控制 1602 LCD显示#include #include #define uchar unsigned char#define uint unsigned intsbit DQ = P22; /定义DS18B20端口DQ sbit BEEP=P23 ; /蜂鸣器驱动线bit presence,flag;bit compare_th,compare_tl,alarm_on_off=0,temp_th,temp_tl;sbit LCD_RS = P35; sbit LCD_RW = P36;sbit LCD_EN = P34;uchar code cdis1 = READ_
2、ROMCORD ;uchar code cdis2 = ;uchar code cdis3 = DS18B20 ERR0R ;uchar code cdis4 = PLEASE CHECK ;uchar code cdis5 = TEMP: ;uchar code cdis6 = TH: TL: ;unsigned char data temp_data2 = 0x00,0x00;unsigned char data temp_alarm2 = 0x20,0x10;unsigned char data display5 = 0x00,0x00,0x00,0x00,0x00; /温度值显示uns
3、igned char data display13 = 0x00,0x00,0x00; /温度报警值显示unsigned char data RomCode8 = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00; unsigned char code mytab18 = 0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00;unsigned char code mytab28 = 0x01,0x1b,0x1d,0x19,0x1d,0x1b,0x01,0x00;/小喇叭#define delayNOP(); _nop_();_nop_()
4、;_nop_();_nop_();unsigned char Temp,temp_comp,timecount,count;unsigned char crc;void Disp_Temp_alarm(uchar addr,uchar num);void spk(uchar addr);void set_temp_alarm();void temp_compare();void beep();/*/void delay1(int ms) unsigned char y; while(ms-) for(y = 0; y250; y+) _nop_(); _nop_(); _nop_(); _no
5、p_(); /*/* */*检查LCD忙状态 */*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 */* */*/ bit lcd_busy() bit result; LCD_RS = 0; LCD_RW = 1; LCD_EN = 1; delayNOP(); result = (bit)(P0&0x80); LCD_EN = 0; return(result); /*/* */*写指令数据到LCD */*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 */* */*/void lcd_wcmd(uchar cmd) delay1(10); LCD_
6、RS = 0; LCD_RW = 0; LCD_EN = 0; _nop_(); _nop_(); P0 = cmd; delayNOP(); LCD_EN = 1; delayNOP(); LCD_EN = 0; /*/* */*写显示数据到LCD */*RS=H,RW=L,E=高脉冲,D0-D7=数据。 */* */*/void lcd_wdat(uchar dat) delay1(10); LCD_RS = 1; LCD_RW = 0; LCD_EN = 0; P0 = dat; delayNOP(); LCD_EN = 1; delayNOP(); LCD_EN = 0; /*/* *
7、/*自定义字符写入CGRAM */* */*/void writetab() unsigned char i; lcd_wcmd(0x40); /写CGRAM for (i = 0; i 8; i+) lcd_wdat(mytab1i); for (i = 0; i 0; i-) DQ = 0; / 给脉冲信号 dat = 1; DQ = 1; / 给脉冲信号 if(DQ) dat |= 0x80; Delay(4); return (dat);/*/* */* 写一个字节 */* */*/ WriteOneChar(unsigned char dat) unsigned char i = 0; for (i = 8; i 0; i-)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1