×
单片机 > 单片机程序设计 > 详情

LM3S9B96 中断映射表的配置

发布时间:2020-06-08 发布时间:
|
中断映射表类似于MFC中的消息映射机制,当你在main函数中定义一个中断处理函数,例如:GPIO_Port_J_ISR,PJ口中断处理函数。
如果想进入这个中断处理函数,你必须在startup_ewarm.c文件中添加两处相应代码

1. 声明GPIO_Port_J_ISR函数代码:该函数是在main中定义的,在startup_ewarm.c文件中使用前,要先声明一下

 

//*****************************************************************************

//

// External declarations for the interrupt handlers used by the application.

//

//*****************************************************************************

extern void GPIO_Port_J_ISR(void);

 

 

2. 中断映射表

 

//*****************************************************************************

//

// The vector table.  Note that the proper constructs must be placed on this to

// ensure that it ends up at physical address 0x0000.0000.

//

//*****************************************************************************

__root const uVectorEntry __vector_table[] @ ".intvec" =

{

    { .ulPtr = (unsigned long)pulStack + sizeof(pulStack) },

                                            // The initial stack pointer

    __iar_program_start,                    // The reset handler

    NmiSR,                                  // The NMI handler

    FaultISR,                               // The hard fault handler

    IntDefaultHandler,                      // The MPU fault handler

    IntDefaultHandler,                      // The bus fault handler

    IntDefaultHandler,                      // The usage fault handler

    0,                                      // Reserved

    0,                                      // Reserved

    0,                                      // Reserved

    0,                                      // Reserved

    IntDefaultHandler,                      // SVCall handler

    IntDefaultHandler,                      // Debug monitor handler

    0,                                      // Reserved

    IntDefaultHandler,                      // The PendSV handler

    IntDefaultHandler,                      // The SysTick handler

    IntDefaultHandler,                      // GPIO Port A

    IntDefaultHandler,                      // GPIO Port B

    IntDefaultHandler,                      // GPIO Port C

    IntDefaultHandler,                      // GPIO Port D

    IntDefaultHandler,                      // GPIO Port E

    IntDefaultHandler,                      // UART0 Rx and Tx

    IntDefaultHandler,                      // UART1 Rx and Tx

    IntDefaultHandler,                      // SSI0 Rx and Tx

    IntDefaultHandler,                      // I2C0 Master and Slave

    IntDefaultHandler,                      // PWM Fault

    IntDefaultHandler,                      // PWM Generator 0

    IntDefaultHandler,                      // PWM Generator 1

    IntDefaultHandler,                      // PWM Generator 2

    IntDefaultHandler,                      // Quadrature Encoder 0

    IntDefaultHandler,                      // ADC Sequence 0

    IntDefaultHandler,                      // ADC Sequence 1

    IntDefaultHandler,                      // ADC Sequence 2

    IntDefaultHandler,                      // ADC Sequence 3

    IntDefaultHandler,                      // Watchdog timer

    IntDefaultHandler,                      // Timer 0 subtimer A

    IntDefaultHandler,                      // Timer 0 subtimer B

    IntDefaultHandler,                      // Timer 1 subtimer A

    IntDefaultHandler,                      // Timer 1 subtimer B

    IntDefaultHandler,                      // Timer 2 subtimer A

    IntDefaultHandler,                      // Timer 2 subtimer B

    IntDefaultHandler,                      // Analog Comparator 0

    IntDefaultHandler,                      // Analog Comparator 1

    IntDefaultHandler,                      // Analog Comparator 2

    IntDefaultHandler,                      // System Control (PLL, OSC, BO)

    IntDefaultHandler,                      // FLASH Control

    IntDefaultHandler,                      // GPIO Port F

    IntDefaultHandler,                      // GPIO Port G

    IntDefaultHandler,                      // GPIO Port H

    IntDefaultHandler,                      // UART2 Rx and Tx

    IntDefaultHandler,                      // SSI1 Rx and Tx

    IntDefaultHandler,                      // Timer 3 subtimer A

    IntDefaultHandler,                      // Timer 3 subtimer B

    IntDefaultHandler,                      // I2C1 Master and Slave

    IntDefaultHandler,                      // Quadrature Encoder 1

    IntDefaultHandler,                      // CAN0

    IntDefaultHandler,                      // CAN1

    IntDefaultHandler,                      // CAN2

    IntDefaultHandler,                      // Ethernet

    IntDefaultHandler,                      // Hibernate

    IntDefaultHandler,                      // USB0

    IntDefaultHandler,                      // PWM Generator 3

    IntDefaultHandler,                      // uDMA Software Transfer

    IntDefaultHandler,                      // uDMA Error

    IntDefaultHandler,                      // ADC1 Sequence 0

    IntDefaultHandler,                      // ADC1 Sequence 1

    IntDefaultHandler,                      // ADC1 Sequence 2

    IntDefaultHandler,                      // ADC1 Sequence 3

    IntDefaultHandler,                      // I2S0

    IntDefaultHandler,                      // External Bus Interface 0

GPIO_Port_J_ISR                       // GPIO Port J

};

 

 
下面是中断映射表配置例子的main.c文件:

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"

