资源描述
核心源程序如下:
#include "hw_types.h"
#include "hw_memmap.h"
#include "hw_ints.h"
#include "hw_gpio.h"
#include "hw_pwm.h"
#include "sysctl.h"
#include "systick.h"
#include "debug.h"
#include "gpio.h"
#include "pwm.h"
#include "systeminit.h"
unsigned char tosin[]={
2, 5, 9, 12, 16, 19, 22, 25, 28, 32, 35, 38, 41, 44,
47, 51, 54, 57, 60, 63, 66, 69, 72, 76, 79, 82, 85, 88, 91,
94, 97, 100, 103, 106, 108, 111, 114, 117, 120, 123, 126, 128, 131, 134,
137, 139, 142, 145, 147, 150, 153, 155, 158, 160, 163, 165, 168, 170, 172,
175, 177, 179, 182, 184, 186, 188, 190, 193, 195, 197, 199, 201, 203, 205,
207, 208, 210, 212, 214, 216, 217, 219, 221, 222, 224, 225, 227, 228, 230,
231, 232, 234, 235, 236, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
247, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254,
253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 247, 247, 246, 245, 244,
243, 242, 241, 240, 239, 238, 236, 235, 234, 232, 231, 230, 228, 227, 225,
224, 222, 221, 219, 217, 216, 214, 212, 210, 208, 207, 205, 203, 201, 199,
197, 195, 193, 190, 188, 186, 184, 182, 179, 177, 175, 172, 170, 168, 165,
163, 160, 158, 155, 153, 150, 147, 145, 142, 139, 137, 134, 131, 128, 126,
123, 120, 117, 114, 111, 108, 106, 103, 100, 97, 94, 91, 88, 85, 82,
79, 76, 72, 69, 66, 63, 60, 57, 54, 51, 47, 44, 41, 38, 35,
32, 28, 25, 22, 19, 16, 12, 9, 7, 4, 2, //250
};
int main(void)
{
unsigned char n;
jtagWait(); // 防止JTAG失效
clockInit();
SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // PWM时钟源1分频
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // 使能PD口外设
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); // 使能PWM外设
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); // 设置PD0,PD1为PWM0和PWM1
PWMGenPeriodSet(PWM_BASE, PWM_GEN_0,600/2); // 设置两路PWM的共同周期
PWMGenConfigure(PWM_BASE, PWM_GEN_0, // 设置PWM发生器0为上下计数方式,两路PWM不同步
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true); // 使能PWM0和PWM1
PWMGenEnable(PWM_BASE, PWM_GEN_0); // 使能PWM发生器0
while(1)
{
for(n=0;n<250;n++)
{
PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,tosin[n]*2/2); // 分别设置两路PWM的匹配值
PWMPulseWidthSet(PWM_BASE, PWM_OUT_1,tosin[n]*2/2); // 修改50000和10000可以设置占空比
}
}
}
展开阅读全文