TI中文支持网
TI专业的中文技术问题搜集分享网站

请问一个用到timer gpio的简单程序

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"

uint32_t g_ui32SysClock;

uint32_t TimerFlag=0;

uint32_t LED1=0;
uint32_t LED2=0;
uint32_t LED3=0;
uint32_t LED4=0;
uint32_t BUTTON1=0;
uint32_t BUTTON2=0;
uint32_t BUTTON3=0;
uint32_t BUTTON4=0;


#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

void
Timer0IntHandler(void)
{ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, LED1*GPIO_PIN_1);GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, LED2*GPIO_PIN_0);GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, LED3*GPIO_PIN_4);GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, LED4*GPIO_PIN_0);//UARTprintf("\rT1: %c  T2: %c", cOne, cTwo);
}


void
Timer1IntHandler(void)
{ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);TimerFlag=1;
}


void
ConfigureUART(void)
{ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);ROM_GPIOPinConfigure(GPIO_PA0_U0RX);ROM_GPIOPinConfigure(GPIO_PA1_U0TX);ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);UARTStdioConfig(0, 115200, g_ui32SysClock);
}

int main(void)
{g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 20000000);ConfigureUART();UARTprintf("Start!");ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1);ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4);GPIOPadConfigSet(GPIO_PORTJ_BASE,GPIO_PIN_0 | GPIO_PIN_1,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);GPIOPadConfigSet(GPIO_PORTQ_BASE,GPIO_PIN_1,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);GPIOPadConfigSet(GPIO_PORTP_BASE,GPIO_PIN_3,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock/1000);ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, g_ui32SysClock / 2);ROM_IntEnable(INT_TIMER0A);ROM_IntEnable(INT_TIMER1A);ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);ROM_TimerEnable(TIMER0_BASE, TIMER_A);ROM_TimerEnable(TIMER1_BASE, TIMER_A);ROM_IntMasterEnable();while(1){if(TimerFlag==1){LED2=1-LED2;LED4=1-LED4;TimerFlag=0;}// SysCtlDelay(1);}
}



代码如上,变量LED1,LED2,LED3,LED4用于控制ek_tm4c1294板上四个LED灯。
现在遇到的问题是:
主函数while1循环里注释掉SysCtlDelay后,LED2和4便不再正常闪烁。暂停后总是停在 if(TimerFlag==1) 处。
保留SysCtlDelay则正常。
对这一现象不甚理解,望各位前辈指点!

第一次提问,如果有表达不清楚的地方还望指出 
xyz549040622:

1.你要实现什么功能呢?

2.怀疑你的定时器时间太短,一直进入中断1,从而导致TimerFlag一直为1,你先测试你的定时器是否定时ok呢?

赞(0)
未经允许不得转载:TI中文支持网 » 请问一个用到timer gpio的简单程序
分享到: 更多 (0)