#include "hw_memmap.h" #include "hw_types.h" #include "hw_ints.h" #include "gpio.h" #include "sysctl.h" #include "timer.h" #include "interrupt.h" #define PINS1 GPIO_PIN_7
void Timer0A_ISR (void) { TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);// 清除定时器0中断 GPIOPinWrite(GPIO_PORTD_BASE, PINS1,GPIOPinRead(GPIO_PORTD_BASE, PINS1) ^ PINS1); // 翻转GPIO D7 端口 (LED不停的翻转闪烁) TimerEnable(TIMER0_BASE, TIMER_A); // 使能定时器0 }
int main(void) { SysCtlClockSet( SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ ); SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOD ); IntMasterEnable(); GPIODirModeSet(GPIO_PORTD_BASE, PINS1,GPIO_DIR_MODE_OUT); GPIOPinWrite( GPIO_PORTD_BASE, PINS1, 1 ); TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/2); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_A); IntEnable(INT_TIMER0A); while(1); }
上述实验使LED每秒2次的频率不停的闪烁,比如我想要LED闪烁10秒中以后就不闪烁,不知该怎样利用定时器产生,希望Zlg指点。 |