-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclock.c
48 lines (40 loc) · 1.26 KB
/
clock.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
#include <xc.h>
#include <stdint.h>
#include "clock.h"
#include "elm327slcan.h"
extern uint8_t state;
static volatile uint16_t clock_msticker = 0, tmp;
static volatile uint8_t led_ticker = 0;
void __interrupt(low_priority) myLoIsr(void) {
if (CCP1IF && CCP1IE) {
CCP1IF = 0;
// 1 ms
if (++clock_msticker == 60000) clock_msticker = 0;
}
if (CCP2IF && CCP2IE) {
CCP2IF = 0;
// 100 ms
led_ticker = (led_ticker + 1) & 31;
stateLED((led_ticker == 0) || (state != STATE_CONFIG));
if (OERR()) { // steady orange light
errorLED(1); // device must be repowered
} else if (RXBnOVFL()) { // one orange light flash
errorLED((led_ticker & 2) && (led_ticker < 4));
} else if (RX_OVFL()) { // two orange light flash
errorLED((led_ticker & 2) && (led_ticker < 8));
} else if (TX_OVFL()) { // three orange light flash
errorLED((led_ticker & 2) && (led_ticker < 12));
}
}
}
uint16_t clock_getMS(void) {
CCP1IE = 0;
tmp = clock_msticker;
CCP1IE = 1;
return tmp;
}
void clock_reset(void) {
CCP1IE = 0;
clock_msticker = 0;
CCP1IE = 1;
}