riscv-mcu / GD32VF103_Firmware_Library

Original GD32VF103 Firmware Library
129 stars 37 forks source link

Alarmsystem for temp, GD32VF103 #10

Open Halimack opened 3 years ago

Halimack commented 3 years ago

I want my code to trigger an alarm when the temp is to high or to low, and after 1 minut the alarm should accelerate in speed until someone restarts it. Does anyone know how to change (t5expq()) so that it turns of and on at different speeds to make this alarming sound? Fwi im a beginner.

include "gd32vf103.h"

include "drivers.h"

include "eclicw.h"

include "lcd.h"

include "ds18b20.h"

void ds18B20callBack(unsigned int temp){ LCD_ShowNum(8, 10, temp>>4, 2, WHITE); LCD_ShowNum(8, 30, temp%16, 2, WHITE); }

int main(void){ int ms=0, s=0, key, pKey=-1, c=0, idle=0; int lookUpTbl[16]={1,4,7,14,2,5,8,0,3,6,9,15,10,11,12,13};

t5omsi();                               // Initialize timer5 1kHz
colinit();                              // Initialize column toolbox
l88init();                              // Initialize 8*8 led toolbox
keyinit();                              // Initialize keyboard toolbox
Lcd_SetType(LCD_INVERTED);              // LCD_INVERTED/LCD_NORMAL!
Lcd_Init();
LCD_Clear(RED);
ds18B20init(&ds18B20callBack);          // Initialize ds18B20 temp sensor

eclic_global_interrupt_enable();        // !!!!! Enable Interrupt !!!!!

while (1) {
    idle++;                             // Manage Async events
    LCD_WR_Queue();                     // Manage LCD com queue!

    if (t5expq()) {                     // Manage periodic tasks
        l88row(colset());               // ...8*8LED and Keyboard
        ms++;                           // ...One second heart beat
        if (ms==1000){
          ms=0;
          l88mem(0,s++);
        }
        if ((key=keyscan())>=0) {       // ...Any key pressed?
          if (pKey==key) c++; else {c=0; pKey=key;}
          l88mem(1,lookUpTbl[key]+(c<<4));
        }
        l88mem(2,idle>>8);              // ...Performance monitor
        l88mem(3,idle); idle=0;
    }
}

}