|
我想用LM3S系 产生PWM方波来驱动蜂鸣器 下面是我参考资料写的程序,但是看示波器,怎么也不产生方波,请哪位高手帮助分析一下啊~
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
#include "hw_memmap.h"
#include "pwm.h"
#include "lm3s5t36.h"
unsigned long TheSysClock ;
#define uint unsigned int
#define uchar unsigned char
int main()
{
SysCtlClockSet(SYSCTL_SYSDIV_2|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //ʹÄÜB¿Ú
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); // ʹÄÜPWM¿Ú
SysCtlPWMClockSet(SYSCTL_PWMDIV_1); //8·ÖƵ=2M
TheSysClock = SysCtlClockGet();
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_0);
GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_0,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_0 ); // PB0andPB1
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_1 );
PWMGenConfigure(PWM_BASE, PWM_GEN_1,PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); //·¢ÉúÆ÷1£¬µÝ¼õ£¬
PWMGenPeriodSet(PWM_BASE, PWM_GEN_1, 6000);
PWMPulseWidthSet(PWM_BASE, PWM_OUT_2, 4200);
PWMPulseWidthSet(PWM_BASE, PWM_OUT_3, 1800);
PWMOutputState(PWM_BASE,PWM_OUT_2_BIT, true);
PWMGenEnable(PWM_BASE, PWM_GEN_1);
while(1)
{
}
}
|
|