]> www.fi.muni.cz Git - bike-lights.git/blob - lights.c
PWM experiments
[bike-lights.git] / lights.c
1 #include <avr/io.h>
2 #include <avr/eeprom.h>
3 #include <util/delay.h>
4
5 char dbg[5] __attribute__((section(".eeprom")));
6
7 int main(void)
8 {
9         TCCR1C = _BV(COM1D0) | _BV(COM1D1) | _BV(PWM1D);
10         TCCR1A = _BV(PWM1A) | _BV(PWM1B);
11         TCCR1B = 0x80 | _BV(CS13) | _BV(CS12);
12         OCR1C = 0xFF;
13         OCR1D = 0x20;
14         TCNT1 = 3;
15         DDRB |= _BV( PB5 );
16         PORTB &= ~_BV( PB5 );
17
18         _delay_ms(1000);
19         eeprom_write_byte(&dbg[0], TCNT1);
20         eeprom_write_byte(&dbg[1], OCR1C);
21         eeprom_write_byte(&dbg[2], OCR1D);
22         eeprom_write_byte(&dbg[3], TIFR);
23         eeprom_write_byte(&dbg[4], TCCR1B);
24     DDRA |= _BV( PA0 );
25     while( 1 ) { 
26         PORTA |=  _BV( PA0 );
27         _delay_ms(2000);
28         PORTA &=~ _BV( PA0 );
29         _delay_ms(2000);
30     }
31 }