功能是 串口助手发送一个数,单片机收到后,控制电机实现转速从零到全速的变化
中断能进,led灯可以亮,可是控制不了电机的转速。。。
#include <stdint.h>
#include <stdbool.h>
#include "utils/ustdlib.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/fpu.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "grlib/grlib.h"
#include "driverlib/interrupt.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/uart.h"
#define PWM_MAX 100
#define PWM_MIN 0
void delay()
{
int i,j;
for(i=0;i<1000;i++)
{
for(j=0;j<1000;j++);
}
}
void UART5IntHandler(void)
{
unsigned int ulStatus;
ulStatus = ROM_UARTIntStatus(UART5_BASE, true);
ROM_UARTIntClear(UART5_BASE, ulStatus);
while(ROM_UARTCharsAvail(UART5_BASE))
{
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1);
delay();
ROM_UARTCharPutNonBlocking(UART5_BASE,ROM_UARTCharGetNonBlocking(UART5_BASE));
}
}
int main (void)
{
FPUEnable();
FPULazyStackingEnable();
SysCtlClockSet(SYSCTL_SYSDIV_2_5 |SYSCTL_USE_PLL
|SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
GPIOPinConfigure(GPIO_PE4_U5RX);
GPIOPinConfigure(GPIO_PE5_U5TX);
GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
ROM_IntMasterEnable();
ROM_UARTConfigSetExpClk(UART5_BASE, ROM_SysCtlClockGet(),9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_IntEnable(INT_UART5);
ROM_UARTIntEnable(UART5_BASE, UART_INT_RX | UART_INT_RT);
int PWM_Width=ROM_UARTCharGet(UART5_BASE);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
ROM_GPIOPinConfigure(GPIO_PC5_M0PWM7);
ROM_GPIOPinTypePWM(GPIO_PORTC_BASE,GPIO_PIN_5);
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_3,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, 100);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7, 0);
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_3);
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_7_BIT, true);
while(1);
}
此帖出自
小平头技术问答
一周热门 更多>