The timer generates a PWM square wave output to P1.4, and then S1 controls the duty cycle of the PWM wave s1---p1.7TA0CCR3----P1.4 (There is no problem with generating PWM wave and controlling the duty cycle, but it cannot be controlled by key interrupt, and there is no problem with the header file) void GPIO_init(); unsigned int freq=10; void main() { WDTCTL = WDTPW + WDTHOLD; SPWM_1Way_Init(); SPWM_1Way_Set_Freq(10); GPIO_init(); _EINT();//Open the total interrupt } void GPIO_init() { P1REN |=BIT7; P1OUT |=BIT7; P1IE |=BIT7; P1IES|=BIT7; P1IFG&=~BIT7; } void SPWM_1Way_Init(void) { spwm_i=0; TA0CCR0 =198;//Carrier 126.26KHZ TA0CCR3 =Lab1[spwm_i]; TA0CCTL3 =OUTMOD_7; TA0CTL =TASSEL_2+MC_1+TACLR;//Select clock as SMCLK, UP mode TA1CCR0 =2499;//25000000/(100*100)=2500:100Hz, 100 points: 10KHZ (the time is not accurate, I made some compensation) TA1CTL =TASSEL_2+MC_1+TACLR;//Select clock as SMCLK, UP mode } void SPWM_1Way_Set_Freq(unsigned int freq) { unsigned long freq_num; freq_num=250000/(freq)-1; TA1CCR0 =freq_num; } #pragma vector=PORT1_VECTOR __interrupt void PORT17ISR(void) { TA0CCR3 =Lab1[spwm_i++]; if(spwm_i==100)spwm_i=0; TA1IV=0; }