1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| #include "stm32f10x.h" #include "OLED.h" #include "AM2302.h" #include "HC_SR04.h" #include "Key.h"
uint32_t Distance; uint16_t Humidity, Temperature; float sound_speed_M_S; uint8_t KeyNum = 0; int16_t compensation_value = 0;
void System_Init(void); void getData(void); void Data_Show(void);
int main(void) { System_Init(); while (1) { KeyNum = Key_GetNum(); if(KeyNum == 1){ compensation_value += 1; } if(KeyNum == 2){ compensation_value -= 1; } if(KeyNum == 3){ compensation_value = 0; } getData(); Data_Show(); } }
void System_Init(void){ OLED_Init(); OLED_ShowString(2, 4, "Loading..."); Key_Init(); AM2302_Init(); Drv_Hcsr04_Init(); OLED_Clear(); }
void getData(){ AM2302(&Humidity, &Temperature); Distance = getDistance(Humidity, Temperature, &sound_speed_M_S); Distance += compensation_value; sound_speed_M_S *= 1000; }
void Data_Show(){ uint8_t D_Line = 1, V_Line = 2, H_Line = 3, T_Line = 4; int16_t abs_cp_value = (compensation_value < 0) ? -compensation_value : compensation_value; OLED_ShowString(D_Line, 1, "D: "); OLED_ShowNum(D_Line, 4, Distance / 10, 4); OLED_ShowString(D_Line, 8, "."); OLED_ShowNum(D_Line, 9, Distance % 10, 1); OLED_ShowString(D_Line, 11, "CM"); OLED_ShowString(V_Line, 1, "V: "); OLED_ShowNum(V_Line, 4, sound_speed_M_S / 1000, 4); OLED_ShowString(V_Line, 8, "."); OLED_ShowNum(V_Line, 9, (int)sound_speed_M_S % 1000, 3); OLED_ShowString(V_Line, 12, "M/S"); OLED_ShowString(H_Line, 1, "H: "); OLED_ShowNum(H_Line, 4, Humidity / 10, 2); OLED_ShowString(H_Line, 6, "."); OLED_ShowNum(H_Line, 7, Humidity % 10, 1); OLED_ShowString(H_Line, 8, "%"); OLED_ShowString(T_Line, 1, "T: "); OLED_ShowNum(T_Line, 4, Temperature / 10, 2); OLED_ShowString(T_Line, 6, "."); OLED_ShowNum(T_Line, 7, Temperature % 10, 1); OLED_ShowString(T_Line, 8, "C"); OLED_ShowString(T_Line, 10, "B:"); if(compensation_value < 0){ OLED_ShowString(T_Line, 12, "-"); } else{ OLED_ShowString(T_Line, 12, "+"); } OLED_ShowNum(T_Line, 13, abs_cp_value, 2); OLED_ShowString(T_Line, 15, "mm"); }
|