C2000LaunchPad学习记录(3)——外部中断翻转LED

程序功能:将GPIO12配置成中断输入。按键按下,触发下降沿中断,中断服务子程序翻转LED。


中断向量表

C2000LaunchPad学习记录(3)——外部中断翻转LED_第1张图片


主函数,main.c

/* Includes ------------------------------------------------------------------*/
#include
#include
#include "SubFunction.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

void main(void)
{
	// 系统控制初始化
	InitSysCtrl();
	InitGpio();
	// 禁止全局中断
	DINT;
	InitPieCtrl();
	// 禁止CPU中断
	IER = 0x0000;
	// 清楚CPU所有中断标志
	IFR = 0x0000;
	// 位向量表中的所有中断向量配置对应的入口地址
	InitPieVectTable();
	EXTI_Configure();
	EINT;
	// 允许访问受保护的空间
	EALLOW;
	// 配置I/O口为输出
    GpioCtrlRegs.GPADIR.all=0x000f;
    // 禁止访问受保护的空间
    EDIS;
	while(1){
	}
}


外部中断配置函数

/* Includes ------------------------------------------------------------------*/
#include
#include
#include "C2000_it.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/****************************************************************************
* Function Name  : EXTI_Configure
* Description    : 配置外部中断
* Input          : None
* Output         : None
* Return         : None
******************************************************************************/
void EXTI_Configure(void)
{
	//允许访问受保护的空间
	EALLOW;

	PieVectTable.XINT1= &EXTI12_IRQHandler;
	GpioCtrlRegs.GPAPUD.bit.GPIO12 = 1;			//除能上拉电阻
	GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0;		//GPIO12作普通IO使用 p189
	GpioCtrlRegs.GPADIR.bit.GPIO12 = 0;			//配置为输入
	GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 2;		// 6 samples
	GpioCtrlRegs.GPACTRL.bit.QUALPRD1 = 0xFF;	//采样周期为510*Tsysclk,窗口宽度为5*510*Tsysclk=2550/60M=42.5us
	GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 12;	//GPIO12作为xint1的中断源

	XIntruptRegs.XINT1CR.bit.POLARITY = 1;    	//上升沿触发中断
	XIntruptRegs.XINT1CR.bit.ENABLE = 1;      	//外中断1使能

	PieCtrlRegs.PIECTRL.bit.ENPIE = 1;			//使能PIE
	PieCtrlRegs.PIEIER1.bit.INTx4 = 1;			//使能int1.4

	IER |= 0x0001;								//使能int1
	//禁止访问受保护的空间
	EDIS;
}

中断服务程序

/* Includes ------------------------------------------------------------------*/
#include
#include
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/*******************************************************************************
* Function Name  : EXTI12_IRQHandler
* Description    : This function handles External interrupt Line 12 request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
interrupt void EXTI12_IRQHandler(void)
{
	GpioDataRegs.GPATOGGLE.bit.GPIO0=1;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}










你可能感兴趣的:(C2000LaunchPad学习记录(3)——外部中断翻转LED)