msp430f149具有PWM输出吗?
发布网友
发布时间:2023-07-28 17:48
我来回答
共1个回答
热心网友
时间:2024-12-03 08:56
有,我现在也在学习:)
//P2.3(TA1)和P2.4(TA2)连接内部模块,输出PWM
//Period(CCR0):PWM周期(4096-1)
//Cyc1(CCR1):P2.3口输出方波的占空比(3072)
//Cyc2(CCR2):P2.4口输出方波的占空比(1024)
#include"MSP430x14x.h"
#define uchar unsigned char
#define uint unsigned int
/*void PWM_TimerA(uint T,uint High1,uint High2 )
{
P2SEL |= BIT3 + BIT4; // P2.3和P2.4连接内部模块
P2DIR = 0xff; // P2端口设置为输出
P2OUT = 0xff; // 关闭其他LED
CCR0 = T; // PWM周期为1S
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = High1; // CCR1 PWM ty cycle
CCTL2 = OUTMOD_7; // CCR2 reset/set
CCR2 = High2; // CCR2 PWM ty cycle
TACTL = TASSEL_1 + ID_3 + MC_1; // ACLK/8, up mode
}*/
void PWM_TimerA(uint T,uint High1 )
{
P1SEL |=BIT2+BIT3;//P1.2和P1.3连接内部模块
P1DIR = 0xff;
P1OUT = 0xff;
CCR0=T;//装入PMW周期值
CCTL1=OUTMOD_7;//CCR1输出单元为 复位/置位输出模式
CCR1=High1;
//CCTL2=OUTMOD_7;//CCR2输出单元为 复位/置位输出模式
//CCR2=High2;
}
//PWM_TimerA(4095,3072,1024);
// _BIS_SR(LPM3_bits);