📄 int_test.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,key_flag;
init_int();
key_flag = 0;
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
rEXTINT = 0x22222222; // Falling edge mode
uart_printf(" Press the buttons \n");
uart_printf(" push buttons may have glitch noise problem \n");
rINTMSK = ~(BIT_GLOBAL | BIT_EINT4567);
while(1)
{
while(!f_ucWhichInt)
{
if(key_flag==0)
led_test();
else if(key_flag==1)
leds_off();
} // 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();
if(key_flag == 0)
key_flag = 1;
else if(key_flag == 1)
key_flag = 0;
uart_printf(" key_flag = %d\n",key_flag);
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 + -