#include /* pwm example LEDs attached to PORTH, pins 3, 4, 5 (timer 4, channels A, B, C, respectively). */ int main(void) { // Configure appropriate pins as outputs, including the LED on the // Arduinio board itself DDRB = 0x80; DDRH = 0x38; // Flash all the LEDs to show that they are connected and that the program // is booting. PORTH ^= 0x38; PORTB = PORTB ^= 0x80; delay_ms(200); PORTH ^= 0x38; PORTB = PORTB ^= 0x80; delay_ms(200); PORTH ^= 0x38; PORTB = PORTB ^= 0x80; delay_ms(200); PORTH ^= 0x38; PORTB = PORTB ^= 0x80; delay_ms(200); // Configure timer 4 for 10-bit PWM timer4_config(TIMER4_PRE_8); timer4_output_compare_config(TIMER4_OUTPUT_COMPARE_CONFIG_PWM_F_10); // Configure each channel for output-compare mode timer4_compare_output_A_mode_set(TIMER16B_COMPARE_OUTPUT_MODE_CLEAR); timer4_compare_output_B_mode_set(TIMER16B_COMPARE_OUTPUT_MODE_CLEAR); timer4_compare_output_C_mode_set(TIMER16B_COMPARE_OUTPUT_MODE_CLEAR); // Set initial duty cycle on each to zero timer4_output_compare_A_set(0); timer4_output_compare_B_set(0); timer4_output_compare_C_set(0); int i; // Loop forever while(1) { // Slowly increase the duty cycle on channel A for(i=0; i < 1024; ++i) { timer4_output_compare_A_set(i); delay_ms(1); }; // Slowly bring the duty cycle back to zero for(i=1023; i > 0; --i) { timer4_output_compare_A_set(i); delay_ms(1); }; // Slowly increase the duty cycle on channel B for(i=0; i < 1024; ++i) { timer4_output_compare_B_set(i); delay_ms(1); }; // Slowly bring the duty cycle back to zero for(i=1023; i > 0; --i) { timer4_output_compare_B_set(i); delay_ms(1); }; // Slowly increase the duty cycle on channel C for(i=0; i < 1024; ++i) { timer4_output_compare_C_set(i); delay_ms(1); }; // Slowly bring the duty cycle back to zero for(i=1023; i > 0; --i) { timer4_output_compare_C_set(i); delay_ms(1); }; } return(0); }