0
我想在atmega8的PB1和PB2上使用硬件PWM。但是在代碼中這些引腳的輸出值在情況發生時不會更新。請指導。PWM在atmega8中沒有得到更新
#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;
}