//*****************************************************************************
// 数据类型定义区
//*****************************************************************************
typedef unsigned char BYTE; // 8 bit
typedef unsigned short WORD; // 16 bit
typedef unsigned long DWORD; // 32 bit
typedef enum {FALSE = 0, TRUE = !FALSE} bool;

/* 寄存器地址 ---------------------------------------------------------------*/
#define GPIO_PORTF_APB_DIR_R 0x40025400
#define GPIO_PORTF_APB_DEN_R 0x4002551C

/* 用于调试 PF1 LED -----------------------------------------------------*/
#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_PORT GPIO_PORTF_BASE
#define LED_PIN GPIO_PIN_1
#define LED_OFF 1 << 1
#define LED_ON ~(1 << 1) // 低电平点亮LED


//*****************************************************************************
//
// 延时函数
//
//*****************************************************************************
void Delay(volatile signed long nCount)
{
for(; nCount != 0; nCount--);
}

//*****************************************************************************
//
// LED初始化函数,用于调试timer, watchdog等
//
//*****************************************************************************
void LED_Init(void)
{
// 使能LED所在的GPIO端口
SysCtlPeripheralEnable(LED_PERIPH);

// 设置LED所在管脚为输出
GPIOPinTypeGPIOOutput(LED_PORT, LED_PIN);

// 熄灭LED(默认LED是点亮的,低电平点亮LED)
GPIOPinWrite(LED_PORT, LED_PIN, LED_ON);
}

//*****************************************************************************
//
// PJ7管脚设置为,双沿触发中断方式
//
//*****************************************************************************
void GPIO_PJ7_Init(void)
{
// 使能GPIOJ端口
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);

// 设置PJ7管脚为输入
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_7);

// 配置PJ7管脚带弱上拉电阻
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

// 设置PJ7管脚的中断类型,双沿触发
GPIOIntTypeSet(GPIO_PORTJ_BASE, GPIO_PIN_7, GPIO_BOTH_EDGES);
UARTprintf("PJ7 is high at begin ->\n");

// 使能GPIOJ端口中断
IntEnable(INT_GPIOJ);

// 使能PJ7管脚的中断
GPIOPinIntEnable(GPIO_PORTJ_BASE, GPIO_PIN_7);
}

//*****************************************************************************
//
// This function sets up UART2 to be used for a console to display information
// as the example is running.
//
//*****************************************************************************
void InitConsole(void)
{
// Enable GPIO port D which is used for UART2 pins.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

// Select the alternate (UART) function for these pins.
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
GPIOPinConfigure(GPIO_PD0_U2RX);
GPIOPinConfigure(GPIO_PD1_U2TX);

// Initialize the UART for console I/O.
UARTStdioInit(2);

UARTprintf("Uart2 is ready ->\n");
}


//*****************************************************************************
//
// 主函数
//
//*****************************************************************************
int main(void)
{
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

LED_Init(); // 初始化LED,输出

InitConsole(); // UART2初始化

GPIO_PJ7_Init(); // 初始化PJ7管脚,输入

IntMasterEnable(); // 开总中断

GPIOPinWrite(LED_PORT, LED_PIN, LED_OFF);
Delay(0xFFFFF);
GPIOPinWrite(LED_PORT, LED_PIN, LED_ON);
Delay(0xFFFFF);
GPIOPinWrite(LED_PORT, LED_PIN, LED_OFF);
Delay(0xFFFFF);
GPIOPinWrite(LED_PORT, LED_PIN, LED_ON);
Delay(0xFFFFF);
GPIOPinWrite(LED_PORT, LED_PIN, LED_OFF);
Delay(0xFFFFF);
GPIOPinWrite(LED_PORT, LED_PIN, LED_ON);
Delay(0xFFFFF);

while (1)
{
Delay(0xFFFFF); // 646ms
}
}


//*****************************************************************************
//
// PJ7管脚的中断服务函数,双沿触发
//
//*****************************************************************************
void GPIO_Port_J_ISR(void)
{
// 读取中断状态,GPIOJ端口的8个管脚都可能触发中断
DWORD Status = GPIOPinIntStatus(GPIO_PORTJ_BASE, true);

// 清除中断状态,重要
GPIOPinIntClear(GPIO_PORTJ_BASE, Status);

if ((Status & GPIO_PIN_7) != 0)
{
// 上升沿中断处理函数
if (0x00000080 == GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_7))
{
UARTprintf("PJ7 is low to high ->\n");
Delay(0xFFFFF);
}
else if (0 == GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_7)) // 下降沿中断处理函数
{
UARTprintf("PJ7 is high to low ->\n");
Delay(0xFFFFF);
}
}
}




『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
TQ210天嵌开发板S5PV210 LED闪烁程序C语言代码记录