main
Line | |
---|
1 | #include <avr/io.h>
|
---|
2 | #include <avr/interrupt.h>
|
---|
3 | #include <avr/wdt.h>
|
---|
4 | #include <avr/pgmspace.h>
|
---|
5 | #include <util/delay.h>
|
---|
6 |
|
---|
7 | #include <string.h>
|
---|
8 | #include <stdbool.h>
|
---|
9 |
|
---|
10 | // muSerial: ATTiny2313 - LED = PD6
|
---|
11 | // K4KUSB: ATTiny2313 - LED = PB2
|
---|
12 | #define DDRLED DDRB
|
---|
13 | #define PORTLED PORTB
|
---|
14 | #define LEDBIT 1 << PB2
|
---|
15 |
|
---|
16 | #define BAUD 9600 // Safe value even for low clocks. (used by setbaud.h)
|
---|
17 |
|
---|
18 | int main() {
|
---|
19 | wdt_enable(WDTO_2S);
|
---|
20 | // configure timer 0 for a rate of FCPU/(256 * 256)
|
---|
21 | TCCR0A = 0; // timer 0 prescaler: 256
|
---|
22 | TCCR0B = 4;
|
---|
23 |
|
---|
24 | //debug LED - output
|
---|
25 | DDRLED |= 255;
|
---|
26 |
|
---|
27 | PORTLED = 0;
|
---|
28 |
|
---|
29 | // Serial baudrate - use avrlibc magic to compute the baudrate register
|
---|
30 | // values.
|
---|
31 | #include <util/setbaud.h>
|
---|
32 | UBRRH = UBRRH_VALUE;
|
---|
33 | UBRRL = UBRRL_VALUE;
|
---|
34 | #if USE_2X
|
---|
35 | UCSRA |= (1 << U2X);
|
---|
36 | #else
|
---|
37 | UCSRA &= ~(1 << U2X);
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | // Enable the serial port.
|
---|
41 | UCSRB = (1<<RXEN) |(1<<TXEN);
|
---|
42 | UCSRC = (1 << UCSZ1) | (1 << UCSZ0);
|
---|
43 |
|
---|
44 | // Let's rock!
|
---|
45 | uint8_t counter = 0;
|
---|
46 | for(;;) {
|
---|
47 | wdt_reset();
|
---|
48 |
|
---|
49 | // Wait for timer overflow...
|
---|
50 | if (TIFR & (1 << TOV0)) {
|
---|
51 | TIFR = (1 << TOV0); // reset flag
|
---|
52 | counter++;
|
---|
53 | }
|
---|
54 |
|
---|
55 | if (counter == 0)
|
---|
56 | {
|
---|
57 | PORTLED ^= LEDBIT; // Toggle the LED
|
---|
58 | UDR = 'H'; // Send a byte to the UART
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | return 0;
|
---|
63 | }
|
---|
64 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.