文档详情

DS18B20温度显示演示程序-LCD1602显示.docx

发布:2018-06-12约6.56千字共9页下载文档
文本预览下载声明
/*DS18B20温度显示演示程序-LCD1602显示开机时对DS18B20进行检测,如果DS18B20检测不正常,LCD1602显示: DS18B20 ERROR PLEASE CHECK 蜂鸣器报警。DS18B20检测正常,LCD1602显示: DS18B20 OK TEMP: 100.8℃如果温度值高位为0,将不显示出来。你可以通过拔插DS18B20查看DS18B20的检测功能。*/#include reg51.h #include intrins.h #define uchar unsigned char#define uint unsigned intsbit DQ = P3^2 ; //定义DS18B20端口DQ sbit BEEP=P1^0 ; //蜂鸣器驱动线bit presence ;sbit LCD_RS = P1^0 ;sbit LCD_RW = P1^1;sbit LCD_EN = P1^2 ;uchar code cdis1[ ] = { DS18B20 OK } ;uchar code cdis2[ ] = { TEMP: . C } ;uchar code cdis3[ ] = { DS18B20 BUSY } ;uchar code cdis4[ ] = { PLEASE WAIT } ;unsigned char data temp_data[2] = {0x00,0x00} ;unsigned char data display[5] = {0x00,0x00,0x00,0x00,0x00} ;unsigned char code ditab[16] = {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04, 0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ;void beep() ; unsigned char code mytab[8] = {0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00} ;#define delayNOP() ; {_nop_() ;_nop_() ;_nop_() ;_nop_() ;} ;/*******************************************************************/void delay1(int ms){ unsigned char y ; while(ms--) { for(y = 0 ; y250 ; y++) { _nop_() ; _nop_() ; _nop_() ; _nop_() ; } }}/******************************************************************//*检查LCD忙状态 *//*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 *//******************************************************************/ bit lcd_busy() { bit result ; LCD_RS = 0 ; LCD_RW = 1 ; LCD_EN = 1 ; delayNOP() ; result = (bit)(P00x80) ; LCD_EN = 0 ; return(result) ; }/*写指令数据到LCD *//*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 *//*******************************************************************/void lcd_wcmd(uchar cmd){ while(lcd_busy()) ; LCD_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=数据。 *//*************************
显示全部
相似文档