
    
    1.4、管脚约束
    
    二、程序设计
    2.1、程序中函数定义
    
    2.2、主要代码
    key.c
- #include <stdio.h> 
- #include "platform.h" 
- #include "xparameters.h" 
- #include "xintc.h" 
- #include "xgpio.h" 
- #include "xil_exception.h" 
- #include "led.h" 
- #define KEY_DEV_ID XPAR_AXI_GPIO_KEY_DEVICE_ID //按键 AXI GPIO ID 
- #define INTC_DEVICE_ID XPAR_AXI_INTC_KEY_DEVICE_ID //中断控制器ID 
- #define EXCEPTION_ID XIL_EXCEPTION_ID_INT //中断异常ID 
- #define AXI_GPIO_INTR_ID XPAR_INTC_0_GPIO_1_VEC_ID //AXI GPIO中断ID 
- static XIntc Intc; //中断控制器实例 
- static XGpio KEY_Gpio; //GPIO中断实例 按键 
- int key_intr_flag = 0; //中断标志 
- int int_flag=0; 
- void GpioHandler(void *CallbackRef) 
- { 
- XGpio *GpioPtr = (XGpio *)CallbackRef; 
- key_intr_flag = 1; //接收到中断,标志信号拉高 
- XGpio_InterruptDisable(GpioPtr, 1); //关闭中断 
- XGpio_InterruptClear(GpioPtr, 1); //清除中断 
- XGpio_InterruptEnable(GpioPtr, 1); //使能中断 
- } 
- void init_key(void) 
- { 
- xil_printf("AXI GPIO INTERRUPT TEST!\r\n"); 
- XGpio_Initialize(&KEY_Gpio, KEY_DEV_ID); //AXI_GPIO器件初始化 
- XGpio_SetDataDirection(&KEY_Gpio, 1, 1); 
- XIntc_Initialize(&Intc, INTC_DEVICE_ID); //初始化中断控制器 
- //关联中断ID和中断服务函数 
- XIntc_Connect(&Intc,AXI_GPIO_INTR_ID,(Xil_ExceptionHandler)GpioHandler,&KEY_Gpio ); 
- XGpio_InterruptEnable(&KEY_Gpio, 1); //使能中断 
- XGpio_InterruptGlobalEnable(&KEY_Gpio); //使能全局中断 
- XIntc_Enable(&Intc,AXI_GPIO_INTR_ID); //在中断控制器上启用中断向量 
- XIntc_Start(&Intc, XIN_REAL_MODE); //启动中断控制器 
- //设置并打开中断异常处理 
- Xil_ExceptionInit(); 
- Xil_ExceptionRegisterHandler(EXCEPTION_ID, 
- (Xil_ExceptionHandler)XIntc_InterruptHandler,&Intc); 
- Xil_ExceptionEnable(); 
- } 
- void key_hdl(void) 
- { 
- u32 Delay; 
- if(key_intr_flag) //检测中断标志信号有效 
- { 
- int_flag= ~int_flag; 
- if(int_flag==0) 
- { 
- led0_on(); 
- } 
- else 
- { 
- led0_off(); 
- } 
- xil_printf("INTC \r\n"); 
- key_intr_flag = 0; //中断标志清零 
- } 
- } 
       三、程序执行
   按下和松开触摸按键开关,中断分别执行一次,上升沿和下降沿执行。同时LED0点亮和关闭各执行一次。
    

 
					
				
 
			
			
			
						
			 我要赚赏金
 我要赚赏金 STM32
STM32 MCU
MCU 通讯及无线技术
通讯及无线技术 物联网技术
物联网技术 电子DIY
电子DIY 板卡试用
板卡试用 基础知识
基础知识 软件与操作系统
软件与操作系统 我爱生活
我爱生活 小e食堂
小e食堂

