blob: b9bb5ce08bffdf1e61d9c0ce4a683f8af1ea64a5 (
plain)
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
|
#include "common.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "i2c.h"
#include "uart.h"
#include "timer.h"
#include "gyro.h"
#include "accel.h"
#include "pwm.h"
#include "ui.h"
static void cpuInit () {
/* enter change prescaler mode */
CLKPR = (1 << CLKPCE);
/* write new prescaler */
#if F_CPU == 1000000
CLKPR = 0b00000011;
#elif F_CPU == 4000000
CLKPR = 0b00000001;
#elif F_CPU == 8000000
CLKPR = 0b00000000;
#else
#error "cpu speed not supported"
#endif
}
int main () {
cpuInit ();
twInit ();
uartInit ();
gyroInit ();
accelInit ();
pwmInit ();
pwmStart ();
set_sleep_mode (SLEEP_MODE_IDLE);
puts ("initialization done");
/* global interrupt enable */
sei ();
gyroStart ();
accelStart ();
uiLoop ();
timerStop ();
pwmStop ();
puts ("stopped");
/* global interrupt disable */
cli ();
while (1);
}
|