Avr 在atmega8中未更新PWM

Avr 在atmega8中未更新PWM,avr,Avr,我尝试在atmega 8的PB1和PB2处使用硬件PWM。但是,当出现这种情况时,这些引脚上的代码输出值不会更新。请导游 #include <avr/io.h> #include <util/delay.h> void init_pwmA(uint8_t a) { TCCR1A|=(1<<COM1A1)|(1<<WGM11); TCCR1B|=(1<<WGM12) |(1<<WGM13)| (1<&l

我尝试在atmega 8的PB1和PB2处使用硬件PWM。但是,当出现这种情况时,这些引脚上的代码输出值不会更新。请导游

#include <avr/io.h>
#include <util/delay.h>
void init_pwmA(uint8_t a)
{

    TCCR1A|=(1<<COM1A1)|(1<<WGM11);
    TCCR1B|=(1<<WGM12) |(1<<WGM13)| (1<<CS10)|(1<<CS11);
    ICR1=a;
    OCR1A=0;

}
void init_pwmB(uint8_t a)
{

    TCCR1A|= (1<<WGM11)|(1<<COM1B1);
    TCCR1B|=(1<<WGM12) |(1<<WGM13)| (1<<CS10)|(1<<CS11);
    ICR1=a;
    OCR1B=0;
}


int main()
{ 

    DDRD=0x00;
    DDRB=0xFF;
    PORTB=0x00;
    while(1)
    {
        if(PIND&(0x01) == 0x01)  
        {
            //PORTB=0b00000110;
                init_pwmB(0);
                init_pwmA(0);

        }
        if(PIND&(0x02) == 0x02)
        {

            init_pwmA(255);


        }
    }
    return 0;
}

ICR1中的最大值为100%PWM的值,OCR1A中的最大值为所需的PWM值

因此,将代码更改为:

ICR1=0xff; //assuming, you want 255 to be your top value
OCR1A=a; //your PWM value
见表39。Mega8手册中的波形生成模式位说明