DHT11在1602上显示
DHT11测温湿度程序lcd1602显示
DHT11测温湿度程序lcd1602显示#include<reg52.h>#include<intrins.h>#define uchar unsigned char #define uint unsigned int #define Data P0 //数据端口sbit RS=P2^4;sbit RW=P2^5;sbit E=P2^6;sbit DHT=P1^0;uchar FirstLine[] ="wen:00.00"; //第一行数据uchar SecondLine[]="shi:00.00"; //第二行数据unsigned char shiZ,shiX,wenZ,wenX,check;unsigned char tr_shiZ,tr_shiX,tr_wenZ,tr_wenX;unsigned char flag;unsigned int n=20,m;void delay_1ms(unsigned int i) {unsigned int j=88;for(;i>0;i--){while(j>0)j--;}}void delay_10us(){unsigned char i;i--;i--;i--;i--;i--;i--;}/******************************************/ /*************温湿度读取函数***************/ /******************************************/ char read_data(){unsigned char i,num,temp;num=0;for(i=0;i<8;i++){flag=2;while((!DHT)&&flag++);delay_10us();delay_10us();delay_10us();if(DHT==1){temp=1;flag=2;while(DHT&&flag++);}elsetemp=0;num<<=1;num|=temp;}return(num);}void delay(uchar ms) // 延时函数ms毫秒 { uchar i,j;for(i=ms;i>0;i--) for(j=100;j>0;j--); }void DelayUs(unsigned char us) //--延时函数 { unsigned char uscnt;uscnt=us>>1; /*12MHz频率*/while(--uscnt); }void DelayMs(unsigned char ms){while(--ms){DelayUs(250);DelayUs(250);DelayUs(250);DelayUs(250);}}void lcd_write_com(uchar c) //写命令 { DelayMs(5);//操作前短暂延时,保证信号稳定E=0;RS=0;RW=0;_nop_();E=1;Data=c;E=0;}void lcd_write_dat(uchar c) //写数据 { DelayMs(5); //操作前短暂延时,保证信号稳定E=0;RS=1;RW=0;_nop_();E=1;Data=c;E=0;RS=0;}void lcd_init() //LCD初始化{DelayMs(15);lcd_write_com(0x38); //display modelcd_write_com(0x38); //display modelcd_write_com(0x38); //display modelcd_write_com(0x06); //显示光标移动位置lcd_write_com(0x0c); //显示开及光标设置lcd_write_com(0x01); //显示清屏}void ShowChar(uchar pos,uchar c) //显示单个字符 { unsigned char p;if (pos>=0x10)p=pos+0xb0; //是第二行则命令代码高4位为0xcelsep=pos+0x80; //是第二行则命令代码高4位为0x8lcd_write_com(p);//写命令lcd_write_dat(c); //写数据}void ShowString (uchar line,char *ptr) //显示字符串{unsigned char l,*p;p=ptr;l=line<<4;while((*p)!='\0'){ShowChar(l++,*(p));p++;}}void disp(void) //主函数调用的显示函数 {ShowString(0,FirstLine);ShowString(1,SecondLine); }/******************************************//************初始化及采集程序**************//******************************************/ void read_init(){DHT=0; //主机使DHT11低电平并延时至少18msdelay_1ms(21);DHT=1; //主机置DHT11高电平20~40us,并等待从机相应delay_10us();delay_10us();delay_10us();delay_10us();DHT=1;if(!DHT) //从机发出相应信号{flag=2;while((!DHT)&&flag++);flag=2;while(DHT&&flag++); //开始采集数据tr_shiZ=read_data();//采集湿度整数部分tr_shiX=read_data();//采集湿度小数部分tr_wenZ=read_data();//采集温度整数部分tr_wenX=read_data();//采集温度小数部分check=read_data(); //采集校验位DHT=1;}}void main(){unsigned char temp;lcd_init();delay(50);while(1){disp();read_init();temp=tr_shiZ+tr_shiX+tr_wenZ+tr_wenX;if(check==temp){shiZ=tr_shiZ;shiX=tr_shiX;wenZ=tr_wenZ;wenX=tr_wenX;}FirstLine[4]='0'+wenZ/10; FirstLine[5]='0'+wenZ%10; FirstLine[8]='0'+wenX/10; FirstLine[9]='0'+wenX%10; SecondLine[4]='0'+shiZ/10; SecondLine[5]='0'+shiZ%10; SecondLine[8]='0'+shiX/10; SecondLine[9]='0'+shiX%10; }}。
Arduino从DHT11读取温湿度数据并显示在1602LCD
Arduino从DHT11读取温湿度数据并显⽰在1602LCD硬件清单Arduino NANO1602LCD + PCF8574T模块YL-47 DHT11模块连线1. 连接LCD: PCF8574T模块4pin(Gnd, Vcc, SDA i2c数据, SCL i2c时钟) 连接⾄Arduino接⼝ Gnd -> Gnd, Vcc -> Vcc, SDA -> A4, SDL -> A52. 连接YL-47 DHT11: Gnd -> Gnd, Vcc -> Vcc, Data-> D4Library除了1602需要的库以外, 需要安装两个⾃带的库: DHT Sensor Library by Adafruit, Adafruit Unified Sensor测试代码#include <Wire.h>#include <LiquidCrystal_I2C.h>#include <DHT.h>#define DHTPIN 4#define DHTTYPE DHT11// I2C地址, ⼀般为0x3F, 0x20或0x27LiquidCrystal_I2C lcd(0x27,16,2);// 初始化DHTDHT dht(DHTPIN, DHTTYPE);void setup() {lcd.init();lcd.backlight(); // 打开背光Serial.begin(9600);dht.begin();lcd.setCursor(0,0); // line 0, pos 0lcd.print("Good Day!");lcd.setCursor(0,1); // line 1, pos 0lcd.print("H: % T:");delay(1000);}void loop() {// Reading temperature or humidity takes about 250 milliseconds!// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)float h = dht.readHumidity();// Read temperature as Celsius (the default)float t = dht.readTemperature();// Read temperature as Fahrenheit (isFahrenheit = true)float f = dht.readTemperature(true);// Check if any reads failed and exit early (to try again).if (isnan(h) || isnan(t) || isnan(f)) {Serial.println("Failed to read from DHT sensor!");return;}// Compute heat index in Fahrenheit (the default)float hif = puteHeatIndex(f, h);// Compute heat index in Celsius (isFahreheit = false)float hic = puteHeatIndex(t, h, false);Serial.print("Humidity: ");Serial.print(h);Serial.print(" %\t");Serial.print("Temperature: ");Serial.print(t);Serial.print(" *C ");Serial.print(f);Serial.print(" *F\t");Serial.print("Heat index: ");Serial.print(hic);Serial.print(" *C ");Serial.print(hif);Serial.println(" *F");lcd.setCursor(2,1); // line 1, pos 0lcd.print(h);lcd.setCursor(11,1); // line 1, pos 0lcd.print(t);delay(1000);}代码说明1. DHT11启动到读取数据需要等待1~2秒2. 温湿度的精度都为1, 没有⼩数部分3. DHT库⾥⾯带了计算热指数的⽅法 computeHeatIndex(), ⽤于⽣成综合温湿度计算得到的热指数值改进拼接字符串改进后的代码, 注意: arduino⾥的sprintf只能格式化整数, 不能格式化浮点#include <Wire.h>#include <LiquidCrystal_I2C.h>#include <DHT.h>#include <DS3231.h>#define DHTPIN 4#define DHTTYPE DHT11// I2C地址, ⼀般为0x3F, 0x20或0x27LiquidCrystal_I2C lcd(0x27,16,2);DHT dht(DHTPIN, DHTTYPE);DS3231 Clock;bool century=false;bool h12;bool PM;void setup() {lcd.init();//lcd.backlight(); // 打开背光Serial.begin(9600);dht.begin();lcd.setCursor(0,0); // line 0, pos 0lcd.print("Good Day Jessie~~");lcd.setCursor(0,1); // line 1, pos 0lcd.print("H: % T: T:");delay(1000);}void loop() {char str[17];sprintf(str,"%02d-%02d %02d:%02d:%02d ",Clock.getMonth(century),Clock.getDate(),Clock.getHour(h12, PM),Clock.getMinute(),Clock.getSecond());lcd.setCursor(0,0); // line 0, pos 0lcd.print(str);// Reading temperature or humidity takes about 250 milliseconds!// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)float h = dht.readHumidity();// Read temperature as Celsius (the default)float t = dht.readTemperature();// Read temperature as Fahrenheit (isFahrenheit = true)float f = dht.readTemperature(true);// Check if any reads failed and exit early (to try again).if (isnan(h) || isnan(t) || isnan(f)) {Serial.println("Failed to read from DHT sensor!");return;}// Compute heat index in Fahrenheit (the default)float hif = puteHeatIndex(f, h);// Compute heat index in Celsius (isFahreheit = false)float hic = puteHeatIndex(t, h, false);Serial.print("Humidity: ");Serial.print(h);Serial.print(" %\t");Serial.print("Temperature: ");Serial.print(t);Serial.print(" *C ");Serial.print(f);Serial.print(" *F\t");Serial.print("Heat index: ");Serial.print(hic);Serial.print(" *C ");Serial.print(hif);Serial.println(" *F");lcd.setCursor(2,1); // line 1, pos 0lcd.print((int)h);lcd.setCursor(8,1); // line 1, pos 0lcd.print((int)t);lcd.setCursor(13,1);lcd.print((int)(Clock.getTemperature()*10)); delay(1000);}。
msp430对dht11测量结果的1602显示
#include "msp430x14x.h"//typedef unsigned char U8; /* defined for unsigned 8-bits integer variable 无符号8位整型变量*/typedef signed char S8; /* defined for signed 8-bits integer variable 有符号8位整型变量*/typedef unsigned int U16; /* defined for unsigned 16-bits integer variable 无符号16位整型变量*/typedef signed int S16; /* defined for signed 16-bits integer variable 有符号16位整型变量*/typedef unsigned long U32; /* defined for unsigned 32-bits integer variable 无符号32位整型变量*/typedef signed long S32; /* defined for signed 32-bits integer variable 有符号32位整型变量*/typedef float F32; /* single precision floating point variable (32bits) 单精度浮点数(32位长度)*/typedef double F64; /* double precision floating point variable (64bits) 双精度浮点数(64位长度)*///#define SET_H P4DIR|=BIT0;P4OUT|=BIT0 //SETH#define SET_L P4DIR|=BIT0;P4OUT&=~BIT0 //SETL#define PIN0 P4IN#define SET_IN P4DIR&=~BIT0;#define CPU_F ((double)8000000)#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))#define P55 5#define P56 6#define P57 7#define RS_CLR P5OUT &= ~(1 << P55) //RS置低#define RS_SET P5OUT |= (1 << P55) //RS置高#define RW_CLR P5OUT &= ~(1 << P56) //RW置低#define RW_SET P5OUT |= (1 << P56) //RW置高#define EN_CLR P5OUT &= ~(1 << P57) //E置低#define EN_SET P5OUT |= (1 << P57) //E置高#define DataPort P4OUT //P4口为数据口//===================================================================== ==========U8 k;U8 U8temp;U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;U8U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8checkdata_t emp;U8 U8comdata;U8 str[5]={"RS232"};U16 U16temp1,U16temp2;//===================================================================== =============void COM(void){U8 i;for(i=0;i<8;i++){//判断数据位是0还是1while(!(PIN0&0X01));delay_us(10);U8temp=0;delay_us(30);if(PIN0&0X01)U8temp=1;while(PIN0&0X01);// 如果高电平高过预定0高电平值则数据位为1U8comdata<<=1;U8comdata|=U8temp;}}/*void Dis_Lcd( ){U8 temp;temp=(U8)(U8RH_data_H/10);PutString_cn(30,80,(unsigned short *)"当前湿度是:");delay_ms(5);PutChar(160,80,(char)(48+temp));delay_ms(5);temp=U8RH_data_H%10;PutChar(170,80,(char)(48+temp));delay_ms(5);PutChar(180,80,'%');delay_ms(5);temp=(U8)(U8T_data_H/10);PutString_cn(30,140,(unsigned short *)"当前温度是:");delay_ms(5);PutChar(160,140,(char)(48+temp));delay_ms(5);temp=U8T_data_H%10;PutChar(170,140,(char)(48+temp));delay_ms(5);PutString_cn(180,140,(unsigned short *)"℃");delay_ms(5);}*/void Clock_Init(){char i;BCSCTL1&=~XT2OFF; //打开XT振荡器BCSCTL2|=SELM1+SELS; //MCLK为8MHZ,SMCLK为8MHZ do{IFG1&=~OFIFG; //清除震荡标志for(i=0;i<100;i++)_NOP(); //延时等待}while((IFG1&OFIFG)!=0); //如果标志为1,则继续循环等待IFG1&=~OFIFG;}//************************************************************************* // MSP430内部看门狗初始化//************************************************************************* void WDT_Init(){WDTCTL = WDTPW + WDTHOLD; //关闭看门狗}//************************************************************************* // 初始化IO口子程序//************************************************************************* void Port_init(){P4SEL = 0x00;P4DIR = 0xFF;P5SEL = 0x00;P5DIR|= BIT5 + BIT6 + BIT7; //控制口设置为输出模式}//*********************************************************************** // 显示屏命令写入函数//***********************************************************************void LCD_write_com(unsigned char com){RS_CLR;RW_CLR;EN_SET;DataPort = com; //命令写入端口delay_ms(5);EN_CLR;}//*********************************************************************** // 显示屏数据写入函数//***********************************************************************void LCD_write_data(unsigned char data){RS_SET;RW_CLR;EN_SET;DataPort = data; //数据写入端口delay_ms(5);EN_CLR;}//*********************************************************************** // 显示屏清空显示//***********************************************************************void LCD_clear(void){LCD_write_com(0x01); //清屏幕显示delay_ms(5);}//*********************************************************************** // 显示屏单字符写入函数//***********************************************************************void LCD_write_char(unsigned char x,unsigned char y,unsigned char data){if (y == 0){LCD_write_com(0x80 + x); //第一行显示}else{LCD_write_com(0xC0 + x); //第二行显示}LCD_write_data( data);}//*********************************************************************** // 显示屏初始化函数//***********************************************************************void LCD_init(void){LCD_write_com(0x38); //显示模式设置delay_ms(5);LCD_write_com(0x08); //显示关闭delay_ms(5);LCD_write_com(0x01); //显示清屏delay_ms(5);LCD_write_com(0x06); //显示光标移动设置delay_ms(5);LCD_write_com(0x0C); //显示开及光标设置delay_ms(5);}void RH(void){//主机拉低18msSET_L;delay_ms (20);SET_H;//总线由上拉电阻拉高主机延时20usdelay_us(20);//主机设为输入判断从机响应信号SET_IN;while(PIN0&0X01);//判断从机是否有低电平响应信号如不响应则跳出,响应则向下运行if(!(PIN0&0X01))//判断从机是否发出80us 的低电平响应信号是否结束delay_us(50);while(!(PIN0&0X01));//判断从机是否发出80us 的高电平,如发出则进入数据接收状态while((PIN0&0X01));//数据接收状态COM();U8RH_data_H_temp=U8comdata;COM();U8RH_data_L_temp=U8comdata;COM();U8T_data_H_temp=U8comdata;COM();U8T_data_L_temp=U8comdata;COM();U8checkdata_temp=U8comdata;SET_H;//数据校验U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp);if(U8temp==U8checkdata_temp){U8RH_data_H=U8RH_data_H_temp;U8RH_data_L=U8RH_data_L_temp;U8T_data_H=U8T_data_H_temp;U8T_data_L=U8T_data_L_temp;U8checkdata=U8checkdata_temp;}/*str[0]=U8RH_data_H;str[1]=U8RH_data_L;str[2]=U8T_data_H;str[3]=U8T_data_L;str[4]=U8checkdata;*/str[0] = (char)(0X30+U8RH_data_H/10);str[1]= (char)(0X30+U8RH_data_H%10);//湿度小数部分str[2] = (char)(0X30+U8RH_data_L/10);//温度整数部分str[3] = (char)(0X30+U8T_data_H/10);str[4] = (char)(0X30+U8T_data_H%10);//温度小数部分str[5] = (char)(0X30+U8T_data_L/10);}void disp(){LCD_write_char(0,0,'s');LCD_write_char(1,0,'h');LCD_write_char(2,0,'i');LCD_write_char(3,0,'d');LCD_write_char(4,0,'u');LCD_write_char(5,0,':');LCD_write_char(6,0,str[0]);LCD_write_char(7,0,str[1]);LCD_write_char(8,0,'.');LCD_write_char(9,0,str[2]);LCD_write_char(10,0,'%');LCD_write_char(11,0,'R');LCD_write_char(12,0,'H');LCD_write_char(0,2,'w');LCD_write_char(1,2,'e');LCD_write_char(2,2,'n');LCD_write_char(3,2,'d');LCD_write_char(4,2,'u');LCD_write_char(5,2,':');LCD_write_char(6,2,str[3]);LCD_write_char(7,2,str[4]);LCD_write_char(8,2,'.');LCD_write_char(9,2,str[5]);LCD_write_char(10,2,0xDF);LCD_write_char(11,2,'C');delay_ms(50);}/*void Set(){U0CTL |= SWRST; //开启设置U0TCTL = SSEL1; //选择SMCLK=6M 波特率=9600 /* 6M / 9600 = 625 625 = 0x0271 0.000 * 8= 0*//* 32768/9600=3.4133 0.4133*8=4*//* U0BR0 = 0x41;U0BR1 = 0x03;U0MCTL =0x00; //00000000U0CTL |= CHAR; //长度8位U0CTL &= ~SWRST;}/*void Send(U8 num){TXBUF0 = num;while((IFG1&UTXIFG0)==0);}void InitClock(void){U8 k;BCSCTL1 &= ~XT2OFF; //开启XT2晶振do{IFG1 &= ~OFIFG; // 清除振荡器失效标志for(k=0xee;k>0;k--){} //延时}while((IFG1 & OFIFG)!=0); //判断XT2是否起振BCSCTL2 = SELM_2 + SELS; // 选择MCLK SMCLK 为XT2 } //初始化//端口初始化函数void InitPort(void){P6DIR=0XFF;// 设置为输出方向P6OUT=0xFF;//P口先输出低电平P3DIR |= 0x10;P3SEL |= 0x30;Set();ME1 |= UTXE0 + URXE0;IE1 |= URXIE0;}*/void main(void){WDT_Init();/*InitClock();InitPort();*//*LCD_Initial();BackLightTo(80);*/Clock_Init();Port_init();/*ClrScreen(1);*/delay_ms(50);/* P6DIR=0XFF;P6OUT=0X7F;delay_ms(50);P6OUT=0XFF;delay_ms(50);*/LCD_init();LCD_clear();while(1){/*Dis_Lcd();*/LCD_init();LCD_clear();/* */RH();// Send(str[k]);disp();while(1){RH();disp();TACTL |= MC0;}//读取模块数据周期不易小于2S delay_ms(50);}}。
C51温湿度传感器DHT11驱动LCD1602显示程序
DHT11.c 文件#include<reg52.h>#include<Time_Delay.h>//the main only needs to call getDHT11(),then the temperature and huminity was geted in F16T,F16RH as floatsbit bit11=P2^0;unsigned char U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;//用于最终读取的温湿度数据// read 8 bits onicechar COM(void){char i,U8temp,U8comdata;for(i=0;i<8;i++){while(!bit11); //表示读取的高电位延时大于20多us则读取的是1否则读取的是0//通过U8FLAG可判断Delay_us(35);U8temp=0;if(bit11)U8temp=1;while(bit11);U8comdata<<=1;U8comdata|=U8temp; //0}//rofreturn U8comdata;}//--------------------------------//-----温湿度读取子程序------------//--------------------------------//----以下变量均为全局变量--------//----温度高8位== U8T_data_H------//----温度低8位== U8T_data_L------//----湿度高8位== U8RH_data_H-----//----湿度低8位== U8RH_data_L-----//----校验8位== U8checkdata-----//----调用相关子程序如下----------//---- Delay();, Delay_10us();,COM();bit11显示数据的脉长//--------------------------------void getDHT11(void){//主机拉低18msGO1: bit11=0;Delay_ms(20);bit11=1;//总线由上拉电阻拉高主机延时20usDelay_us(60);//主机设为输入判断从机响应信号// bit11=1;//判断从机是否有低电平响应信号如不响应则跳出,响应则向下运行if(!bit11) {while(!bit11); while(bit11); //数据接收状态//T !//wait DHT goto highU8RH_data_H=COM();U8RH_data_L=COM();U8T_data_H=COM();U8T_data_L=COM();U8checkdata=COM();bit11=1;//数据校验if((U8T_data_H+U8T_data_L+U8RH_data_H+U8RH_data_L)!=U8checkdata) check wrong,read againgoto GO1;}//fiF16T=U8T_data_H+(float)U8T_data_L/256; //change integer to floatF16RH=U8RH_data_H+(float)U8RH_data_L/256;}//ifLCD1602 文件#include<reg52.h>#include <stdio.h>#include <INTRINS.H> #include <Lcd_1602.h> #include <Time_Delay.h>#define LCD_DATA P0#define uint unsigned int#define uchar unsigned char /*只由主函数调用的有Init_Lcd()LCD_write_str(uchar X,uchar Y,uchar *s) //LCD1602 data transfer defineLCD_value(unsigned char x,unsigned char y,float f) */sbit LCD_RS = P2^5; sbit RW = P2^6;sbit LCD_E = P2^7; //1602 control define/***************************************************************************//显示开//显示关#define LCD_CURSOR_ON 0x0A //显示光标//无光标//有光标,光标闪动//有光标,光标不闪动//进入模式设置指令//新数据后光标右移//新数据后光标左移//画面可平移//画面不可平移//设定显示屏或光标移动方向指令//光标左移1格,且AC值减1//光标右移1格,且AC值加1//显示器上字符全部左移一格,但光标不动//显示器上字符全部右移一格,但光标不动***************************************************************************/ //注有主函数调用的函数都已作说明其他函数一般不由主函数调用/*****************************************************************************名*功称:Init_Lcd()主函数调用能:Lcd初始化*入口参数:无*出口参数:无*范例:在主函数中直接调用****************************************************************************///LCD初始化{LCD_write_char(0x38,0);Delay_ms(1);LCD_write_char(0x38,0);Delay_ms(1);LCD_write_char(0x38,0);Delay_ms(1);LCD_write_char(0x0c,0);Delay_ms(1);LCD_write_char(0x06,0);Delay_ms(1);LCD_write_char(0x0c,0);Delay_ms(1);//}/*****************************************************************************名*功称:LCD_write_str(uchar X,uchar Y,uchar *s)主函数调用能:在指定地址写一个字符串eg:Y=0,1,2,3,4,5,6,7,8,9,10...15。
DHT11温湿度传感器驱动程序
/* 本程序适用于DHT11温湿度传感器由于DHT11使用拉高总线的不同时常来代替0和1 0 28US 1 70us 同时数据送入1602a显示*/#include<reg52.h>#include<intrins.h>#include<math.h>#define Data P0//数据端口sbit RS = P2^4; //Pin4sbit RW = P2^5; //Pin5sbit E = P2^6; //Pin6sbit dat=P1^2;unsigned int shidu_h=0,shidu_l=0,wendu_h=0,wendu_l=0,i,xiaoyan=0;//定义湿度温度变量unsigned char code tab[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//定义1602a显示0-9unsigned int a[16]={0} ;void delayus(unsigned char i) //延时2us{while(--i);}void delayms(unsigned char j) //延时1ms{while(--j){delayus(125);delayus(125);delayus(125);delayus(125);}}/*************************************************** ***************//* 写入命令函数1602 *//*************************************************** ***************/void WriteCommand(unsigned int c){delayms(10);//操作前短暂延时,保证信号稳定代替状态监测E=0;RS=0;_nop_();E=1;Data=c;E=0;}/*************************************************** ***************//* 写入数据函数*//*************************************************** ***************/void WriteData(unsigned char c){delayms(10);;//操作前短暂延时,保证信号稳定E=0;RS=1;RW=0;_nop_();E=1;Data=c;E=0;}/*************************************************** ***************//* 写入字节函数*//*************************************************** ***************/void ShowChar(unsigned char pos,unsigned int c){unsigned char p;if (pos>=0x10)p=pos+0xb0; //是第二行则命令代码高4位为0xc p低两位表示位置显示代码只用DDRAM前16位elsep=pos+0x80; //是第一行则命令代码高4位为0x8 p低两位表示位置显示代码只用DDRAM前16位WriteCommand (p);//写命令写入数据指针确定行中哪一位显示WriteData (c); //写数据}/******************************************************************//* 写入字符串函数*//*************************************************** ***************/void ShowString (unsigned char line,unsigned int *ptr){unsigned char l,i;//l表示行中某一位显示l=line<<4; //L为0x01时左移四位为了与b0H相加变为0xc for (i=0;i<16;i++)ShowChar (l++,*(ptr+i));//循环显示16个字符}/*************************************************** ***************//* 初始化函数*//*************************************************** ***************/void InitLcd(){WriteCommand(0x38); //display modeWriteCommand(0x38); //display modeWriteCommand(0x38); //display modeWriteCommand(0x06); //显示光标移动位置WriteCommand(0x0c); //显示开及光标设置WriteCommand(0x01); //显示清屏}void main(void){InitLcd(); //初始化LCDdelayms(30);while(1){dat=0;delayms(18);//延时18ms拉低主线dat=1;//主机拉高总线/*delayus(20);*/_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_no p_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_no p_();_nop_();_nop_();_nop_();while(!dat);//判断从机是否相应完毕相应完毕会拉高总线while(dat);//等待从机拉高总线准备开始传送数据while(!dat);//判断是否开始1bit 开始会拉高总线for(i=0;i<8;i++){shidu_h<<=1; //右移1位delayus(14); //延时30us判断是否为1if(dat){shidu_h++;}while(dat);//为一则等待从机拉低总线为零直接跳出while(!dat);//判断是否开始1bit 开始会拉高总线}for(i=0;i<8;i++){delayus(14);shidu_l<<=1;if(dat){shidu_l++;}while(dat);}for(i=0;i<8;i++) {delayus(14); wendu_h<<=1; if(dat){wendu_h++; }while(dat); while(!dat);}for(i=0;i<8;i++) {delayus(14); wendu_l<<=1; if(dat){wendu_l++;}while(dat);}for(i=0;i<8;i++){delayus(14);xiaoyan<<=1;if(dat){xiaoyan++;}while(dat);while(!dat);}{a[0]=tab[(wendu_h)/10]; a[1]=tab[(wendu_h)%10]; a[2]=tab[(shidu_h)/10];a[3]=tab[(shidu_h)%10]; a[4]=tab[xiaoyan/10];a[5]=tab[xiaoyan%10]; ShowString(0,a);}delayms(100);shidu_h=0;wendu_h=0;shidu_l=0;wendu_l=0;xiaoyan=0;}}。
DHT11温湿度传感器
基于单片机的DHT11温湿度传感器设计姓名:史延林指导老师:黄智伟学院:电气工程学院学号:20094470321摘要:温湿度是生活生产中的重要的参数。
本设计为基于单片机的温湿度检测与控制系统,采用模块化、层次化设计。
用新型的智能温湿度传感器DHT11主要实现对温度、湿度的检测,将温度湿度信号通过传感器进行信号的采集并转换成数字信号,再运用单片机STC89C52进行数据的分析和处理,为显示和报警电路提供信号,实现对温湿度的控制报警。
报警系统根据设定报警的上下限值实现报警功能,显示部分采用LCD1602液晶显示所测温湿度值。
系统电路简单、集成度高、工作稳定、调试方便、检测精度高,具有一定的实用价值。
关键词:单片机;DHT11温湿度传感器; LCD1602显示第一章:课程构思1.1课题背景温湿度的检测与控制是工业生产过程中比较典型的应用之一,随着传感器在生产和生活中的更加广泛的应用。
在生产中,温湿度的高低对产品的质量影响很大。
由于温湿度的检测控制不当,可能使我们导致无法估计的经济损失。
为保证日常工作的顺利进行,首要问题是加强生产车间内温度与湿度的监测工作,但传统的方法过于粗糙,通过人工进行检测,对不符合温度和湿度要求的库房进行通风、去湿和降温等工作。
这种人工测试方法费时费力、效率低,且测试的温度及湿度误差大,随机性大。
目前,在低温条件下(通常指100℃以下),温湿度的测量已经相对成熟。
利用新型单总线式数字温度传感器实现对温度的测试与控制得到更快的开发。
但人们对它的要求越来越高,要为现代人工作、科研、学习、生活提供更好的更方便的设施就需要从数字单片机技术入手,一切向着数字化,智能化控制方向发展。
对于国内外对温湿度检测的研究,从复杂模拟量检测到现在的数字智能化检测越发的成熟,随着科技的进步,现在的对于温湿度研究,检测系统向着智能化、小型化、低功耗的方向发展。
在发展过程中,以单片机为核心的温湿度控制系统发展为体积小、操作简单、量程宽、性能稳定、测量精度高,等诸多优点在生产生活的各个方面实现着至关重要的作用。
dht11温湿度传感器驱动程序
/* 本程序适用于DHT11温湿度传感器由于DHT11使用拉高总线的不同时常来代替0和1 0 28US 1 70us 同时数据送入1602a显示*/#include<reg52.h>#include<intrins.h>#include<math.h>#define Data P0//数据端口sbit RS = P2^4; //Pin4sbit RW = P2^5; //Pin5sbit E = P2^6; //Pin6sbit dat=P1^2;unsigned int shidu_h=0,shidu_l=0,wendu_h=0,wendu_l=0,i,xiaoyan=0;//定义湿度温度变量unsigned char code tab[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//定义1602a显示0-9unsigned int a[16]={0} ;void delayus(unsigned char i) //延时2us{while(--i);}void delayms(unsigned char j) //延时1ms{while(--j){delayus(125);delayus(125);delayus(125);delayus(125);}}/*************************************************** ***************//* 写入命令函数1602 *//*************************************************** ***************/void WriteCommand(unsigned int c){delayms(10);//操作前短暂延时,保证信号稳定代替状态监测E=0;RS=0;_nop_();E=1;Data=c;E=0;}/*************************************************** ***************//* 写入数据函数*//*************************************************** ***************/void WriteData(unsigned char c){delayms(10);;//操作前短暂延时,保证信号稳定E=0;RS=1;RW=0;_nop_();E=1;Data=c;E=0;}/*************************************************** ***************//* 写入字节函数*//*************************************************** ***************/void ShowChar(unsigned char pos,unsigned int c){unsigned char p;if (pos>=0x10)p=pos+0xb0; //是第二行则命令代码高4位为0xc p低两位表示位置显示代码只用DDRAM前16位elsep=pos+0x80; //是第一行则命令代码高4位为0x8 p低两位表示位置显示代码只用DDRAM前16位WriteCommand (p);//写命令写入数据指针确定行中哪一位显示WriteData (c); //写数据}/******************************************************************//* 写入字符串函数*//*************************************************** ***************/void ShowString (unsigned char line,unsigned int *ptr){unsigned char l,i;//l表示行中某一位显示l=line<<4; //L为0x01时左移四位为了与b0H相加变为0xc for (i=0;i<16;i++)ShowChar (l++,*(ptr+i));//循环显示16个字符}/*************************************************** ***************//* 初始化函数*//*************************************************** ***************/void InitLcd(){WriteCommand(0x38); //display modeWriteCommand(0x38); //display modeWriteCommand(0x38); //display modeWriteCommand(0x06); //显示光标移动位置WriteCommand(0x0c); //显示开及光标设置WriteCommand(0x01); //显示清屏}void main(void){InitLcd(); //初始化LCDdelayms(30);while(1){dat=0;delayms(18);//延时18ms拉低主线dat=1;//主机拉高总线/*delayus(20);*/_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_no p_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_no p_();_nop_();_nop_();_nop_();while(!dat);//判断从机是否相应完毕相应完毕会拉高总线while(dat);//等待从机拉高总线准备开始传送数据while(!dat);//判断是否开始1bit 开始会拉高总线for(i=0;i<8;i++){shidu_h<<=1; //右移1位delayus(14); //延时30us判断是否为1if(dat){shidu_h++;}while(dat);//为一则等待从机拉低总线为零直接跳出while(!dat);//判断是否开始1bit 开始会拉高总线}for(i=0;i<8;i++){delayus(14);shidu_l<<=1;if(dat){shidu_l++;}while(dat);}for(i=0;i<8;i++) {delayus(14); wendu_h<<=1; if(dat){wendu_h++; }while(dat); while(!dat);}for(i=0;i<8;i++) {delayus(14); wendu_l<<=1; if(dat){wendu_l++;}while(dat);}for(i=0;i<8;i++){delayus(14);xiaoyan<<=1;if(dat){xiaoyan++;}while(dat);while(!dat);}{a[0]=tab[(wendu_h)/10]; a[1]=tab[(wendu_h)%10]; a[2]=tab[(shidu_h)/10];a[3]=tab[(shidu_h)%10];a[4]=tab[xiaoyan/10];a[5]=tab[xiaoyan%10];ShowString(0,a);}delayms(100);shidu_h=0;wendu_h=0;shidu_l=0;wendu_l=0;xiaoyan=0;}}教你如何用WORD文档(2012-06-27 192246)转载▼标签:杂谈1. 问:WORD 里边怎样设置每页不同的页眉?如何使不同的章节显示的页眉不同?答:分节,每节可以设置不同的页眉。
51单片机DHT11芯片,1603显示屏程序代码
51单片机DHT11芯片,1603显示屏程序代码#include<reg52.h>#include<intrins。
h>typedefunsignedcharuchar;typedefunsignedintuint;typedefunsignedlongulong;ucharcom,flag;ucharn,m,y,x,v,u,a1,a2;//温湿度上下限的参数,其中,nm是温湿度超标与否的标准,值为0或者1.这代码的温湿度报警没有用LED或者蜂鸣器,只用了一个软件参数n、m存储报警信息。
需要添加报警功能的可以自己写额外的功能代码,然后nm两个参数就是功能传递参数。
也可以写多一个串口输出代码,用串口调试助手输出n、m的值验证温湿度是否超标判断正确。
voidDelay1000ms()//@11.0592MHz延时{unsignedchari,j,k;_nop_();i=8;j=1;k=243;do{do{while(--k);}while(--j);}while(--i);}voidDelay500us()//@11.0592MHz {ucharb;_nop_();b=227;while(--b);}voidDelay10us()//@11.0592MHz {uchara;a=2;while(--a);}voiddelay(uintz){uchari,j;for(i=z;i>0;i--)for(j=110;j>0;j--);//ÑÓʱº¯Êý}//************************引脚定义************* /*******按键控制引脚定义*********/sbity_tem_inse=P1^0;//sbity_tem_duce=P1^1;//sbitx_tem_inse=P1^2;//sbitx_tem_duce=P1^3;//sbitu_hum_inse=P1^4;//sbitu_hum_duce=P1^5;//sbitv_hum_inse=P1^6;//sbitv_hum_duce=P1^7;///***********其他功能引脚*****/sbitDQ=P2^1;//DTH11//****LCD的****sbitRS=P2^7;sbitRW=P2^6;sbitEN=P2^5;#defineDataPortP0//LCD的接线,我的是8线接发//-----------------函数声明------------- voiddelay_us(uchart);voiddelay_ms(uchart);bitLCD_Check_Busy(void);voidLCD_Write_Com(ucharcom);voidLCD_Write_Data(ucharData);voidLCD_Clear(void);voidLCD_Write_String(ucharx,uchary,uchar*s);voidLCD_Write_Char(ucharx,uchary,ucharData);voidLCD_Init(void);voidCOMdata();//*************************以下是函数定义***************************//**************液晶屏显示原函数由此开始*************************bitLCD_Check_Busy(void)//检忙{DataPort=0xFF;RS=0;RW=1;EN=0;_nop_();EN=1;return(bit)(DataPort&0x80);voidLCD_Write_Com(ucharcom)//写指令原函数{while(LCD_Check_Busy());RS=0;RW=0;EN=1;DataPort=com;_nop_();EN=0;}voidLCD_Write_Data(ucharData)//写数据原函数{while(LCD_Check_Busy());RS=1;RW=0;EN=1;DataPort=Data;_nop_();EN=0;}voidLCD_Clear(void)//清屏LCD_Write_Com(0x01);delay(1);}voidLCD_Write_String(ucharx,uchary,uchar*s)//操作-显示LCD屏的哪个位置{if(y==0)LCD_Write_Com(0x80+x);elseLCD_Write_Com(0xC0+x);while(*s){LCD_Write_Data(*s);s++;}}voidLCD_Write_Char(ucharx,uchary,ucharData)//操作-显示的数据(字符类型,显示数字需找到该数字的ASCII码){if(y==0)LCD_Write_Com(0x80+x);elseLCD_Write_Com(0xC0+x);LCD_Write_Data(Data);}voidLCD_Init(void)//LCD初始化(可以理解为唤醒){delay(15);LCD_Write_Com(0x38);delay(5);LCD_Write_Com(0x38);delay(5);LCD_Write_Com(0x38);delay(5);LCD_Write_Com(0x38);LCD_Write_Com(0x08);LCD_Write_Com(0x01);LCD_Write_Com(0x06);delay(5);LCD_Write_Com(0x0C);}//****************LCD源码结束***********//*********DHT11原函数以下开始*******//*************************************************** ucharcodeASCII[]="0123456789%c";//普通数字需用该数组转成字符ucharcodetable0[]="Hum:";ucharcodetable1[]="Tem:";uchartem;ucharhum;display0[2]={0,0};display1[2]={0,0};//*************************初始化DTH11voidCOMdata()//读数据{uchari,t;for(i=0;i<8;i++){flag=2;while((!DQ)&&flag++);Delay10us();Delay10us();Delay10us();//先看懂DHT11的工作时序图就知道我这个延时操作的含义了,读高电平多少秒可以对应数据0或1t=0;if(DQ)t=1;while((DQ)&&flag++);if(flag==1)break;com<<=1;com|=t;}}voidRH(void)//该函数包括唤醒DHT11发送数据给单片机也包括单片机把数据提取{DQ=0;delay(21);DQ=1;Delay10us();Delay10us();Delay10us();Delay10us();DQ=1;if(!DQ){flag=2;while((!DQ)&&flag++);while((DQ)&&flag++);COMdata();hum=com;COMdata();COMdata();tem=com;COMdata();COMdata();//小数位这里我不显示,所以不用读取tem或hum 第二次的COMdata()函数获取的数据DQ=1;}}//*********************************LCD显示温湿度数据voidDisplay_DTH11(){ucharxh,xl,yh,yl,vh,vl,uh,ul;xh=x/10%10;xl=x%10;yh=y/10%10;yl=y%10;uh=u/10%10;ul=u%10;vh=v/10%10;vl=v%10;LCD_Write_String(8,0,"L");LCD_Write_Char(9,0,ASCII[uh]);LCD_Write_Char(10,0,ASCII[ul]);LCD_Write_String(12,0,"H");LCD_Write_Char(13,0,ASCII[vh]);LCD_Write_Char(14,0,ASCII[vl]);LCD_Write_String(8,1,"L");LCD_Write_Char(9,1,ASCII[xh]);LCD_Write_Char(10,1,ASCII[xl]);LCD_Write_String(12,1,"H");LCD_Write_Char(13,1,ASCII[yh]);LCD_Write_Char(14,1,ASCII[yl]);display0[1]=hum/10%10;//读hum十位display0[0]=hum%10;//个位LCD_Write_String(0,0,table0);LCD_Write_Char(4,0,ASCII[display0[1]]);LCD_Write_Char(5,0,ASCII[display0[0]]);LCD_Write_Char(6,0,ASCII[10]);//显示在LCD的第几行第几位(这一行是指在第0行,第6位开始显示ASCII[10]里面的字符数据,下同),运行结果是显示了“hum:”这四个字符display1[1]=tem/10%10;display1[0]=tem%10;LCD_Write_String(0,1,table1);LCD_Write_Char(4,1,ASCII[display1[1]]);LCD_Write_Char(5,1,ASCII[display1[0]]);LCD_Write_Char(6,1,0xdf);LCD_Write_Char(7,1,ASCII[11]);}//***************原函数结束*************//voidkeyscan(){if(y_tem_inse==0){delay(10);if(y_tem_inse==0)//这里是消抖,下同{y=y+5;while(y==55)y=50;while(y_tem_inse==0);}if(y_tem_duce==0){delay(10);if(y_tem_duce==0);{y=y-5;while(y==5)y=10;while(y_tem_duce==0);}}if(x_tem_inse==0){delay(10);if(x_tem_inse==0){x=x+5;while(x==55)x=50;while(x_tem_inse==0);}}if(x_tem_duce==0)delay(10);if(x_tem_duce==0);{x=x-5;while(x==5)x=10;while(x_tem_duce==0);}}if(u_hum_inse==0){delay(10);if(u_hum_inse==0){u=u+5;while(u==85)u=80;while(u_hum_inse==0);}}if(u_hum_duce==0){delay(10);if(u_hum_duce==0);u=u-5;while(u==25)u=30;while(u_hum_duce==0);}}if(v_hum_inse==0){delay(10);if(v_hum_inse==0){v=v+5;while(v==85)v=80;while(v_hum_inse==0);}}if(v_hum_duce==0){delay(10);if(v_hum_duce==0);{v=v-5;while(v==25)v=20;while(v_hum_duce==0);}}}//*******************************上面是按键扫描,以下开始是主函数main(){LCD_Clear();x=10,y=50,u=30,v=80;//温湿度上下限初值,按键函数里可调tem=0;hum=0;//赋初值LCD_Init();Delay1000ms();//DTH11上电一秒后才工作正常while(1){EA=0;keyscan();RH();if((tem>y)||(tem<x))n=1;elsen=0;//LED或蜂鸣器亮灭判断,下同if((hum>v)||(hum<u))m=1;elsem=0;Display_DTH11();Time0_Init();Delay1000ms();Delay1000ms();Delay1000ms();}}。
温湿度传感器DHT11与16x16点阵模块显示
/*-----------------------------------------------名称:16x16点阵论坛:编写:shifang修改:无硬件:LY-LED16x16A 点阵模块------------------------------------------------*//*在上方声明中,本人已做修改,添加了一些功能而已,源程序是16x16的点阵模块驱动程序,在此添加了DHT11温湿度传感器,采集温度,显示到16x16点阵模块上,仅此而已,程序中有较为详细的说明了,不懂的话仔细看看就知道了,再修改作者:Uncle Pig*/#include "dht111.h"#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义#include <intrins.h>unsigned char code tab0[]={0x80,0x00,0x84,0x10,0x88,0x10,0x90,0x08,0x90,0x04,0x80,0x00,0xFE,0x1F,0x00,0x10,//当0x00,0x10,0x00,0x10,0xFC,0x1F,0x00,0x10,0x00,0x10,0x00,0x10,0xFE,0x1F,0x00,0x00,0x08,0x08,0x10,0x08,0x10,0x04,0xFF,0x7F,0x00,0x00,0x7C,0x10,0x44,0x12,0x44,0x12,//前0x7C,0x12,0x44,0x12,0x44,0x12,0x7C,0x12,0x44,0x10,0x44,0x10,0x54,0x14,0x00,0x00,0x00,0x00,0xC4,0x1F,0x48,0x10,0x48,0x10,0xC1,0x1F,0x42,0x10,0x42,0x10,0xC8,0x1F,//温0x08,0x00,0xE4,0x3F,0x27,0x25,0x24,0x25,0x24,0x25,0x24,0x25,0xF4,0x7F,0x00,0x00,0x80,0x00,0x00,0x01,0xFC,0x7F,0x44,0x04,0x44,0x04,0xFC,0x3F,0x44,0x04,0x44,0x04,//度0xC4,0x07,0x04,0x00,0xF4,0x0F,0x24,0x08,0x42,0x04,0x82,0x03,0x61,0x0C,0x00,0x00,};unsigned char code tab1[]={0x80,0x00,0x84,0x10,0x88,0x10,0x90,0x08,0x90,0x04,0x80,0x00,0xFE,0x1F,0x00,0x10,//湿度0x00,0x10,0x00,0x10,0xFC,0x1F,0x00,0x10,0x00,0x10,0x00,0x10,0xFE,0x1F,0x00,0x00,0x08,0x08,0x10,0x08,0x10,0x04,0xFF,0x7F,0x00,0x00,0x7C,0x10,0x44,0x12,0x44,0x12,0x7C,0x12,0x44,0x12,0x44,0x12,0x7C,0x12,0x44,0x10,0x44,0x10,0x54,0x14,0x00,0x00,0x00,0x00,0xE4,0x1F,0x28,0x10,0x28,0x10,0xE1,0x1F,0x22,0x10,0x22,0x10,0xE8,0x1F,0x88,0x04,0x84,0x04,0x97,0x24,0xA4,0x14,0xC4,0x0C,0x84,0x04,0xF4,0x7F,0x00,0x00,0x80,0x00,0x00,0x01,0xFC,0x7F,0x44,0x04,0x44,0x04,0xFC,0x3F,0x44,0x04,0x44,0x04,0xC4,0x07,0x04,0x00,0xF4,0x0F,0x24,0x08,0x42,0x04,0x82,0x03,0x61,0x0C,0x00,0x00,};unsigned char code tab[]={////取模选择字节倒序,正序得出的字是反的,可以在软件中设置自动倒叙/*-- 文字: 胡--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*///0x00,0x01,0x00,0x01,0x3F,0x01,0x20,0x3F,0xA0,0x20,0x92,0x10,0x54,0x02,0x28,0x02,//0x08,0x02,0x14,0x05,0x24,0x05,0xA2,0x08,0x81,0x08,0x40,0x10,0x20,0x20,0x00,0x00,/*-- 文字: 字--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*///0x00,0x00,0x04,0x01,0xC8,0x3C,0x48,0x24,0x40,0x24,0x40,0x24,0x4F,0x24,0x48,0x24, //0x48,0x24,0x48,0x2D,0xC8,0x14,0x48,0x04,0x08,0x04,0x14,0x04,0xE2,0x7F,0x00,0x00,/*-- 文字: 测--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*///0x80,0x00,0x84,0x10,0x88,0x10,0x90,0x08,0x90,0x04,0x80,0x00,0xFF,0x7F,0x20,0x02,//0x20,0x02,0x20,0x02,0x20,0x02,0x10,0x42,0x10,0x42,0x08,0x42,0x04,0x7C,0x00,0x00,/*-- 文字: 试--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*///0x10,0x01,0x10,0x01,0x10,0x01,0x92,0x7F,0x92,0x02,0x52,0x04,0x32,0x04,0x12,0x00, //0x92,0x3F,0x92,0x24,0x92,0x24,0x92,0x24,0x92,0x24,0x90,0x3F,0x90,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x24,0x00,0x42,0x00,0x42,0x00,0x42,//0 0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x24,0x00,0x18,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x1C,0x00,0x10,0x00,0x10,0x00,0x10,//1 0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x7C,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x40,//2 0x00,0x20,0x00,0x10,0x00,0x08,0x00,0x04,0x00,0x42,0x00,0x7E,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x42,0x00,0x42,0x00,0x40,0x00,0x20,//3 0x00,0x18,0x00,0x20,0x00,0x40,0x00,0x42,0x00,0x42,0x00,0x3C,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x30,0x00,0x30,0x00,0x28,0x00,0x24,//4 0x00,0x24,0x00,0x22,0x00,0xFE,0x00,0x20,0x00,0x20,0x00,0xF8,0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x1E,//5 0x00,0x22,0x00,0x40,0x00,0x40,0x00,0x42,0x00,0x22,0x00,0x1C,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x24,0x00,0x02,0x00,0x02,0x00,0x3A,//6 0x00,0x46,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x44,0x00,0x38,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x42,0x00,0x20,0x00,0x20,0x00,0x10,//7 0x00,0x10,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x24,//8 0x00,0x18,0x00,0x24,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x3C,0x00,0x00,0x00,0x00,// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x22,0x00,0x42,0x00,0x42,0x00,0x42,//9 0x00,0x62,0x00,0x5C,0x00,0x40,0x00,0x40,0x00,0x24,0x00,0x18,0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x1C,0x24,0x10,0x42,0x10,0x42,0x10,0x42,//10 0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x24,0x7C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x1C,0x1C,0x10,0x10,0x10,0x10,0x10,0x10,//11 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x3C,0x1C,0x42,0x10,0x42,0x10,0x42,0x10,0x40,//12 0x10,0x20,0x10,0x10,0x10,0x08,0x10,0x04,0x10,0x42,0x7C,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x3C,0x1C,0x42,0x10,0x42,0x10,0x40,0x10,0x20,//130x10,0x18,0x10,0x20,0x10,0x40,0x10,0x42,0x10,0x42,0x7C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x1C,0x30,0x10,0x30,0x10,0x28,0x10,0x24,//140x10,0x24,0x10,0x22,0x10,0xFE,0x10,0x20,0x10,0x20,0x7C,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x7E,0x1C,0x02,0x10,0x02,0x10,0x02,0x10,0x1E,//150x10,0x22,0x10,0x40,0x10,0x40,0x10,0x42,0x10,0x22,0x7C,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x1C,0x24,0x10,0x02,0x10,0x02,0x10,0x3A,//160x10,0x46,0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x44,0x7C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x7E,0x1C,0x42,0x10,0x20,0x10,0x20,0x10,0x10,//170x10,0x10,0x10,0x08,0x10,0x08,0x10,0x08,0x10,0x08,0x7C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x3C,0x1C,0x42,0x10,0x42,0x10,0x42,0x10,0x24,//180x10,0x18,0x10,0x24,0x10,0x42,0x10,0x42,0x10,0x42,0x7C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x1C,0x1C,0x22,0x10,0x42,0x10,0x42,0x10,0x42,//190x10,0x62,0x10,0x5C,0x10,0x40,0x10,0x40,0x10,0x24,0x7C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x18,0x42,0x24,0x42,0x42,0x42,0x42,0x40,0x42,//20~29 0x20,0x42,0x10,0x42,0x08,0x42,0x04,0x42,0x42,0x24,0x7E,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x10,0x42,0x1C,0x42,0x10,0x42,0x10,0x40,0x10,//0x20,0x10,0x10,0x10,0x08,0x10,0x04,0x10,0x42,0x10,0x7E,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x40,//0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x42,0x42,0x7E,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x20,//0x20,0x18,0x10,0x20,0x08,0x40,0x04,0x42,0x42,0x42,0x7E,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x20,0x42,0x30,0x42,0x30,0x42,0x28,0x40,0x24,//0x20,0x24,0x10,0x22,0x08,0xFE,0x04,0x20,0x42,0x20,0x7E,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0x42,0x02,0x42,0x02,0x42,0x02,0x40,0x1E,//0x20,0x22,0x10,0x40,0x08,0x40,0x04,0x42,0x42,0x22,0x7E,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x18,0x42,0x24,0x42,0x02,0x42,0x02,0x40,0x3A,//0x20,0x46,0x10,0x42,0x08,0x42,0x04,0x42,0x42,0x44,0x7E,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0x42,0x42,0x42,0x20,0x42,0x20,0x40,0x10,//0x20,0x10,0x10,0x08,0x08,0x08,0x04,0x08,0x42,0x08,0x7E,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x24,//0x20,0x18,0x10,0x24,0x08,0x42,0x04,0x42,0x42,0x42,0x7E,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x1C,0x42,0x22,0x42,0x42,0x42,0x42,0x40,0x42,//0x20,0x62,0x10,0x5C,0x08,0x40,0x04,0x40,0x42,0x24,0x7E,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x18,0x42,0x24,0x42,0x42,0x40,0x42,0x20,0x42,//30~39 0x18,0x42,0x20,0x42,0x40,0x42,0x42,0x42,0x42,0x24,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x10,0x42,0x1C,0x42,0x10,0x40,0x10,0x20,0x10,0x18,0x10,0x20,0x10,0x40,0x10,0x42,0x10,0x42,0x10,0x3C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x40,0x42,0x20,0x40,0x18,0x20,0x20,0x10,0x40,0x08,0x42,0x04,0x42,0x42,0x3C,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x40,0x40,0x20,0x20,0x18,0x18,0x20,0x20,0x40,0x40,0x42,0x42,0x42,0x42,0x3C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x20,0x42,0x30,0x42,0x30,0x40,0x28,0x20,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0x42,0x02,0x42,0x02,0x40,0x02,0x20,0x1E,0x18,0x22,0x20,0x40,0x40,0x40,0x42,0x42,0x42,0x22,0x3C,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x18,0x42,0x24,0x42,0x02,0x40,0x02,0x20,0x3A,0x18,0x46,0x20,0x42,0x40,0x42,0x42,0x42,0x42,0x44,0x3C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0x42,0x42,0x42,0x20,0x40,0x20,0x20,0x10,0x18,0x10,0x20,0x08,0x40,0x08,0x42,0x08,0x42,0x08,0x3C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x40,0x42,0x20,0x24,0x18,0x18,0x20,0x24,0x40,0x42,0x42,0x42,0x42,0x42,0x3C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x1C,0x42,0x22,0x42,0x42,0x40,0x42,0x20,0x42,0x18,0x62,0x20,0x5C,0x40,0x40,0x42,0x40,0x42,0x24,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x18,0x30,0x24,0x30,0x42,0x28,0x42,0x24,0x42,//40~49 0x24,0x42,0x22,0x42,0xFE,0x42,0x20,0x42,0x20,0x24,0xF8,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x30,0x1C,0x30,0x10,0x28,0x10,0x24,0x10,0x24,0x10,0x22,0x10,0xFE,0x10,0x20,0x10,0x20,0x10,0xF8,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3C,0x30,0x42,0x30,0x42,0x28,0x42,0x24,0x40,0x24,0x20,0x22,0x10,0xFE,0x08,0x20,0x04,0x20,0x42,0xF8,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3C,0x30,0x42,0x30,0x42,0x28,0x40,0x24,0x20,0x24,0x18,0x22,0x20,0xFE,0x40,0x20,0x42,0x20,0x42,0xF8,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x30,0x30,0x30,0x30,0x28,0x28,0x24,0x24,0x24,0x24,0x22,0x22,0xFE,0xFE,0x20,0x20,0x20,0x20,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x7E,0x30,0x02,0x30,0x02,0x28,0x02,0x24,0x1E,0x24,0x22,0x22,0x40,0xFE,0x40,0x20,0x42,0x20,0x22,0xF8,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x18,0x30,0x24,0x30,0x02,0x28,0x02,0x24,0x3A,0x24,0x46,0x22,0x42,0xFE,0x42,0x20,0x42,0x20,0x44,0xF8,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x7E,0x30,0x42,0x30,0x20,0x28,0x20,0x24,0x10,0x24,0x10,0x22,0x08,0xFE,0x08,0x20,0x08,0x20,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3C,0x30,0x42,0x30,0x42,0x28,0x42,0x24,0x24,0x24,0x18,0x22,0x24,0xFE,0x42,0x20,0x42,0x20,0x42,0xF8,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x1C,0x30,0x22,0x30,0x42,0x28,0x42,0x24,0x42,0x24,0x62,0x22,0x5C,0xFE,0x40,0x20,0x40,0x20,0x24,0xF8,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x18,0x02,0x24,0x02,0x42,0x02,0x42,0x1E,0x42,//50~59 0x22,0x42,0x40,0x42,0x40,0x42,0x42,0x42,0x22,0x24,0x1C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x10,0x02,0x1C,0x02,0x10,0x02,0x10,0x1E,0x10,0x22,0x10,0x40,0x10,0x40,0x10,0x42,0x10,0x22,0x10,0x1C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x3C,0x02,0x42,0x02,0x42,0x02,0x42,0x1E,0x40,0x22,0x20,0x40,0x10,0x40,0x08,0x42,0x04,0x22,0x42,0x1C,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x3C,0x02,0x42,0x02,0x42,0x02,0x40,0x1E,0x20,0x22,0x18,0x40,0x20,0x40,0x40,0x42,0x42,0x22,0x42,0x1C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x20,0x02,0x30,0x02,0x30,0x02,0x28,0x1E,0x24,0x22,0x24,0x40,0x22,0x40,0xFE,0x42,0x20,0x22,0x20,0x1C,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x7E,0x02,0x02,0x02,0x02,0x02,0x02,0x1E,0x1E,0x22,0x22,0x40,0x40,0x40,0x40,0x42,0x42,0x22,0x22,0x1C,0x1C,0x00,0x00,0x00,0x00,0x22,0x46,0x40,0x42,0x40,0x42,0x42,0x42,0x22,0x44,0x1C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x7E,0x02,0x42,0x02,0x20,0x02,0x20,0x1E,0x10,0x22,0x10,0x40,0x08,0x40,0x08,0x42,0x08,0x22,0x08,0x1C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x3C,0x02,0x42,0x02,0x42,0x02,0x42,0x1E,0x24,0x22,0x18,0x40,0x24,0x40,0x42,0x42,0x42,0x22,0x42,0x1C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x1C,0x02,0x22,0x02,0x42,0x02,0x42,0x1E,0x42,0x22,0x62,0x40,0x5C,0x40,0x40,0x42,0x40,0x22,0x24,0x1C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x24,0x24,0x02,0x42,0x02,0x42,0x3A,0x42,//60~69 0x46,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0x24,0x38,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x10,0x24,0x1C,0x02,0x10,0x02,0x10,0x3A,0x10,0x46,0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x44,0x10,0x38,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x3C,0x24,0x42,0x02,0x42,0x02,0x42,0x3A,0x40,0x46,0x20,0x42,0x10,0x42,0x08,0x42,0x04,0x44,0x42,0x38,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x3C,0x24,0x42,0x02,0x42,0x02,0x40,0x3A,0x20,0x46,0x18,0x42,0x20,0x42,0x40,0x42,0x42,0x44,0x42,0x38,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x20,0x24,0x30,0x02,0x30,0x02,0x28,0x3A,0x24,0x46,0x24,0x42,0x22,0x42,0xFE,0x42,0x20,0x44,0x20,0x38,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x7E,0x24,0x02,0x02,0x02,0x02,0x02,0x3A,0x1E,0x46,0x22,0x42,0x40,0x42,0x40,0x42,0x42,0x44,0x22,0x38,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x24,0x24,0x02,0x02,0x02,0x02,0x3A,0x3A,0x46,0x46,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0x44,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x7E,0x24,0x42,0x02,0x20,0x02,0x20,0x3A,0x10,0x46,0x10,0x42,0x08,0x42,0x08,0x42,0x08,0x44,0x08,0x38,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x3C,0x24,0x42,0x02,0x42,0x02,0x42,0x3A,0x24,0x46,0x18,0x42,0x24,0x42,0x42,0x42,0x42,0x44,0x42,0x38,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x1C,0x24,0x22,0x02,0x42,0x02,0x42,0x3A,0x42,0x46,0x62,0x42,0x5C,0x42,0x40,0x42,0x40,0x44,0x24,0x38,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x18,0x42,0x24,0x20,0x42,0x20,0x42,0x10,0x42,//70~79 0x10,0x42,0x08,0x42,0x08,0x42,0x08,0x42,0x08,0x24,0x08,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x10,0x42,0x1C,0x20,0x10,0x20,0x10,0x10,0x10,0x10,0x10,0x08,0x10,0x08,0x10,0x08,0x10,0x08,0x10,0x08,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x3C,0x42,0x42,0x20,0x42,0x20,0x42,0x10,0x40,0x10,0x20,0x08,0x10,0x08,0x08,0x08,0x04,0x08,0x42,0x08,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x3C,0x42,0x42,0x20,0x42,0x20,0x40,0x10,0x20,0x10,0x18,0x08,0x20,0x08,0x40,0x08,0x42,0x08,0x42,0x08,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x20,0x42,0x30,0x20,0x30,0x20,0x28,0x10,0x24,0x10,0x24,0x08,0x22,0x08,0xFE,0x08,0x20,0x08,0x20,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x7E,0x42,0x02,0x20,0x02,0x20,0x02,0x10,0x1E,0x10,0x22,0x08,0x40,0x08,0x40,0x08,0x42,0x08,0x22,0x08,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x18,0x42,0x24,0x20,0x02,0x20,0x02,0x10,0x3A,0x10,0x46,0x08,0x42,0x08,0x42,0x08,0x42,0x08,0x44,0x08,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x7E,0x42,0x42,0x20,0x20,0x20,0x20,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x3C,0x42,0x42,0x20,0x42,0x20,0x42,0x10,0x24,0x10,0x18,0x08,0x24,0x08,0x42,0x08,0x42,0x08,0x42,0x08,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x1C,0x42,0x22,0x20,0x42,0x20,0x42,0x10,0x42,0x10,0x62,0x08,0x5C,0x08,0x40,0x08,0x40,0x08,0x24,0x08,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x18,0x42,0x24,0x42,0x42,0x42,0x42,0x24,0x42,//80~89 0x18,0x42,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x10,0x42,0x1C,0x42,0x10,0x42,0x10,0x24,0x10,0x18,0x10,0x24,0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x3C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x40,0x18,0x20,0x24,0x10,0x42,0x08,0x42,0x04,0x42,0x42,0x3C,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x42,0x40,0x24,0x20,0x18,0x18,0x24,0x20,0x42,0x40,0x42,0x42,0x42,0x42,0x3C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x20,0x42,0x30,0x42,0x30,0x42,0x28,0x24,0x24,0x18,0x24,0x24,0x22,0x42,0xFE,0x42,0x20,0x42,0x20,0x3C,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0x42,0x02,0x42,0x02,0x42,0x02,0x24,0x1E,0x18,0x22,0x24,0x40,0x42,0x40,0x42,0x42,0x42,0x22,0x3C,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x18,0x42,0x24,0x42,0x02,0x42,0x02,0x24,0x3A,0x18,0x46,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0x3C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0x42,0x42,0x42,0x20,0x42,0x20,0x24,0x10,0x18,0x10,0x24,0x08,0x42,0x08,0x42,0x08,0x42,0x08,0x3C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x24,0x18,0x18,0x24,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x1C,0x42,0x22,0x42,0x42,0x42,0x42,0x24,0x42,0x18,0x62,0x24,0x5C,0x42,0x40,0x42,0x40,0x42,0x24,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x18,0x22,0x24,0x42,0x42,0x42,0x42,0x42,0x42,//90~99 0x62,0x42,0x5C,0x42,0x40,0x42,0x40,0x42,0x24,0x24,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x10,0x22,0x1C,0x42,0x10,0x42,0x10,0x42,0x10,0x62,0x10,0x5C,0x10,0x40,0x10,0x40,0x10,0x24,0x10,0x18,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x3C,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x62,0x20,0x5C,0x10,0x40,0x08,0x40,0x04,0x24,0x42,0x18,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x3C,0x22,0x42,0x42,0x42,0x42,0x40,0x42,0x20,0x62,0x18,0x5C,0x20,0x40,0x40,0x40,0x42,0x24,0x42,0x18,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x20,0x22,0x30,0x42,0x30,0x42,0x28,0x42,0x24,0x62,0x24,0x5C,0x22,0x40,0xFE,0x40,0x20,0x24,0x20,0x18,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x7E,0x22,0x02,0x42,0x02,0x42,0x02,0x42,0x1E,0x62,0x22,0x5C,0x40,0x40,0x40,0x40,0x42,0x24,0x22,0x18,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x18,0x22,0x24,0x42,0x02,0x42,0x02,0x42,0x3A,0x62,0x46,0x5C,0x42,0x40,0x42,0x40,0x42,0x24,0x44,0x18,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x7E,0x22,0x42,0x42,0x20,0x42,0x20,0x42,0x10,0x62,0x10,0x5C,0x08,0x40,0x08,0x40,0x08,0x24,0x08,0x18,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x3C,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x62,0x18,0x5C,0x24,0x40,0x42,0x40,0x42,0x24,0x42,0x18,0x3C,0x00,0x00,0x00,0x00,0x62,0x62,0x5C,0x5C,0x40,0x40,0x40,0x40,0x24,0x24,0x18,0x18,0x00,0x00,0x00,0x00,};unsigned int code seg[]={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x 2000,0x4000,0x8000};/*------------------------------------------------硬件端口定义------------------------------------------------*/sbit LATCH_B = P3^5; //16行控制,行信号sbit SRCLK_B= P3^4;sbit SER_B = P3^3;sbit dht11 = P2^2;//温湿度传感器数据口sbit LATCH = P0^2; //数据控制,列信号sbit SRCLK= P0^1;sbit SER= P0^3;/*------------------------------------------------uS延时函数,含有输入参数unsigned char t,无返回值unsigned char 是定义无符号字符变量,其值的范围是0~255 这里使用晶振12M,精确延时请使用汇编,大致延时长度如下T=tx2+5 uS------------------------------------------------*/void DelayUs2x(unsigned char t){while(--t);}/*------------------------------------------------mS延时函数,含有输入参数unsigned char t,无返回值unsigned char 是定义无符号字符变量,其值的范围是0~255 这里使用晶振12M,精确延时请使用汇编------------------------------------------------*//*void DelayMs(unsigned char t){while(t--){//大致延时1mSDelayUs2x(245);DelayUs2x(245);}}*/#define NUMBER 20#define SIZE 5static unsigned char status;//存放五字节数据的数组static unsigned char value_array[SIZE];/*可在其他的文件引用温湿度值,实际是温度的整数的10倍如dht11读回的温度是26,则temp_value = 260, 湿度同理*/int temp_value, humi_value;static unsigned char ReadValue(void);void Delay_1ms(unsigned int ms){unsigned int x, y;for(x = ms; x > 0; x--)for(y = 124; y > 0; y--);}static void DHT11_Delay_10us(void){unsigned char i;i--;i--;i--;i--;i--;i--;}/*读一个字节的数据*/static unsigned char DHT11_ReadValue(void){unsigned char count, value = 0, i;status = OK; //设定标志为正常状态for(i = 8; i > 0; i--) //高位在先{value <<= 1;count = 0;while(dht11 == 0 && count++ < NUMBER); //每一位数据前会有一个50us的低电平时间.等待50us低电平结束if(count >= NUMBER){status = ERROR; //设定错误标志return 0; //函数执行过程发生错误就退出函数}//26-28us的高电平表示该位是0,为70us高电平表该位1DHT11_Delay_10us();DHT11_Delay_10us();DHT11_Delay_10us();//延时30us后检测数据线是否还是高电平if(dht11 != 0){//进入这里表示该位是1value++;//等待剩余(约40us)的高电平结束while(dht11 != 0 && count++ < NUMBER){dht11 = 1;}if(count >= NUMBER){status = ERROR; //设定错误标志return 0;}}}return (value);}//读温度和湿度函数,读一次的数据,共五字节,读出成功函数返回OK, 错误返回ERROR unsigned char DHT11_ReadTempAndHumi(void){unsigned char i = 0, check_value = 0,count = 0;EA = 0;dht11 = 0; //拉低数据线大于18ms发送开始信号Delay_1ms(20); //需大于18毫秒dht11 = 1; //释放数据线,用于检测低电平的应答信号//延时20-40us,等待一段时间后检测应答信号,应答信号是从机拉低数据线80usDHT11_Delay_10us();DHT11_Delay_10us();DHT11_Delay_10us();DHT11_Delay_10us();if(dht11 != 0) //检测应答信号,应答信号是低电平//没应答信号{EA = 1;return ERROR;}else //有应答信号{while(dht11 == 0 && count++ < NUMBER); //等待应答信号结束if(count >= NUMBER) //检测计数器是否超过了设定的范围{dht11 = 1;EA = 1;return ERROR; //读数据出错,退出函数}count = 0;dht11 = 1;//释放数据线//应答信号后会有一个80us的高电平,等待高电平结束while(dht11 != 0 && count++ < NUMBER);if(count >= NUMBER){dht11 = 1;EA = 1;return ERROR; //退出函数}for(i = 0; i < SIZE; i++) //读出湿.温度值{value_array[i] = DHT11_ReadValue();if(status == ERROR) //调用ReadValue()读数据出错会设定status为ERROR{dht11 = 1;EA = 1;return ERROR;} //读出的最后一个值是校验值不需加上去if(i != SIZE - 1){check_value += value_array[i];//在没用发生函数调用失败时进行校验}}if(check_value == value_array[SIZE - 1]){humi_value = value_array[0] ;//* 10;//将温湿度扩大10倍方便分离出每一位temp_value = value_array[2] ;//* 10;dht11 = 1;EA = 1;return OK; //正确的读出dht11输出的数据}else //校验数据出错{EA = 1;return ERROR;}}}/*------------------------------------------------发送字节程序------------------------------------------------*/void SendByte(unsigned char dat){unsigned char i;for(i=0;i<8;i++){SRCLK=0;SER=dat&0x80;dat<<=1;SRCLK=1;}}void SendByte1(unsigned char dat){unsigned char i;for(i=0;i<8;i++){SRCLK_B=0;SER_B=dat&0x80;dat<<=1;SRCLK_B=1;}}void SendSer(unsigned char dat1,unsigned char dat2) {SendByte(dat1);SendByte(dat2);LATCH=1;_nop_();LATCH=0;}/*------------------------------------------------发送位码字节程序使用另外一片单独595------------------------------------------------*/void SendSeg(unsigned int a){SendByte1(a>>8);SendByte1(a);LATCH_B=1; //锁存_nop_();LATCH_B=0;}/*------------------------------------------------主程序------------------------------------------------*/void main(){unsigned char i,j,k;while(1){DHT11_ReadTempAndHumi();Delay_1ms(200);for(j=0;j<4;j++)//循环显示4个汉字{for(k=0;k<40;k++)//每个汉字之间的延时,可以调节for(i=0;i<16;i++)//显示1个汉字循环扫描16行,每行显示2个数据{SendSer(0xff,0xff);//清屏SendSeg(seg[i]);//对应的行选通SendSer(~tab0[32*j+2*i+1],~tab0[32*j+2*i]);//发送改行显示数据}}for(k=0;k<80;k++)for(i=0;i<16;i++)//显示1个汉字循环扫描16行,每行显示2个数据{SendSer(0xff,0xff);//清屏SendSeg(seg[i]);//对应的行选通SendSer(~tab[32*temp_value+2*i+1],~tab[32*temp_value+2*i]);}//湿度://for(k=0;k<60;k++)for(j=0;j<4;j++)//循环显示4个汉字{for(k=0;k<40;k++)//每个汉字之间的延时,可以调节for(i=0;i<16;i++)//显示1个汉字循环扫描16行,每行显示2个数据{SendSer(0xff,0xff);//清屏SendSeg(seg[i]);//对应的行选通SendSer(~tab1[32*j+2*i+1],~tab1[32*j+2*i]);//发送改行显示数据}}for(k=0;k<80;k++)for(i=0;i<16;i++)//显示1个汉字循环扫描16行,每行显示2个数据{SendSer(0xff,0xff);//清屏SendSeg(seg[i]);//对应的行选通SendSer(~tab[32*humi_value+2*i+1],~tab[32*humi_value+2*i]);}}}。
DHT11测温湿度程序lcd1602显示
DHT11测温湿度程序lcd1602显示#include<reg52.h>#include<intrins.h>#define uchar unsigned char #define uint unsigned int #define Data P0 // 数据端口sbit RS=P2A4;sbit RW=P2A5;sbit E=P2A6;sbit DHT=P1A0;uchar FirstLine[] ="wen:00.00"; // 第一行数据uchar SecondLine[]="shi:00.00"; // 第二行数据unsigned char shiZ,shiX,wenZ,wenX,check;unsigned char tr_shiZ,tr_shiX,tr_wenZ,tr_wenX;unsigned char flag;unsigned int n=20,m;void delay_1ms(unsigned int i) {unsigned int j=88;for(;i>0;i--){while(j>0)j--;}}void delay_10us()unsigned char i; i--;i--;i--;i--;i--;i--;char read_data(){unsigned char i,num,temp;num=0;for(i=0;i<8;i++){flag=2;while((!DHT)&&flag++);delay_10us();delay_10us();delay_10us();if(DHT==1)}温湿度读取函数************** */temp=1;flag=2;while(DHT&&flag++);}elsetemp=0;num<<=1; num|=temp;}return(num);}void delay(uchar ms) // 延时函数uchar i,j;for(i=ms;i>0;i--) for(j=100;j>0;j--); } voidDelayUs(unsigned char us) //--unsigned char uscnt; uscnt=us>>1; /*12MHz 频率 */ while(--uscnt); }void DelayMs(unsigned char ms) { while(--ms){DelayUs(250);ms 毫秒{ 延时函数 {DelayUs(250);DelayUs(250);DelayUs(250);}}void lcd_write_com(uchar c) // 写命令{DelayMs(5);// 操作前短暂延时,保证信号稳定E=0;RS=0;RW=0;_nop_();E=1;Data=c;E=0;}void lcd_write_dat(uchar c) // 写数据{ DelayMs(5); // 操作前短暂延时,保证信号稳定E=0;RS=1;RW=0;_nop_();E=1;Data=c;E=0;RS=0;}void lcd_init() //LCD 初始化{DelayMs(15);lcd_write_com(0x38); //display modelcd_write_com(0x38); //display modelcd_write_com(0x38); //display modevoid ShowChar(uchar pos,uchar c) //unsigned char p;if (pos>=0x10) p=pos+0xb0; // 是第二行则命令代码高 else p=pos+0x80; // 是第二行则命令代码高 4 位为 0x8 lcd_write_com(p);// 写命令 lcd_write_dat(c); // 写数据}void ShowString (uchar line,char *ptr) //显示字符串 {unsigned char l,*p;lcd_write_com(0x06); //显示光标移动位置 lcd_write_com(0x0c); //显示开及光标设置 lcd_write_com(0x01); //显示清屏 显示单个字符 {4 位为 0xcp=ptr;l=line<<4;while((*p)!='\0'){ShowChar(l++,*(p));p++;}}void disp(void) // 主函数调用的显示函数{ ShowString(0,FirstLine);ShowString(1,SecondLine); } void read_init()初始化及采集程序**************/{DHT=O; //主机使DHT11低电平并延时至少18msdelay_1ms(21);DHT=1; //主机置DHT11高电平20~40us,并等待从机相应delay_1Ous();delay_10us();delay_10us();delay_10us();DHT=1;if(!DHT) // 从机发出相应信号{flag=2; while((!DHT)&&flag++);flag=2; while(DHT&&flag++); // tr_shiZ=read_data();// tr_shiX=read_data();//tr_wenZ=read_data();//tr_wenX=read_data();//check=read_data(); //DHT=1;}}void main(){unsigned char temp; lcd_init();delay(50); while(1){ disp();read_init();temp=tr_shiZ+tr_shiX+tr_wenZ+tr_wenX; if(check==temp) {shiZ=tr_shiZ; shiX=tr_shiX; wenZ=tr_wenZ; wenX=tr_wenX; }FirstLine[4]='0'+wenZ/10;FirstLine[5]='0'+wenZ%10;FirstLine[8]='0'+wenX/10;FirstLine[9]='0'+wenX%10;SecondLine[4]='0'+shiZ/10;开始采集数据 采集湿度整数部分 采集湿度小数部分 采集温度整数部分 采集温度小数部分 采集校验位SecondLine[5]='0'+shiZ%10; SecondLine[8]='0'+shiX/10; SecondLine[9]='0'+shiX%10; } }。
基于51单片机的DHT11温湿度监测+液晶LCD1602显示程序源代码
基于51单片机的DHT11温湿度监测+液晶LCD1602显示程序源代码/***************DHT11温湿度监测+液晶LCD1602显示程序源代码******************单片机型号:STC15W4K56S4,内部晶振:22.1184M。
功能:DHT11温湿度监测+液晶LCD1602显示。
操作说明:通过温湿度传感器DHT11监测温湿度数值,并将温湿度数值显示在液晶LCD1602上。
**************************************************************************/#include "stc15.h" //包含头文件stc15.h#include <intrins.h> //包含头文件intrins.h#define Busy 0x80 //LCD忙sbit LCD_D0 = P0^0; //LCD_D0对应P0.0sbit LCD_D1 = P0^1; //LCD_D1对应P0.1sbit LCD_D2 = P0^2; //LCD_D2对应P0.2sbit LCD_D3 = P0^3; //LCD_D3对应P0.3sbit LCD_D4 = P0^4; //LCD_D4对应P0.4sbit LCD_D5 = P0^5; //LCD_D5对应P0.5sbit LCD_D6 = P0^6; //LCD_D6对应P0.6sbit LCD_D7 = P0^7; //LCD_D7对应P0.7sbit LCD_RS = P1^0; //LCD_RS对应P1.0sbit LCD_RW = P1^1; //LCD_RW对应P1.1sbit LCD_EN = P3^4; //LCD_EN对应P3.4sbit DHT11_PIN = P4^0; //DHT11管脚对应P4.0void delay(unsigned int t); //delay延时函数void delay_us(unsigned int t); //delay_us延时函数void delay_ms(unsigned int t); //delay_ms延时函数void Delay5Ms(void); //5Ms延时函数void GPIO_1602_Configuration(void); //LCD1602液晶IO口初始化void WriteDataLCD(unsigned char WDLCD); //LCD写数据函数void WriteCommandLCD(unsigned char WCLCD,BuysC); //LCD写命令函数unsigned char ReadDataLCD(void); //LCD读数据函数unsigned char ReadStatusLCD(void); //LCD读状态函数void LCDInit(void); //LCD初始化void DisplayOneChar(unsigned char X,unsigned char Y,unsigned char DData);//LCD显示一个字符void DisplayListChar(unsigned char X,unsigned char Y,unsigned char code *DData); //LCD显示一个字符串void DHT11_Init(void); //初始化DHT11void DHT11_Delay(unsigned int j); //延时函数,用于DHT11 void DHT11_Delay_10us(void); //延时函数,用于DHT11 void COM(void);void RH(unsigned char *temp,unsigned char *humi);void DHT11_Display(void);unsigned char code welcome[] = {"DHT 11"}; //LCD显示内容DHT 11 unsigned char code Dht11[] = {"T: H: "}; //LCD显示内容T: H: unsigned char code Space[] = {" "};//LCD显示内容空白unsigned char U8FLAG,k;unsigned char U8count,U8temp;unsigned char U8T_data_H_temp,U8T_data_L_temp;unsigned char U8RH_data_H_temp,U8RH_data_L_temp;unsigned char U8checkdata_temp;unsigned char U8comdata;unsigned char temperature;unsigned char humidity;unsigned char disbuff_T[4]={0,0,0,0};unsigned char disbuff_H[4]={0,0,0,0};void delay(unsigned int t) //delay延时函数{while(t--);}void delay_us(unsigned int t) //delay_us延时函数{unsigned char i;while(t--){i = 3;while(i--) delay(1);}}void delay_ms(unsigned int t) //delay_ms延时函数{while(t--){delay_us(t);}}void Delay5Ms(void) //5ms延时函数{unsigned int TempCyc = 3552;while(TempCyc--);}void GPIO_1602_Configuration(void) //LCD1602液晶IO口初始化{P0M1 = P3M1&0x00;P0M0 = P3M0&0x00;P1M1 = P3M1&0xfc;P1M0 = P3M0&0xfc;P3M1 = P4M1&0xef;P3M0 = P4M0&0xef;}unsigned char ReadStatusLCD(void) //测试LCD忙碌状态{LCD_D7 = 1; //LCD的D7置1LCD_RS = 0; //LCD管脚RS设置成低电平LCD_RW = 1; //LCD管脚RW设置成高电平LCD_EN = 0; //LCD管脚E设置成低电平LCD_EN = 0; //LCD管脚E设置成低电平LCD_EN = 1; //LCD管脚E设置成高电平while(LCD_D7); //检测忙信号return(Busy); //表示当前忙}void WriteCommandLCD(unsigned char WCLCD,BuysC) //BuysC为0时忽略忙检测{if(BuysC) ReadStatusLCD(); //根据需要检测忙LCD_EN = 0; //LCD管脚E设置成低电平_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时LCD_RS = 0; //LCD管脚RS设置成低电平LCD_RW = 0; //LCD管脚RW设置成低电平_nop_(); //空操作,延时_nop_(); //空操作,延时P0 = WCLCD; //将数据送入P0口,即写入指令或地址 _nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时LCD_EN = 1; //E置高电平_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时LCD_EN = 0;//当E由高电平跳变成低电平时,液晶模块开始执行命令}void WriteDataLCD(unsigned char WDLCD) //LCD写数据函数{ReadStatusLCD(); //读取LCD状态LCD_EN = 0; //LCD管脚E设置成低电平_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时LCD_RS = 1; //LCD管脚RS设置成高电平LCD_RW = 0; //LCD管脚RW设置成低电平P0 = WDLCD; //将数据送入P0口_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时LCD_EN = 1; //E置高电平_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时_nop_(); //空操作,延时LCD_EN = 0;//当E由高电平跳变成低电平时,液晶模块开始执行命令}void LCDInit(void) //LCD初始化{WriteCommandLCD(0x38,0); //三次显示模式设置,不检测忙信号Delay5Ms();WriteCommandLCD(0x38,0);Delay5Ms();WriteCommandLCD(0x38,0);Delay5Ms();WriteCommandLCD(0x38,0);WriteCommandLCD(0x08,1); //关闭显示WriteCommandLCD(0x01,1); //显示清屏WriteCommandLCD(0x06,1); //显示光标移动设置WriteCommandLCD(0x0C,1); //显示开及光标设置}void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData){Y &= 0x1;X &= 0xF; //限制X不能大于15,Y不能大于1if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;X |= 0x80; //算出指令码WriteCommandLCD(X,0); //这里不检测忙信号,发送地址码WriteDataLCD(DData); //发送数据}void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData) {unsigned char ListLength;ListLength = 0;Y &= 0x1;X &= 0xF; //限制X不能大于15,Y不能大于1while (DData[ListLength]>=0x20) //若到达字串尾则退出{if (X <= 0xF) //X坐标应小于0xF{DisplayOneChar(X, Y, DData[ListLength]);//显示单个字符ListLength++;X++;}}}void DHT11_Init(void) //初始化DHT11 {P4M1 = P4M1&0xfe;P4M0 = P4M0&0xfe;}void DHT11_Delay(unsigned int j){unsigned char i;for(;j>0;j--){for(i=0;i<250;i++);}}void DHT11_Delay_10us(void){unsigned char i;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;i--;}void COM(void){unsigned char i;for(i=0;i<8;i++){U8FLAG=2;while((!DHT11_PIN)&&U8FLAG++);DHT11_Delay_10us();DHT11_Delay_10us();DHT11_Delay_10us();U8temp=0;if(DHT11_PIN)U8temp=1;U8FLAG=2;while((DHT11_PIN)&&U8FLAG++); //超时则跳出for循环if(U8FLAG==1)break;//判断数据位是0还是1,如果高电平高过预定0高电平值则数据位为 1U8comdata<<=1;U8comdata|=U8temp;}}void RH(unsigned char *temp,unsigned char *humi){DHT11_PIN = 0;DHT11_Delay(180);DHT11_PIN = 1; //总线由上拉电阻拉高主机延时20us DHT11_Delay_10us();DHT11_Delay_10us();DHT11_Delay_10us();DHT11_Delay_10us(); //主机设为输入判断从机响应信号DHT11_PIN = 1;//判断从机是否有低电平响应信号如不响应则跳出,响应则向下运行if(!DHT11_PIN){U8FLAG=2;//判断从机是否发出 80us 的低电平响应信号是否结束while((!DHT11_PIN)&&U8FLAG++);U8FLAG=2;//判断从机是否发出 80us 的高电平,如发出则进入数据接收状态while((DHT11_PIN)&&U8FLAG++); //数据接收状态COM();U8RH_data_H_temp=U8comdata;COM();U8RH_data_L_temp=U8comdata;COM();U8T_data_H_temp=U8comdata;COM();U8T_data_L_temp=U8comdata;COM();U8checkdata_temp=U8comdata;DHT11_PIN=1; //数据校验U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp); if(U8temp==U8checkdata_temp){*temp = U8T_data_H_temp;*humi = U8RH_data_H_temp;}}}void DHT11_Display(void){RH(&temperature,&humidity);disbuff_T[2]=temperature/100+0x30;disbuff_T[1]=temperature/10%10+0x30;disbuff_T[0]=temperature%10+0x30;disbuff_H[2]=humidity/100+0x30;disbuff_H[1]=humidity/10%10+0x30;disbuff_H[0]=humidity%10+0x30;DisplayOneChar(2,1,disbuff_T[2]);delay_ms(10); //延时DisplayOneChar(3,1,disbuff_T[1]);delay_ms(10); //延时DisplayOneChar(4,1,disbuff_T[0]);delay_ms(10); //延时DisplayOneChar(8,1,disbuff_H[2]);delay_ms(10); //延时DisplayOneChar(9,1,disbuff_H[1]);delay_ms(10); //延时DisplayOneChar(10,1,disbuff_H[0]);delay_ms(10); //延时}void main(void){GPIO_1602_Configuration(); //LCD1602液晶IO口初始化delay_ms(10); //延时LCDInit(); //LCD1602初始化delay_ms(10); //延时DHT11_Init(); //初始化DHT11DisplayListChar(5,0,welcome); //LCD1602显示Hello My Friends delay_ms(10); //延时while(1){DisplayListChar(0,1,Space); //LCD1602显示P: K1delay_ms(10); //延时DisplayListChar(0,1,Dht11); //LCD1602显示delay_ms(10); //延时DHT11_Display();delay_ms(200); //延时}}程序源代码是编译通过的DHT11温湿度监测模块接口电路图该程序的实际运行效果。
DHT11数字温湿度传感器(附1602显示程序)已验证ok
1、DHT11产品概述DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器。
它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。
传感器包括一个电阻式感湿元件和一个NTC测温元件,并与一个高性能8位单片机相连接。
因此该产品具有品质卓越、超快响应、抗干扰能力强、性价比极高等优点。
每个DHT11传感器都在极为精确的湿度校验室中进行校准。
校准系数以程序的形式储存在OTP内存中,传感器内部在检测信号的处理过程中要调用这些校准系数。
单线制串行接口,使系统集成变得简易快捷。
超小的体积、极低的功耗,信号传输距离可达20米以上,使其成为各类应用甚至最为苛刻的应用场合的最佳选则。
产品为 4 针单排引脚封装。
连接方便,特殊封装形式可根据用户需求而提供。
2、应用领域►暖通空调►测试及检测设备►汽车►数据记录器►消费品►自动控制►气象站►家电►湿度调节器►医疗►除湿器应用领域3、接口说明建议连接线长度短于20米时用5K上拉电阻,大于20米时根据实际情况使用合适的上拉电阻4、电源引脚DHT11的供电电压为 3-5.5V。
传感器上电后,要等待 1s 以越过不稳定状态在此期间无需发送任何指令。
电源引脚(VDD,GND)之间可增加一个100nF 的电容,用以去耦滤波。
5、串行接口 (单线双向)DATA 用于微处理器与 DHT11之间的通讯和同步,采用单总线数据格式,一次通讯时间4ms左右,数据分小数部分和整数部分,具体格式在下面说明,当前小数部分用于以后扩展,现读出为零.操作流程如下:一次完整的数据传输为40bit,高位先出。
数据格式:8bit湿度整数数据+8bit湿度小数数据 +8bi温度整数数据+8bit温度小数数据+8bit校验和数据传送正确时校验和数据等于“8bit湿度整数数据+8bit湿度小数数据+8bi温度整数数据+8bit温度小数数据”所得结果的末8位。
6、封装信息7、DHT11引脚说明8、DHT11温湿度1602液晶显示程序示例主程序:#include <reg51.h>#include <intrins.h>#include <delay.h>#include<lcd.h>#include<absacc.h>typedef unsigned char U8;typedef unsigned int U16;U8 U8FLAG;U8 U8count,U8temp;U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata; U8U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8 checkdata_temp;U8 U8comdata;sbit P2_0 = P2^0 ;sbit P2_1 = P2^1 ;sbit P2_2 = P2^2 ;sbit P2_3 = P2^3 ;unsigned char str1[]="ShiDu:";unsigned char str2[]="WenDu:";void Delay(U16 j){ U8 i;for(;j>0;j--){for(i=0;i<27;i++);}}void Delay_10us(void){U8 i;i--;i--;i--;i--;i--;i--;}void COM(void){U8 i;for(i=0;i<8;i++){U8FLAG=2;//----------------------P2_1=0 ; //TP2_1=1 ; //T//----------------------while((!P2_0)&&U8FLAG++);Delay_10us();Delay_10us();// Delay_10us();U8temp=0;if(P2_0)U8temp=1;U8FLAG=2;while((P2_0)&&U8FLAG++);//----------------------P2_1=0 ; //TP2_1=1 ; //T//----------------------//超时则跳出for循环if(U8FLAG==1)break;//判断数据位是0还是1// 如果高电平高过预定0高电平值则数据位为1 U8comdata<<=1;U8comdata|=U8temp; //0}//rof}//--------------------------------//-----湿度读取子程序------------//--------------------------------//----以下变量均为全局变量--------//----温度高8位== U8T_data_H------//----温度低8位== U8T_data_L------//----湿度高8位== U8RH_data_H-----//----湿度低8位== U8RH_data_L-----//----校验8位== U8checkdata-----//----调用相关子程序如下----------//---- Delay();, Delay_10us();,COM();//--------------------------------void RH(void){//主机拉低18msP2_0=0;Delay(180);P2_0=1;//总线由上拉电阻拉高主机延时20usDelay_10us();Delay_10us();Delay_10us();Delay_10us();//主机设为输入判断从机响应信号P2_0=1;//判断从机是否有低电平响应信号如不响应则跳出,响应则向下运行if(!P2_0) //T !{U8FLAG=2;//判断从机是否发出80us 的低电平响应信号是否结束while((!P2_0)&&U8FLAG++);U8FLAG=2;//判断从机是否发出80us 的高电平,如发出则进入数据接收状态while((P2_0)&&U8FLAG++);//数据接收状态COM();U8RH_data_H_temp=U8comdata;COM();U8RH_data_L_temp=U8comdata;COM();U8T_data_H_temp=U8comdata;COM();U8T_data_L_temp=U8comdata;COM();U8checkdata_temp=U8comdata;P2_0=1;//数据校验U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_d ata_L_temp);if(U8temp==U8checkdata_temp){U8RH_data_H=U8RH_data_H_temp;U8RH_data_L=U8RH_data_L_temp;U8T_data_H=U8T_data_H_temp;U8T_data_L=U8T_data_L_temp;U8checkdata=U8checkdata_temp;}//fi}//fi}void main(){U8 shidu_shi,shidu_ge,wendu_shi,wendu_ge;LCD_init();delay_nms(2);LCD_write_string(0,LINE1,str1);LCD_write_string(0,LINE2,str2);while(1){RH();shidu_shi=0x30+U8RH_data_H/10;shidu_ge=0x30+U8RH_data_H%10;// shidu_xs=0x30+U8RH_data_L/10;wendu_shi=0x30+U8T_data_H/10;wendu_ge=0x30+U8T_data_H%10;//wendu_xs=0x30+U8T_data_L/10;LCD_write_char(6,0,shidu_shi);LCD_write_char(7,0,shidu_ge);//LCD_write_char(9,0,shidu_xs);LCD_write_char(6,1,wendu_shi);LCD_write_char(7,1,wendu_ge);//LCD_write_char(9,1,wendu_xs);}}H 文件ifndef lcd_H#define lcd_H#include <reg51.h>#include <delay.h>/************************************///common part#define HIGH 1#define LOW 0#define TRUE 1#define FALSE 0#define ZERO 0#define MSB 0x80#define LSB 0x01/************************************///lcd part#define LINE1 0#define LINE2 1#define LINE1_HEAD 0x80#define LINE2_HEAD 0xC0#define DATA_MODE 0x38#define OPEN_SCREEN 0x0C#define DISPLAY_ADDRESS 0x80#define CLEARSCREEN LCD_en_com(0x01) /*************************************///change this part at different board#define LCDIO P1sbit LCD1602_RS=P2^4;sbit LCD1602_RW=P2^5;sbit LCD1602_EN=P2^6;/********************************************************************/ void LCD_Read_BF(void){unsigned char read=0;LCD1602_RS = LOW; //RS 0LCD1602_RW = HIGH; //RW 1LCD1602_EN = HIGH; //EN 1 Read BFLCDIO = 0xFF;do{read = LCDIO;}while(read&MSB);}void LCD_en_com(unsigned char command) //写指令{LCD_Read_BF();LCD1602_RS = LOW; //RS 0LCD1602_RW = LOW; //RW 0LCD1602_EN = HIGH; //EN --\|/__ Write commandLCDIO = command;LCD1602_EN = LOW;}void LCD_en_dat(unsigned char dat) //写数据{LCD_Read_BF();LCD1602_RS = HIGH; //RS 1LCD1602_RW = LOW; //RW 0LCD1602_EN = HIGH; //EN --\|/__ Write dataLCDIO = dat;LCD1602_EN = LOW;}void LCD_set_xy(unsigned char x,unsigned char y){unsigned char address;if(y == LINE1)address = LINE1_HEAD + x;elseaddress = LINE2_HEAD + x;LCD_en_com(address);}void LCD_write_char( unsigned x,unsigned char y,unsigned char dat) {LCD_set_xy(x,y);LCD_en_dat(dat);}void LCD_write_string(unsigned char x,unsigned char y,unsigned char *s) {LCD_set_xy(x,y);while(*s){LCDIO = *s;LCD_en_dat(*s);s++;}}void LCD_init(void){LCD_en_com(DATA_MODE);//set 8 bit data transmission modeLCD_en_com(OPEN_SCREEN);//open display (enable lcd display)LCD_en_com(DISPLAY_ADDRESS);//set lcd first display addressCLEARSCREEN;//clear screen}#endif#ifndef DELAY_H#define DELAY_Hvoid delay_nms(unsigned int n){unsigned int i=0,j=0;for (i=n;i>0;i--)for (j=0;j<1140;j++); }#endif。
STC15单片机DHT11在LCD1602上显示程序
敬告:没有51单片机基础的人请慎重下载高质量实用性51单片机STC15W系列程序(4),STC8A系列可参考STC15单片机DHT11在LCD1602上显示程序注:在本节关于DHT11的程序有两种/*****************************************/版本一:/****************************************//****************************************/main函数程序:#include "Library.h"unsigned char strbuf[4];//void ValToStr(unsigned char *str,unsigned char *source,unsigned char len);unsigned char tmrflag = 0;unsigned char DHTbuf[5];void Delay1000ms() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();i = 43;j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void main(){unsigned char DHTstr[8];P3M1 &= 0xBF; P3M0 &= 0xBF; P2M1 &= 0xE5; P2M0 &= 0xE5;P0M1 = 0x00; P0M0 = 0x00;LCD1602_init();LCD1602_wBytes(2,0,".",1);LCD1602_wBytes(8,0,"humi",4);LCD1602_wBytes(2,1,".",1);LCD1602_wBytes(8,1,"temp",4);while(1){DHT11_start(DHTbuf);// ValToStr(DHTstr,DHTbuf,sizeof(DHTbuf)-1);DHTstr[0] = DHTbuf[0]/10 + '0';DHTstr[1] = DHTbuf[0]%10 + '0';DHTstr[2] = DHTbuf[1]/10 + '0';DHTstr[3] = DHTbuf[1]%10 + '0';DHTstr[4] = DHTbuf[2]/10 + '0';DHTstr[5] = DHTbuf[2]%10 + '0';DHTstr[6] = DHTbuf[3]/10 + '0';DHTstr[7] = DHTbuf[3]%10 + '0';LCD1602_wBytes(0,0,DHTstr,2);LCD1602_wBytes(3,0,DHTstr+2,2);LCD1602_wBytes(0,1,DHTstr+4,2);LCD1602_wBytes(3,1,DHTstr+6,2);Delay1000ms();Delay1000ms();}}//void ValToStr(unsigned char *str,unsigned char *source,unsigned char len)//{// unsigned char i;// while(len>0)// {// str[i*2] = source[i]/10+'0';// str[1+i*2] = source[i]%10+'0';// i++;// len--;// }//}/*********************************************/DHT11程序:/******************************8bit humidity integer data + 8bit humidity decimal data 8bit temperature integer data + 8bit temperature decimal data8bit check sum,high bit ahead*******************************/#include "Library.h"unsigned char u8flag;unsigned char check_buf[5];unsigned char tmp;void delay_1s() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void Delay10us() //@11.0592MHz {unsigned char i;_nop_();i = 25;while (--i);}void Delay20ms() //@11.0592MHz {unsigned char i, j, k;_nop_();_nop_();i = 1;k = 35;do{do{while (--k);} while (--j);} while (--i);}unsigned char Rec_8bit(){unsigned char i;unsigned char ret_8bit;unsigned char tmp;for(i=0;i<8;i++){while(!DHT11port);Delay10us();Delay10us();Delay10us();tmp = 0;if(DHT11port){tmp=1;}u8flag = 2;while((DHT11port)&&u8flag++);if(u8flag==1)break;ret_8bit<<=1;ret_8bit |= tmp;}return ret_8bit;}void DHT11_start(unsigned char *rec_buf) {// delay_1s();DHT11port = 0;Delay20ms();DHT11port = 1;Delay10us();Delay10us();Delay10us();Delay10us();//DHT11port = 1;if(!DHT11port){u8flag=2;// while(!DHT11port);while((!DHT11port)&&u8flag++);// if(DHT11port)// {// while(DHT11port);u8flag=2;while((DHT11port)&&u8flag++);check_buf[0] = Rec_8bit();check_buf[1] = Rec_8bit();check_buf[2] = Rec_8bit();check_buf[3] = Rec_8bit();check_buf[4] = Rec_8bit();if(!DHT11port){while(!DHT11port);}DHT11port = 1;tmp = check_buf[0]+check_buf[1]+check_buf[2]+check_buf[3] ;if(tmp==check_buf[4]){rec_buf[0] = check_buf[0];rec_buf[1] = check_buf[1];rec_buf[2] = check_buf[2];rec_buf[3] = check_buf[3];}// }}else{rec_buf[0] = 0;rec_buf[1] = 0;rec_buf[2] = 0;rec_buf[3] = 0;}}/*********************************************/ LCD1602程序:#include "Library.h"void LCD1602_rsta(){unsigned char tmp;P0 = 0xFF;//this is a mustrs = 0;rw = 1;do{en = 1;//Delay1us();tmp = P0;//Delay1us();en = 0;}while(tmp&0x80);}void LCD1602_wdat(unsigned char dat) {LCD1602_rsta();rs=1;rw=0;P0 = dat;en = 1;//Delay1us();en = 0;}void LCD1602_wcmd(unsigned char cmd) {LCD1602_rsta();rs=0;rw=0;P0 = cmd;en = 1;//Delay1us();en = 0;}void Setcursor(unsigned char x,unsigned char y){if(y==0)x = x + 0x00;else if(y==1)x = x + 0x40;LCD1602_wcmd(x|0x80);}void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len){Setcursor(x,y);while(buf_len>0){LCD1602_wdat(*buf++);buf_len--;}}void OnCursor(){LCD1602_wcmd(0x0F);}void OffCursor()LCD1602_wcmd(0x0C);}void LCD1602_init(){// Delay15ms();// LCD1602_wcmd(0x38);// Delay5ms();LCD1602_wcmd(0x38);// LCD1602_wcmd(0x08);LCD1602_wcmd(0x06);LCD1602_wcmd(0x0C);LCD1602_wcmd(0x01);}/*****************************************/ Library.h#ifndef _Library_H#define _Library_H#include <STC15.h>#include <intrins.h>#define MAIN_Fosc 11059200Lsbit DHT11port = P3^6;void DHT11_start(unsigned char *rec_buf);sbit rs = P2^4;sbit rw = P2^3;sbit en = P2^1;void LCD1602_init();void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len);#endif/*****************************************/ 版本二(结构体):/****************************************/ /****************************************/ main程序:#include "Library.h"#include "string.h"void Delay1000ms() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();i = 43;j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void main(){unsigned char DHTstr[8];P3M1 &= 0xBF; P3M0 &= 0xBF;P2M1 &= 0xE5; P2M0 &= 0xE5;P0M1 = 0x00; P0M0 = 0x00;LCD1602_init();LCD1602_wBytes(2,0,".",1);LCD1602_wBytes(8,0,"humi",4);LCD1602_wBytes(2,1,".",1);LCD1602_wBytes(8,1,"temp",4);while(1){DHT11_start();// memset(DHTstr, 0, 8);DHTstr[0] = ht.humi_h +'0' ;DHTstr[1] = ht.humi_l+'0' ;DHTstr[2] = ht.humi_dh +'0' ;DHTstr[3] = ht.humi_dl +'0' ;DHTstr[4] = ht.temp_h +'0' ;DHTstr[5] = ht.temp_l +'0' ;DHTstr[7] = ht.temp_dh +'0' ;DHTstr[6] = ht.temp_dl +'0' ;LCD1602_wBytes(0,0,DHTstr,2);LCD1602_wBytes(3,0,DHTstr+2,2);LCD1602_wBytes(0,1,DHTstr+4,2);LCD1602_wBytes(3,1,DHTstr+6,2);Delay1000ms();Delay1000ms();}}/***********************************************/ DHT11程序:/******************************8bit humidity integer data + 8bit humidity decimal data 8bit temperature integer data + 8bit temperature decimal data8bit check sum,high bit ahead*******************************/#include "Library.h"unsigned char u8flag;unsigned char check_buf[5];unsigned char tmp;unsigned char rec_buf[4];htstruct ht;void delay_1s() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();i = 43;j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void Delay10us() //@11.0592MHz {unsigned char i;_nop_();i = 25;while (--i);}void Delay20ms() //@11.0592MHz {unsigned char i, j, k;_nop_();_nop_();i = 1;j = 216;k = 35;do{do{while (--k);} while (--j);} while (--i);}unsigned char Rec_8bit(){unsigned char i;unsigned char ret_8bit;unsigned char tmp;for(i=0;i<8;i++){while(!DHT11port);Delay10us();Delay10us();Delay10us();tmp = 0;if(DHT11port){tmp=1;}u8flag = 2;while((DHT11port)&&u8flag++);if(u8flag==1)break;ret_8bit<<=1;ret_8bit |= tmp;}return ret_8bit;}void DHT11_start(){// delay_1s();DHT11port = 0;Delay20ms();DHT11port = 1;Delay10us();Delay10us();Delay10us();Delay10us();//DHT11port = 1;if(!DHT11port){u8flag=2;while((!DHT11port)&&u8flag++);u8flag=2;while((DHT11port)&&u8flag++);check_buf[0] = Rec_8bit();check_buf[1] = Rec_8bit();check_buf[2] = Rec_8bit();check_buf[3] = Rec_8bit();check_buf[4] = Rec_8bit();if(!DHT11port){while(!DHT11port);}DHT11port = 1;tmp = check_buf[0]+check_buf[1]+check_buf[2]+check_buf[3] ;if(tmp==check_buf[4]){rec_buf[0] = check_buf[0];rec_buf[1] = check_buf[1];rec_buf[2] = check_buf[2];rec_buf[3] = check_buf[3];}ht.humi_h = rec_buf[0]/10 ;ht.humi_l = rec_buf[0]%10;ht.humi_dh = rec_buf[1]/10;ht.humi_dl = rec_buf[1]%10;ht.temp_h = rec_buf[2]/10;ht.temp_l = rec_buf[2]%10;ht.temp_dh = rec_buf[3]/10;ht.temp_dl = rec_buf[3]%10; }else{ht.humi_h = 0;ht.humi_l = 0;ht.humi_dh = 0;ht.humi_dl = 0;ht.temp_h = 0;ht.temp_l = 0;ht.temp_dh = 0;ht.temp_dl = 0;}}/************************************************/ LCD1602程序:#include "Library.h"void LCD1602_rsta(){unsigned char tmp;P0 = 0xFF;//this is a mustrs = 0;rw = 1;do{en = 1;//Delay1us();tmp = P0;//Delay1us();en = 0;}while(tmp&0x80);}void LCD1602_wdat(unsigned char dat){LCD1602_rsta();rs=1;rw=0;P0 = dat;en = 1;//Delay1us();en = 0;}void LCD1602_wcmd(unsigned char cmd){LCD1602_rsta();rs=0;rw=0;P0 = cmd;en = 1;//Delay1us();en = 0;}void Setcursor(unsigned char x,unsigned char y){if(y==0)x = x + 0x00;else if(y==1)x = x + 0x40;LCD1602_wcmd(x|0x80);}void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len){Setcursor(x,y);while(buf_len>0){LCD1602_wdat(*buf++); buf_len--;}}void OnCursor(){LCD1602_wcmd(0x0F);}void OffCursor(){LCD1602_wcmd(0x0C);}void LCD1602_init(){// Delay15ms();// LCD1602_wcmd(0x38);// Delay5ms();LCD1602_wcmd(0x38);// LCD1602_wcmd(0x08);LCD1602_wcmd(0x06);LCD1602_wcmd(0x0C);LCD1602_wcmd(0x01);}/******************************************/ Library.h#ifndef _Library_H#define _Library_H#include <STC15.h>#include <intrins.h>#define MAIN_Fosc 11059200Lsbit DHT11port = P3^6;typedef struct htstruct{unsigned char humi_h;unsigned char humi_l;unsigned char humi_dh;unsigned char humi_dl;unsigned char temp_h;unsigned char temp_l;unsigned char temp_dh;unsigned char temp_dl;}htstruct;extern htstruct ht;void DHT11_start();sbit rs = P2^4;sbit rw = P2^3;sbit en = P2^1;void LCD1602_init();void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len);#endif。
STC15单片机DHT11在LCD1602上显示程序
敬告:没有51单片机基础的人请慎重下载高质量实用性51单片机STC15W系列程序(4),STC8A系列可参考STC15单片机DHT11在LCD1602上显示程序注:在本节关于DHT11的程序有两种/*****************************************/版本一:/****************************************//****************************************/main函数程序:#include "Library.h"unsigned char strbuf[4];//void ValToStr(unsigned char *str,unsigned char *source,unsigned char len);unsigned char tmrflag = 0;unsigned char DHTbuf[5];void Delay1000ms() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();i = 43;j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void main(){unsigned char DHTstr[8];P3M1 &= 0xBF; P3M0 &= 0xBF; P2M1 &= 0xE5; P2M0 &= 0xE5;P0M1 = 0x00; P0M0 = 0x00;LCD1602_init();LCD1602_wBytes(2,0,".",1);LCD1602_wBytes(8,0,"humi",4);LCD1602_wBytes(2,1,".",1);LCD1602_wBytes(8,1,"temp",4);while(1){DHT11_start(DHTbuf);// ValToStr(DHTstr,DHTbuf,sizeof(DHTbuf)-1);DHTstr[0] = DHTbuf[0]/10 + '0';DHTstr[1] = DHTbuf[0]%10 + '0';DHTstr[2] = DHTbuf[1]/10 + '0';DHTstr[3] = DHTbuf[1]%10 + '0';DHTstr[4] = DHTbuf[2]/10 + '0';DHTstr[5] = DHTbuf[2]%10 + '0';DHTstr[6] = DHTbuf[3]/10 + '0';DHTstr[7] = DHTbuf[3]%10 + '0';LCD1602_wBytes(0,0,DHTstr,2);LCD1602_wBytes(3,0,DHTstr+2,2);LCD1602_wBytes(0,1,DHTstr+4,2);LCD1602_wBytes(3,1,DHTstr+6,2);Delay1000ms();Delay1000ms();}}//void ValToStr(unsigned char *str,unsigned char *source,unsigned char len)//{// unsigned char i;// while(len>0)// {// str[i*2] = source[i]/10+'0';// str[1+i*2] = source[i]%10+'0';// i++;// len--;// }//}/*********************************************/DHT11程序:/******************************8bit humidity integer data + 8bit humidity decimal data 8bit temperature integer data + 8bit temperature decimal data8bit check sum,high bit ahead*******************************/#include "Library.h"unsigned char u8flag;unsigned char check_buf[5];unsigned char tmp;void delay_1s() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void Delay10us() //@11.0592MHz {unsigned char i;_nop_();i = 25;while (--i);}void Delay20ms() //@11.0592MHz {unsigned char i, j, k;_nop_();_nop_();i = 1;k = 35;do{do{while (--k);} while (--j);} while (--i);}unsigned char Rec_8bit(){unsigned char i;unsigned char ret_8bit;unsigned char tmp;for(i=0;i<8;i++){while(!DHT11port);Delay10us();Delay10us();Delay10us();tmp = 0;if(DHT11port){tmp=1;}u8flag = 2;while((DHT11port)&&u8flag++);if(u8flag==1)break;ret_8bit<<=1;ret_8bit |= tmp;}return ret_8bit;}void DHT11_start(unsigned char *rec_buf) {// delay_1s();DHT11port = 0;Delay20ms();DHT11port = 1;Delay10us();Delay10us();Delay10us();Delay10us();//DHT11port = 1;if(!DHT11port){u8flag=2;// while(!DHT11port);while((!DHT11port)&&u8flag++);// if(DHT11port)// {// while(DHT11port);u8flag=2;while((DHT11port)&&u8flag++);check_buf[0] = Rec_8bit();check_buf[1] = Rec_8bit();check_buf[2] = Rec_8bit();check_buf[3] = Rec_8bit();check_buf[4] = Rec_8bit();if(!DHT11port){while(!DHT11port);}DHT11port = 1;tmp = check_buf[0]+check_buf[1]+check_buf[2]+check_buf[3] ;if(tmp==check_buf[4]){rec_buf[0] = check_buf[0];rec_buf[1] = check_buf[1];rec_buf[2] = check_buf[2];rec_buf[3] = check_buf[3];}// }}else{rec_buf[0] = 0;rec_buf[1] = 0;rec_buf[2] = 0;rec_buf[3] = 0;}}/*********************************************/ LCD1602程序:#include "Library.h"void LCD1602_rsta(){unsigned char tmp;P0 = 0xFF;//this is a mustrs = 0;rw = 1;do{en = 1;//Delay1us();tmp = P0;//Delay1us();en = 0;}while(tmp&0x80);}void LCD1602_wdat(unsigned char dat) {LCD1602_rsta();rs=1;rw=0;P0 = dat;en = 1;//Delay1us();en = 0;}void LCD1602_wcmd(unsigned char cmd) {LCD1602_rsta();rs=0;rw=0;P0 = cmd;en = 1;//Delay1us();en = 0;}void Setcursor(unsigned char x,unsigned char y){if(y==0)x = x + 0x00;else if(y==1)x = x + 0x40;LCD1602_wcmd(x|0x80);}void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len){Setcursor(x,y);while(buf_len>0){LCD1602_wdat(*buf++);buf_len--;}}void OnCursor(){LCD1602_wcmd(0x0F);}void OffCursor()LCD1602_wcmd(0x0C);}void LCD1602_init(){// Delay15ms();// LCD1602_wcmd(0x38);// Delay5ms();LCD1602_wcmd(0x38);// LCD1602_wcmd(0x08);LCD1602_wcmd(0x06);LCD1602_wcmd(0x0C);LCD1602_wcmd(0x01);}/*****************************************/ Library.h#ifndef _Library_H#define _Library_H#include <STC15.h>#include <intrins.h>#define MAIN_Fosc 11059200Lsbit DHT11port = P3^6;void DHT11_start(unsigned char *rec_buf);sbit rs = P2^4;sbit rw = P2^3;sbit en = P2^1;void LCD1602_init();void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len);#endif/*****************************************/ 版本二(结构体):/****************************************/ /****************************************/ main程序:#include "Library.h"#include "string.h"void Delay1000ms() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();i = 43;j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void main(){unsigned char DHTstr[8];P3M1 &= 0xBF; P3M0 &= 0xBF;P2M1 &= 0xE5; P2M0 &= 0xE5;P0M1 = 0x00; P0M0 = 0x00;LCD1602_init();LCD1602_wBytes(2,0,".",1);LCD1602_wBytes(8,0,"humi",4);LCD1602_wBytes(2,1,".",1);LCD1602_wBytes(8,1,"temp",4);while(1){DHT11_start();// memset(DHTstr, 0, 8);DHTstr[0] = ht.humi_h +'0' ;DHTstr[1] = ht.humi_l+'0' ;DHTstr[2] = ht.humi_dh +'0' ;DHTstr[3] = ht.humi_dl +'0' ;DHTstr[4] = ht.temp_h +'0' ;DHTstr[5] = ht.temp_l +'0' ;DHTstr[7] = ht.temp_dh +'0' ;DHTstr[6] = ht.temp_dl +'0' ;LCD1602_wBytes(0,0,DHTstr,2);LCD1602_wBytes(3,0,DHTstr+2,2);LCD1602_wBytes(0,1,DHTstr+4,2);LCD1602_wBytes(3,1,DHTstr+6,2);Delay1000ms();Delay1000ms();}}/***********************************************/ DHT11程序:/******************************8bit humidity integer data + 8bit humidity decimal data 8bit temperature integer data + 8bit temperature decimal data8bit check sum,high bit ahead*******************************/#include "Library.h"unsigned char u8flag;unsigned char check_buf[5];unsigned char tmp;unsigned char rec_buf[4];htstruct ht;void delay_1s() //@11.0592MHz{unsigned char i, j, k;_nop_();_nop_();i = 43;j = 6;k = 203;do{do{while (--k);} while (--j);} while (--i);}void Delay10us() //@11.0592MHz {unsigned char i;_nop_();i = 25;while (--i);}void Delay20ms() //@11.0592MHz {unsigned char i, j, k;_nop_();_nop_();i = 1;j = 216;k = 35;do{do{while (--k);} while (--j);} while (--i);}unsigned char Rec_8bit(){unsigned char i;unsigned char ret_8bit;unsigned char tmp;for(i=0;i<8;i++){while(!DHT11port);Delay10us();Delay10us();Delay10us();tmp = 0;if(DHT11port){tmp=1;}u8flag = 2;while((DHT11port)&&u8flag++);if(u8flag==1)break;ret_8bit<<=1;ret_8bit |= tmp;}return ret_8bit;}void DHT11_start(){// delay_1s();DHT11port = 0;Delay20ms();DHT11port = 1;Delay10us();Delay10us();Delay10us();Delay10us();//DHT11port = 1;if(!DHT11port){u8flag=2;while((!DHT11port)&&u8flag++);u8flag=2;while((DHT11port)&&u8flag++);check_buf[0] = Rec_8bit();check_buf[1] = Rec_8bit();check_buf[2] = Rec_8bit();check_buf[3] = Rec_8bit();check_buf[4] = Rec_8bit();if(!DHT11port){while(!DHT11port);}DHT11port = 1;tmp = check_buf[0]+check_buf[1]+check_buf[2]+check_buf[3] ;if(tmp==check_buf[4]){rec_buf[0] = check_buf[0];rec_buf[1] = check_buf[1];rec_buf[2] = check_buf[2];rec_buf[3] = check_buf[3];}ht.humi_h = rec_buf[0]/10 ;ht.humi_l = rec_buf[0]%10;ht.humi_dh = rec_buf[1]/10;ht.humi_dl = rec_buf[1]%10;ht.temp_h = rec_buf[2]/10;ht.temp_l = rec_buf[2]%10;ht.temp_dh = rec_buf[3]/10;ht.temp_dl = rec_buf[3]%10; }else{ht.humi_h = 0;ht.humi_l = 0;ht.humi_dh = 0;ht.humi_dl = 0;ht.temp_h = 0;ht.temp_l = 0;ht.temp_dh = 0;ht.temp_dl = 0;}}/************************************************/ LCD1602程序:#include "Library.h"void LCD1602_rsta(){unsigned char tmp;P0 = 0xFF;//this is a mustrs = 0;rw = 1;do{en = 1;//Delay1us();tmp = P0;//Delay1us();en = 0;}while(tmp&0x80);}void LCD1602_wdat(unsigned char dat){LCD1602_rsta();rs=1;rw=0;P0 = dat;en = 1;//Delay1us();en = 0;}void LCD1602_wcmd(unsigned char cmd){LCD1602_rsta();rs=0;rw=0;P0 = cmd;en = 1;//Delay1us();en = 0;}void Setcursor(unsigned char x,unsigned char y){if(y==0)x = x + 0x00;else if(y==1)x = x + 0x40;LCD1602_wcmd(x|0x80);}void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len){Setcursor(x,y);while(buf_len>0){LCD1602_wdat(*buf++); buf_len--;}}void OnCursor(){LCD1602_wcmd(0x0F);}void OffCursor(){LCD1602_wcmd(0x0C);}void LCD1602_init(){// Delay15ms();// LCD1602_wcmd(0x38);// Delay5ms();LCD1602_wcmd(0x38);// LCD1602_wcmd(0x08);LCD1602_wcmd(0x06);LCD1602_wcmd(0x0C);LCD1602_wcmd(0x01);}/******************************************/ Library.h#ifndef _Library_H#define _Library_H#include <STC15.h>#include <intrins.h>#define MAIN_Fosc 11059200Lsbit DHT11port = P3^6;typedef struct htstruct{unsigned char humi_h;unsigned char humi_l;unsigned char humi_dh;unsigned char humi_dl;unsigned char temp_h;unsigned char temp_l;unsigned char temp_dh;unsigned char temp_dl;}htstruct;extern htstruct ht;void DHT11_start();sbit rs = P2^4;sbit rw = P2^3;sbit en = P2^1;void LCD1602_init();void LCD1602_wBytes(unsigned char x,unsigned char y,unsigned char *buf,unsigned char buf_len);#endif。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//11.0592MHz单片机STC89C52RC;DHT11在LCD1602显示#include <reg52.h>
# include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
/***********端口定义**************/
sbit RS=P2^6;//1602RS端口
sbit RW=P2^5;//1602RW端口
sbit E=P2^7;//1602E端口
//LCD1602数据口接P0
sbit IO=P2^0;//dht11数据口
/**********变量定义*****************/
uint timeout;//溢出
uchar RH_H;//温度整数位
uchar RH_L;// 温度小数位
uchar T_H;// 湿度整数位
uchar T_L;// 湿度小数位
uchar Cheakdata;//校验位
/**********************************/
/*****延时1ms******/
void Delay1ms(uchar c)//1ms延时
{
uchar i, j;
for(;c>0;c--)
{
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
/*****延时10us******/
void Delay10us(void)//10us延时
{
uchar i;
{
i = 2;
while (--i);
}
}
/****1602忙检测函数****/
uchar LCD1602_BUSY()//读状态
{
uchar state;
RS=0;
RW=1;
P0=0xFF;
E=1;
Delay1ms(1);
E=0;
return state;
}
/*****1602写数据函数带忙检测*****/
void LCD1602_WRITE_DATA_BUSY(uchar databuf) {
while((LCD1602_BUSY()&&0x80)==0x80); RS=1;
RW=0;
P0=databuf;
E=1;
E=0;
}
/****1602写指令函数******/
void LCD1602_WRITE_COM(uchar combuf)
{
RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
/****1602写指令函数带忙检测******/
void LCD1602_WRITE_COM_BUSY(uchar combuf) {
while((LCD1602_BUSY()&&0x80)==0x80); RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
/****1602初始化函数******/
void LCD1602_init(void)
{
Delay1ms(15);//15ms
LCD1602_WRITE_COM(0x38);
Delay1ms(5);//5ms
LCD1602_WRITE_COM(0x38);
Delay1ms(5);//5ms
LCD1602_WRITE_COM(0x38);
LCD1602_WRITE_COM_BUSY(0x38);
LCD1602_WRITE_COM_BUSY(0x08);
LCD1602_WRITE_COM_BUSY(0x01);
LCD1602_WRITE_COM_BUSY(0x06);
LCD1602_WRITE_COM_BUSY(0x0C);
}
/*******DHT11读字节**************/ uchar ReadByte(void)
{
uchar i;
uchar buf=0;
for(i=0;i<8;i++)
{
IO=1;
timeout=0;
while((IO==0)&&((timeout++)<500));
Delay10us();
Delay10us();
Delay10us();
_nop_();//31us
buf=buf<<1;
if(IO==1)
{
buf=buf|0x01;
}
timeout=0;
while((IO==1)&&((timeout++)<500));
}
return buf;
}
/*******DHT11读温湿度************/ uchar ReadRH(void)
{
IO=0;
Delay1ms(20);//20ms
IO=1;
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();//50us
if(IO==0)
{
timeout=0;
while((IO==0)&&((timeout++)<500));
timeout=0;
while((IO==1)&&((timeout++)<500));
RH_H=ReadByte();
RH_L=ReadByte();
T_H=ReadByte();
T_L=ReadByte();
Cheakdata=ReadByte();
if(Cheakdata==RH_H+RH_L+T_H+T_L)
{return 1;}//成功
else
{return 0;}//失败
}
else
return 0;//失败
}
/******1602写地址函数*********/
void LCD1602_WRITE_ADRESS(uchar x,uchar y)
{
if(y==0)
LCD1602_WRITE_COM_BUSY(0x80+x);
else
LCD1602_WRITE_COM_BUSY(0x80+0x40+x); }
/*********1602显示*************/
void LCD1602_DISP(uchar x,uchar y,uchar buf)
{
LCD1602_WRITE_ADRESS(x,y);
LCD1602_WRITE_DATA_BUSY(buf);//显示数字}
/*****主函数*****/
void main(void)
{
LCD1602_init();
while(1)
{
if(ReadRH()==1)
{
if(RH_H>99) RH_H=0;
if(T_H>50) T_H=0;
LCD1602_DISP(0,0,'R');
LCD1602_DISP(1,0,'H');
LCD1602_DISP(2,0,':');
LCD1602_DISP(3,0,RH_H/10+'0');
LCD1602_DISP(4,0,RH_H%10+'0');
LCD1602_DISP(5,0,'%');
LCD1602_DISP(0,1,'T');
LCD1602_DISP(1,1,':');
LCD1602_DISP(2,1,T_H/10+'0');
LCD1602_DISP(3,1,T_H%10+'0');
LCD1602_DISP(4,1,0xdf);
LCD1602_DISP(5,1,'C');
}
}
}。