/***********************************************************
* 函數(shù)庫(kù)說(shuō)明:ATMEGE8 PWM
* 版本: v1.0
*
************************************************************
*注意: PB1 PB2 20khz 50% 占空比方波
***********************************************************/
#include
int main(void)
{
//PB1 PB2 設(shè)置為輸出模式
DDRB |= (1 << DDB1) | (1 << DDB2);
//PWM周期計(jì)數(shù)器
ICR1 = 300;
//PB1占空比計(jì)數(shù)器,占空比50%
OCR1A = 150;
//PB2占空比計(jì)數(shù)器,占空比50%
OCR1B = 150;
//OC1A OC1B起始高電平電平
TCCR1A |= (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
//OC1A OC1B 快速PWM,TOP值為ICR1,不分頻,PWM啟動(dòng)
TCCR1B |= (1 << WGM13) | (1 << WGM12) | (1 << CS10);
while(1);
return 0;
}