main
Line | |
---|
1 | #include <usart.h>
|
---|
2 |
|
---|
3 | #include <avr/io.h>
|
---|
4 | #include <avr/interrupt.h>
|
---|
5 | #include <avr/wdt.h>
|
---|
6 | #include <avr/pgmspace.h>
|
---|
7 | #include <util/delay.h>
|
---|
8 |
|
---|
9 | #include <string.h>
|
---|
10 | #include <stdbool.h>
|
---|
11 |
|
---|
12 | // muSerial: ATTiny2313 - LED = PD6
|
---|
13 | // K4KUSB: ATTiny2313 - LED = PB2
|
---|
14 | #define DDRLED DDRB
|
---|
15 | #define PORTLED PORTB
|
---|
16 | #define LEDBIT (1 << PB2)
|
---|
17 |
|
---|
18 | #define BAUD 9600 // Safe value even for low clocks. (used by setbaud.h)
|
---|
19 |
|
---|
20 | int main() {
|
---|
21 | wdt_enable(WDTO_2S);
|
---|
22 | // configure timer 0 for a rate of FCPU/(256 * 256)
|
---|
23 | TCCR0A = 0; // timer 0 prescaler: 256
|
---|
24 | TCCR0B = 4;
|
---|
25 |
|
---|
26 | //debug LED - output
|
---|
27 | DDRLED |= LEDBIT;
|
---|
28 | PORTLED &= ~LEDBIT;
|
---|
29 |
|
---|
30 | USARTInit();
|
---|
31 |
|
---|
32 | // Let's rock!
|
---|
33 | uint8_t counter = 0;
|
---|
34 | for(;;) {
|
---|
35 | wdt_reset();
|
---|
36 |
|
---|
37 | // Wait for timer overflow...
|
---|
38 | if (TIFR & (1 << TOV0)) {
|
---|
39 | TIFR = (1 << TOV0); // reset flag
|
---|
40 | counter++;
|
---|
41 |
|
---|
42 | if (counter == 0)
|
---|
43 | {
|
---|
44 | PORTLED ^= LEDBIT; // Toggle the LED
|
---|
45 | USARTWriteChar('H'); // Send a byte to the UART
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | return 0;
|
---|
51 | }
|
---|
52 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.