/*static void __irq EINT11_ISR(void) { //清中断必须按一下三个的顺序
rEINTPEND |=( 1<< 11);//外部中断悬挂寄存器,清0无请求,1时有中断请求 rSRCPND |= (1<<5);//指示中断源状态,0无中断源请求,1时有中断源请求 rINTPND |=(1<<5);//指示中断状态,0无中断请求,1时有中断请求 Uart_Printf(\"EINT11 is occurred.\\n\");
}
static void __irq EINT8_ISR(void)
{ //清中断必须按一下三个的顺序
rEINTPEND |=( 1<< 8);//外部中断悬挂寄存器,清0无请求,1时有中断请求 rSRCPND |= (1<<5);//指示中断源状态,0无中断源请求,1时有中断源请求 rINTPND |=(1<<5);//指示中断状态,0无中断请求,1时有中断请求 Uart_Printf(\"EINT8 is occurred.\\n\"); }*/
U8 Key_Scan( void ) {
Delay( 8000 ) ;
if( (rGPGDAT&(1<< 0)) == 0 ) return 1 ; else if( (rGPGDAT&(1<< 3)) == 0 ) return 2;
else if( (rGPGDAT&(1<< 5)) == 0 ) return 3 ;
else if( (rGPGDAT&(1<< 6)) == 0 ) return 4 ;
else if( (rGPGDAT&(1<< 7)) == 0 ) return 5 ;
else if( (rGPGDAT&(1<<11)) == 0 ) return 6 ; else
return 0xff;
}
static void __irq Key_ISR(void)
{
//U32 r;
//EnterCritical(&r);
if(rINTPND==BIT_EINT8_23) { ClearPending(BIT_EINT8_23); if(rEINTPEND&(1<<8)) { //Uart_Printf(\"eint11\\n\"); rEINTPEND |= 1<< 8; }
if(rEINTPEND&(1<<11)) { //Uart_Printf(\"eint11\\n\"); rEINTPEND |= 1<< 11; }
if(rEINTPEND&(1<<13)) { //Uart_Printf(\"eint11\\n\"); rEINTPEND |= 1<< 13; }
if(rEINTPEND&(1<<14)) { //Uart_Printf(\"eint11\\n\"); rEINTPEND |= 1<< 14; }
if(rEINTPEND&(1<<15)) { //Uart_Printf(\"eint11\\n\"); rEINTPEND |= 1<< 15; }
if(rEINTPEND&(1<<19)) { // Uart_Printf(\"eint19\\n\"); rEINTPEND |= 1<< 19; } }
key=Key_Scan(); if( key == 0xff )
Uart_Printf( \"Interrupt occur... Key is released!\\n\") ; else
Uart_Printf( \"Interrupt occur... K%d is pressed!\\n\//ExitCritical(&r); }
void xmain(void) {
ChangeClockDivider(3,1);
ChangeMPllValue(127,2,1); //405MHZ MMU_Init(); Isr_Init();
Uart_Init(0, 115200); Uart_Select(0);
Uart_Printf(\"the main is running.\\n\");
//-----------------中断初始化----------------// //选择功能管脚
//rGPGCON = rGPGCON & (~(3<<0) |(2<<0) );
//rGPGCON &(0x82);//当GPG0取10时,表示EINT8,即K1 p144
rGPGCON =rGPGCON & (~((3<<22)|(3<<6)|(3<<0)|(3<<10)|(3<<12)|(3<<14))) | ((2<<22)|(2<<6)|(2<<0)|(2<<10)|(2<<12)|(2<<14));
//中断模式
rINTMOD = rINTMOD & ( ~(1<<5) );//EINT8-23:外部中断8~23 p154 //触发方式
//rEXTINT1 = ( rEXTINT1 | (7<<0) ) & ( ~(4<<0) );//EINT8 falling edge triggered rEXTINT1 &= ~(7|(7<<0));
rEXTINT1 |= (0|(0<<0)); //EXTINT1用于设置EINT15~EINT8触发信号的类型 p146 rEXTINT1 &= ~(7|(7<<12));
rEXTINT1 |= (0|(0x0<<12)); //EXTINT1用于设置EINT15~EINT8触发信号的类型 p146
rEXTINT1 &= ~(7<<20);
rEXTINT1 |= (0<<20); //set eint13 falling edge int
rEXTINT1 &= ~(7<<24);
rEXTINT1 |= (0<<24); //set eint14 falling edge int
rEXTINT1 &= ~(7<<28);
rEXTINT1 |= (0<<28); //set eint15 falling edge int
rEXTINT2 &= ~(0xf<<12);
rEXTINT2 |= (0<<12); //set eint19 falling edge int //使能中断
rINTMSK = rINTMSK & ( ~(1<<5) );//设定被中断屏蔽,0为中断服务有效,1为中断服务屏蔽 p154 //清中断
//rSRCPND |= (1<<8);//to clear EINT8
//rEINTPEND |= ~(1<<8); //clear eint 8
rEINTMASK &= ~((1<<8)|(1<<11)|(1<<13)|(1<<14)|(1<<15)|(1<<19)); //p148 外部中断掩码寄存器,[3:0]保留取值0,[23:4]控制相应的EINT[23:4],清零使能相应的中断,置1时屏蔽中断
// rEINTMASK &= ~((1<<11)); //enable eint11 //中断向量
//pISR_EINT0 = (U32)EINT0_ISR;//EINT0
//ExitCritical(&r); while(1) {
Uart_Printf(\"the main is running.\\n\"); Delay(50000000);
pISR_EINT8_23 = (U32)Key_ISR; }
}
1、MMU 一定要在主函数里面开启。否则会出现dummy is busy............错误
2、请中断的时候一定要按顺序请中断,这个在上面程序注释里面已经有了。否则会无法正常中断。
因篇幅问题不能全部显示,请点此查看更多更全内容