source: avrstuff/blinkled/main.c@ 6f22754

main
Last change on this file since 6f22754 was 6f22754, checked in by Adrien Destugues <pulkomandy@…>, 5 years ago

blinkled: cleanup a bit

I get bored of editing too much things in there after a while...

  • Property mode set to 100644
File size: 915 bytes
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#if defined(__AVR_ATmega8__)
11#define _TCCA TCCR1A
12#define _TCCB TCCR1B
13#define _TIFR TIFR
14#define _TOV TOV1
15#elif defined(__AVR_ATmega48P__)
16#define _TCCA TCCR0A
17#define _TCCB TCCR0B
18#define _TIFR TIFR0
19#define _TOV TOV0
20#else
21#error Unknown device! Add it to main.c and set the timer properly
22#endif
23
24int main() {
25 wdt_enable(WDTO_2S);
26 // configure timer 0 for a rate of 16M/(256 * 256) = ~244Hz
27 _TCCA = 0; // timer 0 prescaler: 256
28 _TCCB = 4;
29
30 //debug LED - output
31 DDRD |= (1<<PD6);
32
33 PORTD = 0;
34
35 while(1) {
36 wdt_reset();
37
38
39 // check timer if we need periodic reports
40 if (_TIFR & (1 << _TOV)) {
41 _TIFR = (1 << _TOV); // reset flag
42 PORTD ^= (1<<PD6);
43 }
44 }
45
46 return 0;
47}
48
Note: See TracBrowser for help on using the repository browser.