You are on page 1of 1

#include <avr/io.

h>
#include <util/delay.h>
void InitPWM()
{
TCCR2 = 0x69;
DDRD =0x08;
}
void SetPWMOutput(uint8_t duty) //unsigned char
{
OCR2=duty;
}
void Wait()
{
_delay_loop_2(3200);
}
void main()
{
uint8_t brightness=0;
InitPWM();
while(1)
{
//Now Loop with increasing brightness
for(brightness=0;brightness<255;brightness+5)
{
SetPWMOutput(brightness);
Wait();
}
// Loop with decreasing brightness
for(brightness=255;brightness>0;brightness-5)
{
SetPWMOutput(brightness);
Wait();
}
}
}

You might also like