⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int_test.c

📁 Embest Arm EduKit II Evaluation Board External Interrupt Test Example Please Select the trigger:
💻 C
字号:
/*********************************************************************************************
* File:	int_test.c
* Author:	embest
* Desc:	the extern interrupt source test
* History:	
*********************************************************************************************/

#include	"44blib.h"
#include	"44b.h"
#include	"def.h"

/*------------------------------------------------------------------------------------------*/
/*                                     function declare                                     */
/*------------------------------------------------------------------------------------------*/
void init_int(void);
void int_test(void);
void int4567_isr(void);// __attribute__ ((interrupt ("IRQ")));

/*------------------------------------------------------------------------------------------*/
/*                                     global variables                                     */
/*------------------------------------------------------------------------------------------*/
unsigned char f_ucIntNesting = 0;			// Interrupt nesting count
unsigned char f_ucWhichInt   = 0;			// interrupt source symbol

/*********************************************************************************************
* name:		init_int
* func:		initialize the extern interrupt control
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void init_int(void)
{
	// interrupt settings
	rI_ISPC    = 0x3ffffff;					// clear interrupt pending register
	rEXTINTPND = 0xf;						// clear EXTINTPND register
	rINTMOD    = 0x0;						// all for IRQ mode
	rINTCON    = 0x5;						// nonVectored mode, IRQ disable, FIQ disable    
	rINTMSK    = ~(BIT_GLOBAL|BIT_EINT4567);
		
	// set EINT interrupt handler
	pISR_EINT4567 = (int)int4567_isr;
    
	// PORT G configuration
	rPCONG  = 0xffff;						// EINT7~0
	rPUPG   = 0x0;							// pull up enable	    
	rEXTINT = rEXTINT | 0x22220020;			// EINT4567 falling edge mode	
	rI_ISPC |=  BIT_EINT4567;
	rEXTINTPND = 0xf;						// clear EXTINTPND reg
}

/*********************************************************************************************
* name:		int_test
* func:	
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void int_test(void)
{
	unsigned int unSaveG,unSavePG;
 
	init_int();
	rINTMSK = rINTMSK | BIT_EINT4567;		// disable EINT2 int
	// user interface
	uart_printf("\n\r External Interrupt Test\n");   
	uart_printf(" Please Select the trigger:\n"
				"  1 - Falling trigger\n"
				"  2 - Rising trigger\n"
				"  3 - Both Edge trigger\n" 
				"  4 - Low level trigger\n"
				"  5 - High level trigger\n"
				"  any key to exit...\n");				
    
	// save the current settings of Port G controler
	unSaveG = rPCONG;
	unSavePG= rPUPG;
	rPCONG  = 0xf5ff;						// EINT7~0
	rPUPG   = 0x0;							// pull up enable
	switch(uart_getch())
	{
		case '1':
			rEXTINT = 0x22222222;			// Falling edge mode 
			break;	    
		case '2':
			rEXTINT = 0x44444444;			// Rising edge mode
			break;
		case '3':
			rEXTINT = 0x77777777;			// Both edge mode
			break;
		case '4':
			rEXTINT = 0x0;		            // "0" level mode
			break;
		case '5':
			//rEXTINT = 0x11111111;			// "1" level mode
			uart_printf(" EINT4567 was pulled up. \n");
			f_ucWhichInt = 9;
			break;
		default:
			rPCONG = unSaveG;
			rPUPG = unSavePG;
			return;
	}

	uart_printf(" Press the buttons \n");
	uart_printf(" push buttons may have glitch noise problem \n");
	rINTMSK = ~(BIT_GLOBAL | BIT_EINT4567);  
	while(!f_ucWhichInt);					// waiting for the interrupt
	f_ucIntNesting = 1;						// Allow to Nesting.

	switch(f_ucWhichInt)
	 {
		case 1:
			uart_printf(" EINT4 had been occured... \n");
			break;
		    
		case 2:
			uart_printf(" EINT5 had been occured...\n");
			break;
		    
		case 4:								// SB2 --- flash LED1
			uart_printf(" EINT6 had been occured... LED1 (D1204) on\n");
			
			// flesh LED1
			leds_off();
			led1_on();
			delay(10000);					// 10000 x 100 us
			led1_off();
			break;
		    
		case 8:								// SB3 --- flash LED2
			uart_printf(" EINT7 had been occured... LED2 (D1205) on\n");
			leds_off();
			// flesh LED2
			led4_on();
			delay(10000);					// 10000 x 100 us
			led4_off();
			break;
		    
		case 9:
			uart_printf(" The extern interrupt had been occured (1 level mode)\n");
		    break;
		    
		default :
			uart_printf(" Error!\n");
			break;
	  }
	
	// reset the global variables
	f_ucWhichInt = 0;						// interrupt source symbol
	f_ucIntNesting = 0;
	
	// restore the Port G controler value
	rPCONG = unSaveG;
	rPUPG  = unSavePG;
}

/*********************************************************************************************
* name:		int4567_isr
* func:	
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void int4567_isr(void)
{
	delay(10);
	f_ucWhichInt  = rEXTINTPND;
	uart_printf(" EINT.. \n");
	if(f_ucIntNesting)
	{
	f_ucIntNesting++;					// an extern intrrupt had been occur before dealing with one.
        delay(100);
        uart_printf(" f_ucIntNesting = %d\n",f_ucIntNesting);
	}

	rEXTINTPND = 0xf;						// clear EXTINTPND reg.		
	rI_ISPC   |=  BIT_EINT4567;				// clear pending_bit

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -