/* Copyleft (!C) 2003 C. Manders, (http://www.gnu.org/copyleft/gpl.html); */ #include #include #define F_CPU 1000000UL #include int main (void) { volatile uint8_t i,j; /* set up the PWM on timer 0 (8-bit)*/ TCCR0A=0xf3; TCCR0B=0x1; /* set up the PWM on timer 1 * which is 8-10 bits, but will use as * 8 bit. */ TCCR1A=0xf1; TCCR1B=0x9; /* set up the PWM on timer 2 (8-bit) */ TCCR2A=0xf3; TCCR2B=0x1; /* make sure the data direction registers are * set as output. */ DDRD=0xff; DDRB=0xff; /* turn off unneccessary LEDs */ PORTD=0; PORTB=0; /* loop infinitely */ while(1){ /* change pulse widths on timer 1 */ for ( j =0 ;j <255 ;j=j+1){ /* delay a bit */ _delay_us(768.0); _delay_us(768.0); _delay_us(768.0); /* change the pulse widths */ OCR1A = j; OCR1B = 255-j; } /* change pulse widths on timer 2 */ for ( j =0 ;j <255 ;j=j+1){ _delay_us(768.0); _delay_us(768.0); _delay_us(768.0); OCR2A = j; OCR2B = 255-j; } /* change the pulse widths on timer 0 */ for ( j =0 ;j <255 ;j=j+1){ _delay_us(768.0); _delay_us(768.0); _delay_us(768.0); OCR0A = j; OCR0B = 255-j; } } }