#include
#include
# define uchar unsigned char
# define uint unsigned int
# define key PINB. 1
# define KEY_DOWN 0
Uchar key_code=0;
Flash uchar led_value [4]={255, 77, 26, 13};
Void PWM_ini (void)
{
TCCR0A=0 x83;//fast PWM mode
TCCR0B=0 x01;//no crossover
}
Void key_scan ()
{
If (key==KEY_DOWN)
{
Delay_ms (30);
If (key==KEY_DOWN)
{
Key_code + +;
If (key_code==4)
Key_code=0;
while(! Key);
}
}
}
Void main (void)
{
PORTB=0 x02;
DDRB=0 x01;
PWM_ini ();
While (1)
{
Key_scan ();
OCR0A=led_value [key_code];
Delay_ms (30);
}
}