Pārlūkot izejas kodu

Added display HTU data.

Vladimir N. Shilov 1 gadu atpakaļ
vecāks
revīzija
f6d4ea8118
2 mainītis faili ar 30 papildinājumiem un 1 dzēšanām
  1. 1 1
      lib/led.c
  2. 29 0
      src/main.c

+ 1 - 1
lib/led.c

@@ -10,7 +10,7 @@
 #define GPIO_TOGGLE(a,b)  a->ODR ^= b
 
 uint8_t LedDigits[8] = {1, 2, 3, 4, 5, 6, 7, 8}; // digits to dsplay
-uint8_t LedPoint[8] = {0, 0, 0, 1, 0, 0, 0, 1}; // dots for digits
+uint8_t LedPoint[8] = {0, 0, 1, 0, 0, 0, 1, 0}; // dots for digits
 
 static const uint16_t led_num[8] = {0x10, 0x20, 0x80, 0x40, 0x01, 0x02, 0x08, 0x04};
 

+ 29 - 0
src/main.c

@@ -38,6 +38,8 @@ static uint16_t Humidity;
 
 /* Private function prototypes -----------------------------------------------*/
 static void boardInit(void);
+static void showT(void);
+static void showH(void);
 
 void main(void)
 {
@@ -50,14 +52,41 @@ void main(void)
   /* Infinite loop */
   while (1) {
     htu_GetTemperature(&Temperature);
+    showT();
     Delay(410);
     htu_GetHumidity(&Humidity);
+    showH();
     Delay(440);
   }
 
 }
 
 /* Private functions ---------------------------------------------------------*/
+static void showT(void) {
+  int16_t t;
+  uint8_t a;
+  if (Temperature > 0) {
+    LedDigits[0] = LED_OUT_PL;
+    t = (Temperature + 5) / 10;
+  } else {
+    LedDigits[0] = LED_OUT_MM;
+    t = ((Temperature + 5) / 10) * -1;
+  }
+  LedDigits[1] = t / 100;
+  a = t % 100;
+  LedDigits[2] = a / 10;
+  LedDigits[3] = a % 10;
+}
+
+static void showH(void) {
+ uint8_t a;
+ LedDigits[4] = LED_OUT_H;
+ LedDigits[5] = Humidity / 100;
+ a = Humidity % 100;
+ LedDigits[6] = a / 10;
+ LedDigits[7] = a % 10;
+}
+
 static void boardInit(void) {
   /* Насколько я понял, для частот выше 16МГц нужно вводить задержку при работе с FLASH:
     - Before using the HSE clock make sure that the "Flash_Wait_States" is set to 1.