pic_therm

PIC16F877A and BME280 thermometer
git clone git://git.margiolis.net/pic_therm.git
Log | Files | Refs | README | LICENSE

commit 9a2b04f633fa892c9c16d88d551b160f42a7dbfc
parent cc855f90511faadef1a74bb1077d745703b0c404
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sat, 26 Mar 2022 16:55:05 +0200

add hang macro

Diffstat:
Msrc/main.c | 17+++++++++++------
Msrc/tmr0.c | 4++--
2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -31,6 +31,11 @@ static char buf[BUFSIZ+1] = {0}; /* Generic buffer */ lcd_puts(itoa(&buf[sizeof(buf)-1], v)); \ } while (0) +#define HANG(str) do { \ + lcd_puts(str); \ + for (;;); \ +} while (0) + static void ctx_main(void) { @@ -107,14 +112,14 @@ void main(void) { tmr0_init(); - tmr0_set_event(&led_blink, 1000); - tmr0_set_event(&button_debounce, 1); + if (tmr0_set_event(&led_blink, 1000) < 0) + HANG("led_blink event failed"); + if (tmr0_set_event(&button_debounce, 1) < 0) + HANG("button_debounce event failed"); lcd_init(); i2c_init(I2C_MASTER, I2C_SLEW_OFF, I2C_CLK_1MHZ); - if (bme280_init() < 0) { - lcd_puts("BME280 error"); - for (;;); /* Hang */ - } + if (bme280_init() < 0) + HANG("BME280 error"); BTN_TRIS = INPUT; LED_PORT = 1; /* LED on */ diff --git a/src/tmr0.c b/src/tmr0.c @@ -70,7 +70,7 @@ tmr0_set_event(ev_handler handler, uint16_t rate) r->handler = handler; r->rate = rate; r->cnt = 0; - return (1); + return (0); } - return (0); + return (-1); }