新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > LM3S9B96 中斷映射表的配置

LM3S9B96 中斷映射表的配置

作者: 時(shí)間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
中斷映射表類似于MFC中的消息映射機(jī)制,當(dāng)你在main函數(shù)中定義一個(gè)中斷處理函數(shù),例如:GPIO_Port_J_ISR,PJ口中斷處理函數(shù)。
如果想進(jìn)入這個(gè)中斷處理函數(shù),你必須在startup_ewarm.c文件中添加兩處相應(yīng)代碼

1. 聲明GPIO_Port_J_ISR函數(shù)代碼:該函數(shù)是在main中定義的,在startup_ewarm.c文件中使用前,要先聲明一下

本文引用地址:http://butianyuan.cn/article/201611/317008.htm

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

//

// 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"

//*****************************************************************************
// 數(shù)據(jù)類型定義區(qū)
//*****************************************************************************
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

/* 用于調(diào)試 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) // 低電平點(diǎn)亮LED


//*****************************************************************************
//
// 延時(shí)函數(shù)
//
//*****************************************************************************
void Delay(volatile signed long nCount)
{
for(; nCount != 0; nCount--);
}

//*****************************************************************************
//
// LED初始化函數(shù),用于調(diào)試timer, watchdog等
//
//*****************************************************************************
void LED_Init(void)
{
// 使能LED所在的GPIO端口
SysCtlPeripheralEnable(LED_PERIPH);

// 設(shè)置LED所在管腳為輸出
GPIOPinTypeGPIOOutput(LED_PORT, LED_PIN);

// 熄滅LED(默認(rèn)LED是點(diǎn)亮的,低電平點(diǎn)亮LED)
GPIOPinWrite(LED_PORT, LED_PIN, LED_ON);
}

//*****************************************************************************
//
// PJ7管腳設(shè)置為,雙沿觸發(fā)中斷方式
//
//*****************************************************************************
void GPIO_PJ7_Init(void)
{
// 使能GPIOJ端口
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);

// 設(shè)置PJ7管腳為輸入
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_7);

// 配置PJ7管腳帶弱上拉電阻
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

// 設(shè)置PJ7管腳的中斷類型,雙沿觸發(fā)
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");
}


//*****************************************************************************
//
// 主函數(shù)
//
//*****************************************************************************
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管腳的中斷服務(wù)函數(shù),雙沿觸發(fā)
//
//*****************************************************************************
void GPIO_Port_J_ISR(void)
{
// 讀取中斷狀態(tài),GPIOJ端口的8個(gè)管腳都可能觸發(fā)中斷
DWORD Status = GPIOPinIntStatus(GPIO_PORTJ_BASE, true);

// 清除中斷狀態(tài),重要
GPIOPinIntClear(GPIO_PORTJ_BASE, Status);

if ((Status & GPIO_PIN_7) != 0)
{
// 上升沿中斷處理函數(shù)
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)) // 下降沿中斷處理函數(shù)
{
UARTprintf("PJ7 is high to low ->n");
Delay(0xFFFFF);
}
}
}



關(guān)鍵詞: LM3S9B96中斷映射表配

評(píng)論


技術(shù)專區(qū)

關(guān)閉