annotate main.c @ 3:888be1b234b6

Add FatFS
author Matt Johnston <matt@ucc.asn.au>
date Tue, 08 May 2012 22:51:38 +0800
parents ab0e30c4b344
children 54d369e3d689
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /* Name: main.c
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Author: <insert your name here>
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 * Copyright: <insert your copyright message here>
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * License: <insert your license reference here>
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 */
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 #include <stdio.h>
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 #include <string.h>
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
9 #include <avr/io.h>
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
10 #include <avr/interrupt.h>
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
11 #include <avr/sleep.h>
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 #include <util/crc16.h>
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13
3
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents: 2
diff changeset
14 #include "integer.h"
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents: 2
diff changeset
15
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 // configuration params
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 // - measurement interval
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 // - transmit interval
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 // - bluetooth params
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 // - number of sensors (and range?)
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
22 // 1 second. we have 1024 prescaler, 32768 crystal.
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
23 #define SLEEP_COMPARE 32
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
24 #define SECONDS_WAKE 60
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
25
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
26 #define BAUD 9600
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
27 #define UBRR ((F_CPU)/16/(BAUD)-1)
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
28
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 static int uart_putchar(char c, FILE *stream);
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 _FDEV_SETUP_WRITE);
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 static uint8_t n_measurements;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 static uint8_t measurements[500];
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
36 static uint8_t need_measurement;
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
37
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 static uint8_t readpos;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 static char readbuf[30];
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
41 static uint8_t sec_count;
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
42
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 static void
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
44 uart_init(unsigned int ubrr)
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 // baud rate
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
47 UBRR0H = (unsigned char)(ubrr >> 8);
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
48 UBRR0L = (unsigned char)ubrr;
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
49 UCSR0B = (1<<RXEN0)|(1<<TXEN0);
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 //8N1
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
51 UCSR0C = (1<<UMSEL00)|(3<<UCSZ00);
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 static int
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 uart_putchar(char c, FILE *stream)
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 // XXX should sleep in the loop for power.
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
58 loop_until_bit_is_set(UCSR0A, UDRE0);
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
59 UDR0 = c;
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 return 0;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 static void
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 cmd_fetch()
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 uint16_t crc = 0;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 int i;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 printf("%d measurements\n", n_measurements);
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 for (i = 0; i < n_measurements; i++)
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 printf("%3d : %d\n", i, measurements[i]);
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
72 crc = _crc_ccitt_update(crc, measurements[i]);
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 }
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
74 printf("CRC : %d\n", crc);
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 static void
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 cmd_clear()
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 static void
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 cmd_btoff()
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 static void
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 read_handler()
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 if (strcmp(readbuf, "fetch") == 0)
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 cmd_fetch();
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 else if (strcmp(readbuf, "clear") == 0)
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 cmd_clear();
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 else if (strcmp(readbuf, "btoff") == 0)
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 cmd_btoff();
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 else
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 printf("Bad command\n");
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
108 ISR(USART_RX_vect)
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 {
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
110 char c = UDR0;
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 if (c == '\n')
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 readbuf[readpos] = '\0';
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 read_handler();
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 readpos = 0;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 else
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 readbuf[readpos] = c;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 readpos++;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 if (readpos >= sizeof(readbuf))
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 {
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 readpos = 0;
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
128 ISR(TIMER2_COMPA_vect)
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
129 {
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
130 sec_count ++;
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
131 if (sec_count == SECONDS_WAKE)
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
132 {
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
133 sec_count = 0;
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
134 need_measurement = 1;
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
135 }
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
136 }
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
137
3
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents: 2
diff changeset
138 DWORD get_fattime (void)
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents: 2
diff changeset
139 {
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents: 2
diff changeset
140 return 0;
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents: 2
diff changeset
141 }
888be1b234b6 Add FatFS
Matt Johnston <matt@ucc.asn.au>
parents: 2
diff changeset
142
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
143 static void
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
144 deep_sleep()
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
145 {
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
146 // p119 of manual
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
147 OCR2A = SLEEP_COMPARE;
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
148 loop_until_bit_is_clear(ASSR, OCR2AUB);
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
149
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
150 set_sleep_mode(SLEEP_MODE_PWR_SAVE);
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
151 sleep_mode();
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
152 }
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
153
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
154 static void
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
155 do_measurement()
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
156 {
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
157 need_measurement = 0;
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
158 }
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
159
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 int main(void)
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 {
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
162 uart_init(UBRR);
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 fprintf(&mystdout, "hello %d\n", 12);
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
166 // set up counter2.
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
167 // COM21 COM20 Set OC2 on Compare Match (p116)
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
168 // WGM21 Clear counter on compare
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
169 // CS22 CS21 CS20 clk/1024
2
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
170 TCCR2A = _BV(COM2A1) | _BV(COM2A0) | _BV(WGM21);
ab0e30c4b344 switch to atmega328
Matt Johnston <matt@ucc.asn.au>
parents: 1
diff changeset
171 TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20);
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
172 // set async mode
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
173 ASSR |= _BV(AS2);
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 for(;;){
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 /* insert your main loop code here */
1
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
177 if (need_measurement)
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
178 {
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
179 do_measurement();
1d1897d66b03 Some counter2 bits
Matt Johnston <matt@ucc.asn.au>
parents: 0
diff changeset
180 }
0
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 }
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 return 0; /* never reached */
c8b14b2950b9 Some basic bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 }