-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_example.c
50 lines (43 loc) · 1.5 KB
/
main_example.c
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
#include <stdio.h>
#include <fbm340.h>
/* Private variable */
int32_t real_p, real_t, altitude;
//float real_p, real_t;
volatile uint32_t TMR0_Ticks = 0; //one tick per millisecond(ms)
volatile uint32_t fbm340_update_rdy = 0;
/**
* @brief A timer generate an interrupt every millisecond
*/
void TMR0_IRQHandler(void)
{
if (TIMER_GetIntFlag(TIMER0) == 1)
{
/* Clear Timer0 time-out interrupt flag */
TIMER_ClearIntFlag(TIMER0);
TMR0_Ticks++;
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Main Function */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
/* fbm340 initiation */
fbm340_init();
while (1)
{
/* Updating fbm340 data */
fbm340_update_data();
if (fbm340_update_rdy) {
/* If you need the pressure value read is in uint of Pa, use this function. */
// real_p = fbm340_read_pressure();
/* If you need the temperature value read is in unit of degree Celsius, use this function. */
// real_t = fbm340_read_temperature();
/* This function read pressure and temperature values. Pressure uint:Pa, Temperature unit:0.01 degree Celsius */
fbm340_read_data(&real_p, &real_t);
/* This function converts pressure value to altitude in unit of millimeter(mm). */
altitude = fbm340_get_altitude(real_p);
fbm340_update_rdy = 0;
}
}
}