#include //this library has the AVR's functions #include //This library has some utilities, only the delay utility is used here #define output(directions,pin) (directions |= pin) // set port direction for output #define set(port,pin) (port |= pin) // set port pin (setting its value to 1) #define PWM_delay() _delay_us(25) // PWM delay=25 MicroSeconds #define led_port PORTA //the led is connected to a pin from the pins of port A #define led_direction DDRA #define led (1 << PA7) // PA7 is connected to the led int main(void) { // // main // unsigned char count, pwm; //Making two variables will be used in the main loop // set clock divider to /1 // CLKPR = (1 << CLKPCE); // CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); // // initialize LED pins // set(led_port, led); output(led_direction, led); // // main loop // while (1) { // // off -> red // for (count = 0; count < 255; ++count) { clear(led_port,led); for (pwm = count; pwm < 255; ++pwm) PWM_delay(); set(led_port,led); for (pwm = 0; pwm < count; ++pwm) PWM_delay(); } for (count = 255; count > 0; --count) { clear(led_port,led); for (pwm = count; pwm < 255; ++pwm) PWM_delay(); set(led_port,led); for (pwm = 0; pwm < count; ++pwm) PWM_delay(); } } }