原创 C51 温湿度传感器DHT11驱动 LCD1602显示程序 硬件通过 含电路图和实际测试效果图
unsigned char str[15]; //不能定义为char* str,数组长度一定要大于浮点数的总位数
sprintf(str,"%.1f",f); //1表示小数位数 小数太多 自动四舍五入 LCD_write_str( x, y, str);
return 0;
}
主函数文件
#include <reg52.h>
#include <intrins.h>
#include <Lcd_1602.h>
#include <Time_Delay.h>
#include"DHT11.h"
extern float F16T,F16RH; //全局变量声明
void main ()
{
Init_Lcd();
LCD_write_str(0,1,"abc"); //液晶预显示测试
LCD_value(0,0,34.345);
Delay_ms(2000);
Init_Lcd();
while(1)
{
getDHT11();
LCD_write_str(0,0,"T=");
LCD_value(3,0,F16T); LCD_write_str(8,0,"\"C");
LCD_write_str(0,1,"RH=");
LCD_value(4,1,F16RH); LCD_write_str(9,1,"%");
Delay_ms(500);
}
}
延时函数文件
//以下为延时函数 this is fit to old C51 12MHz,
void Delay_ms(unsigned int n)//n毫秒延时 //字符" 应用转义格式 12 devide freqency