根据之前问题,如果我要改用P2.5与P2.4输出pwm呢#include "driverlib.h" #define TIMER_PERIOD 8192 void Timer_A0_PWM_Init(void) { Timer_A_outputPWMParam htim = {0}; //P1.2复用输出 GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN2); // GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN5); //时钟源选为SMCLK = 1048576 HZ htim.clockSource = TIMER_A_CLOCKSOURCE_ACLK; //分频系数设为32 32768HZ htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; //装载值设为8192 - 1 ,周期为0.25s htim.timerPeriod = TIMER_PERIOD - 1; //P1.2 对应 TA0.1 故设为TIMER_A_CAPTURECOMPARE_REGISTER_1 定时器为0 htim.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; //选择复位置位模式 htim.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET; //设置占空比,为5% htim.dutyCycle = TIMER_PERIOD / 20 ; //P1.2 对应 TA0.1 为TIMER_A0_BASE Timer_A_outputPWM(TIMER_A0_BASE, &htim); } void Timer_A1_PWM_Init(void) { Timer_A_outputPWMParam htim = {0}; //P1.3复用输出 GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN0); // GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN4); //时钟源选为SMCLK = 1048576 HZ htim.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; //分频系数设为32 32768HZ htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32; //装载值设为8192 - 1 ,周期为0.25s htim.timerPeriod = TIMER_PERIOD - 1; //P1.3 对应 TA1.1 故设为TIMER_A_CAPTURECOMPARE_REGISTER_1 定时器为1 htim.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; //选择复位置位模式 htim.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET; //设置占空比,为10% htim.dutyCycle = TIMER_PERIOD / 10 ; //P1.3 对应 TA1.1 为TIMER_A1_BASE Timer_A_outputPWM(TIMER_A1_BASE, &htim); }
时间: 2024-04-21 07:24:28 浏览: 114
easyarm101-keil.rar_Easyarm_KEIL ARM_driverlib.l_easyarm101_kei
如果您要将引脚从P1.2和P1.3更改为P2.5和P2.4,您需要进行以下更改:
在Timer_A0_PWM_Init函数中,将以下行:
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN2);
更改为:
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN5);
在Timer_A1_PWM_Init函数中,将以下行:
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN0);
更改为:
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4);
这样,您的代码将使用P2.5和P2.4引脚来输出PWM信号。请确保根据您的硬件连接进行正确的引脚配置。
阅读全文