求大神帮我看看,调了一个晚上,,串口和pwm毫无变化。。。
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/pwm.h"
#include "driverlib/rom.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
uint16_t cThisChar;
int right,left;
void
Inituart(void)
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
ROM_UARTEnable(UART0_BASE);
ROM_IntMasterEnable();
ROM_UARTIntStatus(UART0_BASE, true);
ROM_UARTFIFODisable(UART0_BASE);
ROM_IntEnable(INT_UART0);
ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
}
int
PWMInit (void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB4_M0PWM2);
GPIOPinConfigure(GPIO_PB5_M0PWM3);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4|GPIO_PIN_5);
PWMGenConfigure(PWM0_BASE, PWM_GEN_1,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1,100);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 100);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 100);
PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT| PWM_OUT_3_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_1);
return(0);
}
int
cthischarconfigue()
{
if( cThisChar=='e')
{
right=100;
left=100;
}
else if(cThisChar=='d')
{
left=0;
right=0;
}
else if(cThisChar=='f')
{
if(left>=right)
{
if(left<=50)
{
do
{
left++;
right–;
}
while((left-right>=25)&&(right==0));
if(left-right<20)
{
right=20;
left=20;
do
{
left++;
right–;
}
while(left-right>=25);
}
}
else
{
left=50;
right=50;
do
{
left++;
right–;
}
while(left-right>=25);
}
}
}
else if(cThisChar=='s')
{
if(right>=left)
{
if(right<=50)
{
do
{
left–;
right++;
}
while((right-left>=25)&&(left==0));
if(right-left<20)
{
left=20;
right=20;
do
{
right++;
left–;
}
while(right-left>=25);
}
}
else
{
right=50;
left=50;
do
{
left–;
right++;
}
while(left-right>=25);
}
}
}
return 0; }
int
UART0IntHandler(void)
{
uint32_t ui32Status;
ui32Status = ROM_UARTIntStatus(UART2_BASE, true);
ROM_UARTIntClear(UART2_BASE, ui32Status);
ROM_UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_RT);
PWMGenDisable(PWM0_BASE, PWM_GEN_1 );
PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT| PWM_OUT_3_BIT, false);
while(true!=ROM_UARTCharsAvail(UART0_BASE));
cThisChar=UARTCharGet(UART0_BASE);
UARTCharPut(UART0_BASE, cThisChar);
cthischarconfigue();
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, right);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, left);
PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT| PWM_OUT_3_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_1);
ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
return 0;
}
int
main(void)
{
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
Inituart();
PWMInit ();
while(1);
}
xyz549040622:
这麽长的程序,楼主先回答我问题
1.串口是否单独调试OK
2.PwM是否单独调试OK
3.你自己判断是串口的问题,还是pwm的问题
xingwen zhou:
回复 xyz549040622:
已调试成功。。。在串口中断配置出了点毛病。。
xingwen zhou:
回复 xyz549040622:
已调试成功。。在串口中断配置上出了点毛病
xingwen zhou:
回复 xyz549040622:
对。。我着个试了一下。。才跳出的
xyz549040622:
回复 xingwen zhou:
串口的中断,是有例程的,可以参考官方的例程
xingwen zhou:
回复 xyz549040622:
谢谢。。。。要得就是这个。。。。请问你那还有没有关于ADC操作的程序啊。。。。帮帮我。。
xyz549040622:
回复 xingwen zhou:
//模数转换器实验程序解析 //头文件 #include <stdint.h> #include <stdbool.h> #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/fpu.h" #include "driverlib/sysctl.h" #include "driverlib/rom.h" #include "driverlib/pin_map.h" #include "grlib/grlib.h" #include "drivers/cfal96x64x16.h" #include "driverlib/gpio.h" #include "driverlib/adc.h" #include "inc/hw_gpio.h"int main(void) {tContext sContext;tRectangle sRect;ui32 ulADC0_Value;ui8 ulADC0_v[8];ui32 i,j;const char chars[16]={"0123456789ABCDEF"};//使能FPUFPUEnable();FPULazyStackingEnable();//设置系统时钟为50MHz (400/2/4=50)ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL |SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);//初始化ADC0/PE3ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);//设置ADC参考电压为外部3VROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);//配置ADC采集序列ROM_ADCSequenceConfigure(ADC0_BASE, 0,ADC_TRIGGER_PROCESSOR, 0);ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 |ADC_CTL_END | ADC_CTL_IE);//使能ADC采集序列ROM_ADCSequenceEnable(ADC0_BASE, 0);ROM_ADCIntClear(ADC0_BASE, 0);ROM_ADCIntEnable(ADC0_BASE, 0);//初始化显示模块CFAL96x64x16Init();GrContextInit(&sContext, &g_sCFAL96x64x16);while(1){//触发采集ADCProcessorTrigger(ADC0_BASE, 0);//等待采集结束while(!ADCIntStatus(ADC0_BASE, 0, false)) ;//获取采集结果ADCSequenceDataGet(ADC0_BASE, 0, &ulADC0_Value);//将采集结果从32位无符号数转化为chari=28;for(j=0;j<8;j++){ulADC0_v[j]=chars[(ulADC0_Value>>i)&0xf];i-=4;}//延时SysCtlDelay(SysCtlClockGet() / 12);//屏幕的上面24行填充蓝色覆盖上次的显示结果sRect.i16XMin = 0;sRect.i16YMin = 0;sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;sRect.i16YMax = 23;GrContextForegroundSet(&sContext, ClrDarkKhaki);GrRectFill(&sContext, &sRect);//在颜色块的边缘放置白框GrContextForegroundSet(&sContext, ClrWhite);GrRectDraw(&sContext, &sRect);//显示工程名称和采集结果GrContextFontSet(&sContext, g_psFontCm12);GrStringDrawCentered(&sContext, ulADC0_v, 8,GrContextDpyWidthGet(&sContext) / 2, 10, 0);GrStringDrawCentered(&sContext, "ADC Results", -1,GrContextDpyWidthGet(&sContext) / 2,((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24, 0);//更新显示GrFlush(&sContext);} }重点看AD的配置
xingwen zhou:
回复 xyz549040622:
多谢。。。你人真好。。。。