共2条
1/1 1 跳转至页
Beep 我真搞不明白为什么执行下面的代码就可以让我的Beep发声?
问
好奇怪哦,我没看到有哪一段代码对Beep那个管脚进行操作啊?
定时器2中断服务里面就这一条指令
rI_ISPC=BIT_TIMER2;//clear timer2 interrput pending of BIT_TIMER2
难道只有GPE5(Beep)才能输出PWM?
就这段代码Beep就发出声音了
void SetBeepPwm(unsigned short Freq, unsigned char HiRatio)
{
rTCON &= 0xffff0fff; // clear manual update bit, stop Timer2
rTCFG0 &= 0xffff00ff; // set Timer 2&3 prescaler 0
rTCFG1 &= 0xfffff0ff; // set Timer 2 MUX 1/16
rTCFG1 |= 0x00000300;
rTCNTB2 = MCLK/(Freq*16); //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
rTCMPB2 = (rTCNTB2*(100-HiRatio))/100; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
// rTCON |= 0x00002000; // manual update
rTCON &= 0xffff0fff; // clear manal update bit
rTCON |= 0x0000d000; // auto reload, inverter on, start Timer 2
}
答 1: 兄弟!你说对了,这段只有在GPE5才有PWM输出很多东西不一定是只有你看到才算发生了,看一下硬件手册吧
定时器2中断服务里面就这一条指令
rI_ISPC=BIT_TIMER2;//clear timer2 interrput pending of BIT_TIMER2
难道只有GPE5(Beep)才能输出PWM?
就这段代码Beep就发出声音了
void SetBeepPwm(unsigned short Freq, unsigned char HiRatio)
{
rTCON &= 0xffff0fff; // clear manual update bit, stop Timer2
rTCFG0 &= 0xffff00ff; // set Timer 2&3 prescaler 0
rTCFG1 &= 0xfffff0ff; // set Timer 2 MUX 1/16
rTCFG1 |= 0x00000300;
rTCNTB2 = MCLK/(Freq*16); //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
rTCMPB2 = (rTCNTB2*(100-HiRatio))/100; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
// rTCON |= 0x00002000; // manual update
rTCON &= 0xffff0fff; // clear manal update bit
rTCON |= 0x0000d000; // auto reload, inverter on, start Timer 2
}
答 1: 兄弟!你说对了,这段只有在GPE5才有PWM输出很多东西不一定是只有你看到才算发生了,看一下硬件手册吧
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |