/
main.c
84 lines (67 loc) · 1.32 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include "config.h"
#include "twi_master/twi_master.h"
#include "can/spi.h"
#include "can/can.h"
#include "can_handler.h"
#include "netvar/netvar.h"
#include "io.h"
#include "animationen.h"
#include "ds1631.h"
#include "motion.h"
#include "temp_read.h"
static volatile uint8_t tickscounter;
ISR(TIMER0_OVF_vect)
{
tickscounter++;
}
static void init(void)
{
ACSR = _BV(ACD); // Disable Analog Comparator (power save)
//motion_init();
TCCR0 = _BV(CS02) | _BV(CS00); // clk / 256
TIMSK = _BV(TOIE0);
io_init();
// init twi
if (!TWIM_Init())
{
while (1);
}
ds1631_init(I2C_ADRESSE_DS1631); // Init twi temperature sensor
spi_init(); // initialize spi port
can_read_addr();
can_init(); // initialize can communication
sei(); // turn on interrupts
wdt_enable(WDTO_250MS);
#ifndef NO_NETVAR
switch_netvars_init();
lamp_out_init();
#endif
}
int main(void)
{
uint16_t send_temp_counter = 0;
init(); // system initialization
while (1)
{
can_handler();
do_ani();
if (tickscounter > 10)
{
tickscounter = 0;
switch_handler();
#ifndef NO_NETVAR
netvar_handle_events();
#endif
send_temp_counter++;
if (send_temp_counter > 1000) {
temp_sensor_read();
send_temp_counter = 0;
}
//motion_tick();
}
wdt_reset();
}
}