?? int_test.c.bak
字號:
/*********************************************************************************************
* File: int_test.c
* Author: tops
* 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")));
void int0_isr(void);
/*------------------------------------------------------------------------------------------*/
/* 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|BIT_EINT0);
// set EINT interrupt handler
pISR_EINT4567 = (int)int4567_isr;
pISR_EINT0=(int)int0_isr;
// PORT G configuration
rPCONG = 0xffff; // EINT7~0
rPUPG = 0x0; // pull up enable
rEXTINT = rEXTINT | 0x22220020; // EINT4567 falling edge mode
rI_ISPC |= (BIT_EINT4567|BIT_EINT0);
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 = 0;
rINTMSK = rINTMSK | BIT_EINT4567|BIT_EINT0; // disable EINT0 EINT4567 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 = 0xffff; // 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|BIT_EINT0);
pISR_EINT4567 = (int)int4567_isr;
uart_printf(" f_ucWhichInt=%d \n",f_ucWhichInt);
while(!f_ucWhichInt);
// waiting for the interrupt
uart_printf(" f_ucWhichInt=%d \n",f_ucWhichInt);
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: // S3 --- EINT6---flash LED3
uart_printf(" EINT6 had been occured... LED3 (D8) on\n");
// flesh LED3
leds_off();
led3_on();
delay(10000); // 10000 x 100 us
led3_off();
break;
case 8:
uart_printf(" EINT7 had been occured... \n");
break;
case 9: // S2 ---EINT0---flash LED4
uart_printf(" EINT0 had been occured...LED4(D8) on \n");
// flesh LED4
leds_off();
led4_on();
delay(10000); // 10000 x 100 us
led4_off();
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)
{
uart_printf(" EINT.. \n");
delay(10);
f_ucWhichInt = rEXTINTPND;
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
}
void int0_isr(void)
{
uart_printf(" EINT.. \n");
delay(10);
f_ucWhichInt=9;
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);
}
rI_ISPC |= BIT_EINT0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -