部分代碼在這
- /************************************************************************************/
- /*通過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]);
- }
- }
- }
復制代碼 |