"); //-->
1.初始化TOUTn
设置TOUT0输出功能,并禁止TOUT0口的上啦电阻
rGPBCON = (rGPBCON & (~(3<<0))) | (2<<0);
rGPBUP |= 1<<0;
2.设置Timer0,初始化PWM输出
设置Prescaler 0 [7:0]——These 8 bits determine prescaler value for Timer 0 and 1:
rTCFG0 = rTCFG0 & ~(0xff<<0)|(99<<0);
//rTCFG0[7:0]=99,预分频0设为100,取....
设置MUX 0——Select MUX input for PWM Timer0:
rTCFG1 = rTCFG1 & ~(0xf<<0);
//rTCFG1[3:0]=0,再取1/2
设置TCNTB0和TCMPB0
rTCMPB0 = duty;
rTCNTB0 = cycle;
Determine auto reload on[3]、output inverter off[2]、manual update[1] and start for Timer 0[0].
rTCON = (rTCON & ~(0xf<<0)) | (0xb << 0);
The Timer 0 manual update bit has to be cleared at next writing.
rTCON &= ~2;
3.跟新rTCMPB0,以获得不同的占空比
rTCMPB0 = pwm_dac;
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。