2 #include <avr/eeprom.h>
3 #include <util/delay.h>
5 #include <avr/interrupt.h>
8 volatile uint16_t adcval;
19 unsigned char debug EEMEM = 1;
24 ADCSRA &= ~_BV(ADIE); /* disable ADC interrupt */
34 ISR(TIMER0_COMPA_vect)
40 unsigned char intensity :2;
41 unsigned char length :6;
42 } pattern[] = { {1, 2}, {0, 4}, { 1, 2 }, {0, 15}, {0, 0} };
44 static void inline init_pwm()
46 TCCR1C = _BV(COM1D0) | _BV(COM1D1) | _BV(PWM1D);
47 TCCR1A = _BV(COM1A0) | _BV(COM1A1) | _BV(COM1B0) | _BV(COM1B1) | _BV(PWM1A) | _BV(PWM1B);
48 TCCR1B = 0x80| _BV(CS13) | _BV(CS11);
51 OCR1D = OCR1B = OCR1A = 0x40;
53 DDRB |= _BV( PB5 ) | _BV( PB1 ) | _BV( PB3 );
54 PORTB &= ~(_BV( PB5 ) | _BV( PB1 ) | _BV( PB3 ));
58 static void inline init_adc()
60 ADCSRA = _BV(ADEN) | _BV(ADATE) | _BV(ADPS1) | _BV(ADPS0);
61 ADMUX = _BV(REFS1) | _BV(MUX0);
62 // ADCSRB = _BV(REFS2);
63 DIDR0 = _BV(ADC1D) | _BV(AREFD);
66 static void inline init_tmr()
69 TCCR0B = _BV(CS02); // | _BV(CS00);
85 pcount = pattern[ppos].length;
86 if (pattern[ppos].intensity) {
91 unsigned char pwmhi, pwmlo;
93 if (intflags.adc_int) {
101 pwmlo = adcval & 0xFF;
115 if (intflags.pwm_int) {
116 intflags.pwm_int = 0;
117 ADCSRA |= _BV(ADIE) | _BV(ADSC);
120 if (intflags.tmr_int) {
121 intflags.tmr_int = 0;
124 pcount = pattern[ppos].length;
127 pcount = pattern[ppos].length;
129 if (pattern[ppos].intensity) {
144 eeprom_write_byte(&debug, 2);
153 PORTA &=~ _BV( PA0 );