开发板:stc89c52rc
显示:lcd1602
温湿度模块:DHT11
通信模块:HC-08蓝牙
将DHT11温湿度读取数据,通过HC-08蓝牙发送至手机,且在lcd1602显示
由于代码没经过分文件封装,所以代码臭且厂,这里只展现部分,其他的函数在前面的文章可以一一找到哦
Build_Data()函数里加上0x30 是为了让数字ascll码变成字符型
举个栗子:数字4 即0100 +0x30 (00110000)= 0011 0100 查看下发ascll表
void Build_Datas()
{
huma[0] = 'H';
huma[1] = datas[0]/10 + 0x30;
huma[2] = datas[0]%10 + 0x30;
huma[3] = '.';
huma[4] = datas[1]/10 + 0x30;
huma[5] = datas[1]%10 + 0x30;
huma[6] = '%';
huma[7] = '\0';
temp[0] = 'T';
temp[1] = datas[2]/10 + 0x30;
temp[2] = datas[2]%10 + 0x30;
temp[3] = '.';
temp[4] = datas[3]/10 + 0x30;
temp[5] = datas[3]%10 + 0x30;
temp[6] = 'C';
temp[7] = '\0';
}
void main()
{
Delay1000ms();
UartInit();
LCD1602_INIT();
Delay1000ms();
Delay1000ms();
ledOne = 0;
while(1){
Delay1000ms();
Read_Data_From_DHT();
if(datas[2] > 24){
fengshan = 0;
}
Build_Datas();
sendString(huma);
sendString("\r\n");
sendString(temp);
sendString("\r\n");
LCD1602_showLine(1,2,huma);
LCD1602_showLine(2,2,temp);
}
}