|
@@ -10,6 +10,16 @@
|
10
|
10
|
|
11
|
11
|
#include "twi.h"
|
12
|
12
|
|
|
13
|
+#define ICP_PRE_SCALE (4)
|
|
14
|
+#if defined(__AVR_ATmega2560__)
|
|
15
|
+#define SERIAL_RX_ISR USART0_RX_vect
|
|
16
|
+#elif defined(__AVR_ATmega328__)
|
|
17
|
+#define SERIAL_RX_ISR USART_RX_vect
|
|
18
|
+#else
|
|
19
|
+#error Unknown target processor
|
|
20
|
+#endif
|
|
21
|
+
|
|
22
|
+
|
13
|
23
|
//------------------------------------------------------------------------------
|
14
|
24
|
|
15
|
25
|
#define SER_BUF_N (16) // size of receive buffer
|
|
@@ -102,7 +112,7 @@ void i2c_init()
|
102
|
112
|
twi_init();
|
103
|
113
|
}
|
104
|
114
|
|
105
|
|
-ISR(USART_RX_vect)
|
|
115
|
+ISR(SERIAL_RX_ISR)
|
106
|
116
|
{
|
107
|
117
|
// receive the incoming byte
|
108
|
118
|
ser_buf[ ser_buf_i_idx ] = uart_getchar();
|
|
@@ -112,25 +122,6 @@ ISR(USART_RX_vect)
|
112
|
122
|
}
|
113
|
123
|
|
114
|
124
|
|
115
|
|
-//--------------------------------------------------------------------------------------------------
|
116
|
|
-static volatile int timerFl = 0;
|
117
|
|
-
|
118
|
|
-
|
119
|
|
-ISR(TIMER1_COMPA_vect)
|
120
|
|
-{
|
121
|
|
- timerFl = 1;
|
122
|
|
-}
|
123
|
|
-
|
124
|
|
-void timer_init(void)
|
125
|
|
-{
|
126
|
|
- TCCR1A = 0; // set timer control registers to default
|
127
|
|
- TCCR1B = 0; //
|
128
|
|
- OCR1A = 15624; // 1 Hz = 16Mghz / (1024 * 15624)
|
129
|
|
- TCCR1B |= (1 << WGM12); // CTC mode on
|
130
|
|
- TCCR1B |= (1 << CS10); // Set CS10 and CS12 bits for 1024 prescaler:
|
131
|
|
- TCCR1B |= (1 << CS12); //
|
132
|
|
- TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
|
133
|
|
-}
|
134
|
125
|
|
135
|
126
|
//--------------------------------------------------------------------------------------------------
|
136
|
127
|
|
|
@@ -156,7 +147,6 @@ int main (void)
|
156
|
147
|
|
157
|
148
|
DDRB |= _BV(DDB5); // set led pin for output
|
158
|
149
|
|
159
|
|
- timer_init(); // setup the timer
|
160
|
150
|
uart_init(); // setup UART data format and baud rate
|
161
|
151
|
i2c_init();
|
162
|
152
|
sei(); // re-enable interrupts
|
|
@@ -165,12 +155,6 @@ int main (void)
|
165
|
155
|
|
166
|
156
|
for(;;)
|
167
|
157
|
{
|
168
|
|
- if( timerFl )
|
169
|
|
- {
|
170
|
|
- //PORTB ^= _BV(PORTB5); // toggle LED
|
171
|
|
-
|
172
|
|
- timerFl = 0;
|
173
|
|
- }
|
174
|
158
|
|
175
|
159
|
// if there are bytes waiting in the serial buffer
|
176
|
160
|
if( ser_buf_o_idx != ser_buf_i_idx )
|