This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

请教,利用PWM模块产生四路方波 会报错



/*******************************************
开发坏境:CCSv5.5
程序功能:利用PWM模块产生四路方波
程序说明: PB4\PB5\PD0\PD1产生四个PWM方波
*
* PB4=M0PWM2
* PB5=M0PWM3
* PD0=M0PWM6
* PD1=M0PWM7
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/fpu.h"
#include "driverlib/pin_map.h"

//#define GPIO_PB6_M0PWM0 0x00011804
//#define GPIO_PB7_M0PWM1 0x00011C04

int main (void)
{
//使能FPU
FPUEnable();
FPULazyStackingEnable();

//设置系统时钟为80MHz
SysCtlClockSet(SYSCTL_SYSDIV_2_5 |SYSCTL_USE_PLL|SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);

//使能PWM0模块
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

//使能PWM0和PWM1输出所在GPIO
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

//配置PH0/PH1为PWM功能
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);

GPIOPinConfigure(GPIO_PB4_M0PWM2); //#define GPIO_PB6_M0PWM0 0x00011804
GPIOPinConfigure(GPIO_PB5_M0PWM3); //#define GPIO_PB7_M0PWM1 0x00011C04
GPIOPinConfigure(GPIO_PD0_M0PWM6);
GPIOPinConfigure(GPIO_PD1_M0PWM7);
// PWM时钟配置:不分频
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

//配置PWM发生器0:加减计数,不同步
PWMGenConfigure(PWM0_BASE,PWM_GEN_0,PWM_GEN_MODE_UP_DOWN| PWM_GEN_MODE_NO_SYNC);

//设置PWM发生器1的频率,时钟频率/PWM分频数/n,80M/1/800=100KHZ
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 800);

//设置PWM0/PWM1输出的脉冲宽度
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 400);//50%占空比
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 200);//25%占空比
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 200);//25%占空比
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 200);//25%占空比


//使能PWM0和PWM1的输出
PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT |PWM_OUT_1_BIT), true);
PWMOutputState(PWM0_BASE, (PWM_OUT_2_BIT |PWM_OUT_3_BIT), true);

//使能PWM发生器
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
while(1);
}

上面代码中:

GPIOPinConfigure(GPIO_PB4_M0PWM2); //#define GPIO_PB6_M0PWM0 0x00011804
GPIOPinConfigure(GPIO_PB5_M0PWM3); //#define GPIO_PB7_M0PWM1 0x00011C04
GPIOPinConfigure(GPIO_PD0_M0PWM6);
GPIOPinConfigure(GPIO_PD1_M0PWM7);

这四句会报错

"../main.c", line 50: error #20: identifier "GPIO_PB4_M0PWM2" is undefined
"../main.c", line 51: error #20: identifier "GPIO_PB5_M0PWM3" is undefined
"../main.c", line 52: error #20: identifier "GPIO_PD0_M0PWM6" is undefined
"../main.c", line 53: error #20: identifier "GPIO_PD1_M0PWM7" is undefined
4 errors detected in the compilation of "../main.c".