#include "systemInit.h"
#define PF3 GPIO_PIN_3 //LED灯的引脚是PF3
#define KEY GPIO_PIN_7 //按键的引脚是PJ7
// 主函数(程序入口)
int main(void)
{
volatile unsigned long ulLoop;
//jtagWait(); // 防止JTAG失效,重要!
clockInit(); // 时钟初始化:晶振,6MHz
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, PF3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, KEY);
GPIOIntTypeSet(GPIO_PORTJ_BASE, KEY, GPIO_RISING_EDGE);
GPIOPinIntEnable(GPIO_PORTJ_BASE, KEY); // 使能KEY所在管脚的中断
IntEnable(INT_GPIOJ); // 使能GPIOD端口中断
IntMasterEnable();
for (;;)
{
/*if((GPIOPinRead(GPIO_PORTJ_BASE, KEY))==0)
{
GPIOPinWrite(GPIO_PORTF_BASE,PF3,0x08);
for(ulLoop = 0; ulLoop < 600000; ulLoop++)
{
}
GPIOPinWrite(GPIO_PORTF_BASE,PF3,0x00);
for(ulLoop = 0; ulLoop < 600000; ulLoop++)
{
}
}
if((GPIOPinRead(GPIO_PORTJ_BASE, KEY))==1)
GPIOPinWrite(GPIO_PORTF_BASE,PF3,0x00); */ 查询方式正常。
}
}
// GPIOJ的中断服务函数
void GPIO_Port_J_ISR(void)
{
unsigned long ulStatus;
volatile unsigned long ulLoop;
ulStatus = GPIOPinIntStatus(GPIO_PORTJ_BASE, true); // 读取中断状态
GPIOPinIntClear(GPIO_PORTJ_BASE, ulStatus); // 清除中断状态,重要
if (ulStatus & KEY) // 如果KEY的中断状态有效
{
GPIOPinWrite(GPIO_PORTF_BASE,PF3,0x08);
for(ulLoop = 0; ulLoop < 600000; ulLoop++)
{
}
GPIOPinWrite(GPIO_PORTF_BASE,PF3,0x00);
for(ulLoop = 0; ulLoop < 600000; ulLoop++)
{
}
}
}
/******************************/
在startup.s我是这么写的:
EXPORT __Vectors
EXTERN GPIO_Port_J_ISR
__Vectors
DCD StackMem + Stack ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NmiSR ; NMI Handler
DCD FaultISR ; Hard Fault Handler
DCD IntDefaultHandler ; MPU Fault Handler
DCD IntDefaultHandler ; Bus Fault Handler
DCD IntDefaultHandler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD IntDefaultHandler ; SVCall Handler
DCD IntDefaultHandler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD IntDefaultHandler ; PendSV Handler
DCD IntDefaultHandler ; SysTick Handler
DCD IntDefaultHandler ; GPIO Port A
DCD IntDefaultHandler ; GPIO Port B
DCD IntDefaultHandler ; GPIO Port C
DCD IntDefaultHandler ; GPIO Port D
DCD GPIO_Port_J_ISR ; GPIO Port E
DCD IntDefaultHandler ; UART0
DCD IntDefaultHandler ; UART1
DCD IntDefaultHandler ; SSI
DCD IntDefaultHandler ; I2C
在调试的时候,程序总是停在这里:
;******************************************************************************
;
; This is the code that gets called when the processor receives a fault
; interrupt. This simply enters an infinite loop, preserving the system state
; for examination by a debugger.
;
;******************************************************************************
FaultISR
B FaultISR
;******************************************************************************
我刚学ARM。请大家给小弟点提示。 |