// 占空比可调的PWM, 我没试过, 手里没单片机, 只是记下.
#include <msp430x14x.h>
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 |= XTS; // ACLK= LFXT1 = HF XTAL
do {
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--) { // Time for flag to set
;
}
} while ((IFG1 & OFIFG)); // OSCFault flag still set?
BCSCTL2 |= SELM_3; // MCLK= LFXT1 (safe)
P4DIR |= 0x06; // P4.1 and P4.2 output
P4SEL |= 0x06; // P4.2 and P4.2 TB1/2 otions
TBCCR0 = 128; // PWM Period/2
TBCCTL1 = OUTMOD_6; // CCR1 toggle/set
TBCCR1 = 32; // CCR1 PWM duty cycle
TBCCTL2 = OUTMOD_6; // CCR2 toggle/set
TBCCR2 = 96; // CCR2 PWM duty cycle
TBCTL = TBSSEL_1 + MC_3; // ACLK, up-down mode
_BIS_SR(CPUOFF); // Enter LPM0
}
MSP实时输出占空比可调的pwm波形
最新推荐文章于 2023-06-04 01:12:01 发布