部分代码在这
- /************************************************************************************/
- /*通过DS18B20测试当前环境温度, 通过DHT11测试湿度,并通过12864串行显示当前温度值**********/
- /*目前显示范围: 温度-55~ +125摄氏度,湿度20%-95% 湿度测量误差:+-5%******************/
- /************************************************************************************/
- #include "reg52.H"
- #include "intrins.h"
- #include "math.H" //要用到取绝对值函数abs()
- #include "DELAY.H"
- #include "DS18B20.H"
- #include "12864.h"
- #include "DHT11.H"
- #define uchar unsigned char
- #define uint unsigned int
- extern uchar U8RH_data_H,U8RH_data_L;
- int tempValue;
- sbit dula = P2^0; //段选信号的锁存器控制
- sbit wela = P2^1; //位选信号的锁存器控制
- sbit cs88 = P2^2; //点阵管的锁存器控制 cs88=0;//关点阵管
- //unsigned char code digit[10]={"0123456789"}; //定义字符数组显示数字
- //uchar code dis1[] = {"温度:"};
- //uchar code dis2[] = {"湿度:"};
- //uchar code dis3[] = {"烟雾浓度:"};
- //uchar number[10]="0123456789";
- //uchar code dis4[] = {" "};
- void cmg88()//关数码管,点阵函数 实际应用去掉
- {
- dula = 1;
- P0 = 0x00;
- dula = 0;
- cs88 = 0x00;
- P0 = 0x00;
- cs88 = 1;
- }
- /*MAIN*/
- void main()
- {
- unsigned char TMPS[] = {0, 0, 0,0x2e, 0,0};
- unsigned char RHS[] = {0,0,0x2e,0,0x25};
- uchar i,RH_H,RH_L; uint tmp;
- cmg88();//关数码管,点阵函数
- delayxms(10); //延时
- wela=0;
- dula=0;
-
- LCD_INIT();
- while(1)
- {
-
- DS_sendChangeCmd();
- tempValue = DS_getTmpValue();
- lcd_setaddr(1,0);
- lcd_putstr("温度:");
- tmp = abs(tempValue);
- TMPS[0] = 0x30+tmp / 10000;
- TMPS[1] = 0x30+tmp % 10000 / 1000;
- TMPS[2] = 0x30+tmp % 1000 / 100;
- TMPS[4] = 0x30+tmp % 100 / 10;
- TMPS[5] = 0x30+tmp % 10;
-
- lcd_setaddr(1,3);
- for(i = 0;i<6;i++)
- {
- lcd_wdata(TMPS[i]);
- }
- lcd_setaddr(1,6);
- lcd_putstr("℃");
- /*以上为DS18B20温度,以下为DHT11湿度*/
- lcd_setaddr(2,0);
- lcd_putstr("湿度:");
- RH();
- RH_H= U8RH_data_H;
- RH_L= U8RH_data_L;
- RHS[0] = 0x30+RH_H/10;
- RHS[1] = 0x30+RH_H%10;
- RHS[3] = 0x30+RH_L/10;
- lcd_setaddr(2,3);
- for(i = 0;i<5;i++)
- {
- lcd_wdata(RHS[i]);
- }
- }
- }
复制代码 |