测试板为LM4F Launchpad
以下为源代码:目的是测试LAUNCHPAD上SW1开关对应GPIO口的中断.
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/sysctl.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/interrupt.h"
void IntGPIOFHandler(void)
[
ROM_GPIOPinIntClear(GPIO_PORTF_AHB_BASE,GPIO_PIN_4);
ROM_GPIOPinWrite(GPIO_PORTF_AHB_BASE,GPIO_PIN_3,0x08);
ROM_SysCtlDelay(30000000);
ROM_GPIOPinWrite(GPIO_PORTF_AHB_BASE,GPIO_PIN_3,0x00);
int main()
[
//Clock Set
ting...
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
//Enable Peripheral
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable GPIOF
//Configure GPIO Output Type
//APBrefers to the Advanced Peripheral Bus, while AHB refers to the Advanced High-
//Performance Bus. The AHB offers better back-to-back performance than the APB bus.
//GPIO ports accessed through the AHB can toggle every clock cycle vs. once every two
//cycles for ports on the APB. In power sensitive applications, the APB would be a better
//choice than the AHB.
ROM_SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOF); //Enable AHB
ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_AHB_BASE,GPIO_PIN_4); //PF4 input for interrupt
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_AHB_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //PF1,PF2,PF3 As Output
//Interrupt Configure
ROM_GPIOIntTypeSet(GPIO_PORTF_AHB_BASE,GPIO_PIN_4,GPIO_LOW_LEVEL);
ROM_GPIOPinIntEnable(GPIO_PORTF_AHB_BASE,GPIO_PIN_4);
仿真器执行到这一步的时候,接直接跳到中断处理函数了,而且进去就出不来了...
ROM_IntEnable(INT_GPIOF);
ROM_IntMasterEnable();
while(1)
[
//zz=IntIsEnabled(INT_GPIOF);
ROM_GPIOPinWrite(GPIO_PORTF_AHB_BASE, GPIO_PIN_1|GPIO_PIN_2,0x0a);
ROM_SysCtlDelay(26881720); //About 1s
ROM_GPIOPinWrite(GPIO_PORTF_AHB_BASE, GPIO_PIN_1|GPIO_PIN_2,0x00); //Attention It's "0x00", not "0" , "0" will not work here.
ROM_SysCtlDelay(26881720);
]
//return 0;
]