Home > other >  Questions about ATtiny13A PWM Settings
Questions about ATtiny13A PWM Settings

Time:09-25

I want to adjust the brightness of the little lamp with a button circulation, the change OCR0A value method was adopted to adjust the PWM duty cycle, but not achieve a simple function, the code posted here, please down to see where is the problem?

#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);
}
}
  • Related