2410_EINT.c
资源名称:arm_exam.rar [点击查看]
上传用户:mhstny
上传日期:2022-08-05
资源大小:793k
文件大小:3k
源码类别:
微处理器开发
开发平台:
Unix_Linux
- #include "2410lib.h"
- #include "2410addr.h"
- //使用K1按键触发EINT0,EINT0->GPF0
- //使用K3按键触发EINT2,EINT2->GPF2
- //使用K5按键触发EINT11,EINT11->GPG3
- //使用K7按键触发EINT19,EINT19->GPG11
- //KSCAN0->GPE11
- /*********** 外部中断服务程序 ************/
- static void __irq Eint0_ISR(void)
- {
- ClearPending(BIT_EINT0);
- Uart_Printf("EINT0 is occurred.n");
- }
- static void __irq Eint2_ISR(void)
- {
- ClearPending(BIT_EINT2);
- Uart_Printf("EINT2 is occurred.n");
- }
- static void __irq Eint11_19_ISR(void)
- {
- if(rEINTPEND & (1<<11))
- {
- Uart_Printf("EINT11 is occurred.n");
- rEINTPEND=(1<<11);
- ClearPending(BIT_EINT8_23);
- }
- else if(rEINTPEND & (1<<19))
- {
- Uart_Printf("EINT19 is occurred.n");
- rEINTPEND=(1<<19);
- ClearPending(BIT_EINT8_23);
- }
- else
- {
- Uart_Printf("others ENTs are occurredn");
- rEINTPEND=0xffffff;
- ClearPending(BIT_EINT8_23);
- }
- }
- /*********** 外部中断初始化 ************/
- void Eint_Init(void)
- {
- //设置GPE11为输出0
- rGPECON = (rGPECON|(3<<22)) & ~(2<<22);
- rGPEUP |= (1<<11);
- rGPEDAT &= ~(1<<11);
- rGPFCON = rGPFCON & ~(3)|(1<<1); //GPF0设置为EINT0
- rGPFCON = rGPFCON & ~(3<<4)|(1<<5); //GPF2设置为EINT2
- rGPGCON = rGPGCON & ~(3<<6)|(1<<7); //GPG3设置为EINT11
- rGPGCON = rGPGCON & ~(3<<22)|(1<<23); //GPG11设置为EINT19
- rGPFUP|=(1<<0); //disable GPF0 pull up
- rGPFUP|=(1<<2); //disable GPF2 pull up
- rGPGUP|=(1<<3); //disable GPG3 pull up
- rGPGUP|=(1<<11); //disable GPG11 pull up
- rEXTINT0 = (rEXTINT0 & ~(7<<0))|(2<<0); //EINT0 ->falling edge triggered
- rEXTINT0 = (rEXTINT0 & ~(7<<8))|(2<<8); //EINT2 ->falling edge triggered
- rEXTINT1 = (rEXTINT1 & ~(7<<12))|(0x2<<12); //EINT11->falling edge triggered
- rEXTINT2 = (rEXTINT2 & ~(7<<12))|(0x2<<12); //EINT19->falling edge triggered
- pISR_EINT0 = (unsigned)Eint0_ISR;
- pISR_EINT2 = (unsigned)Eint2_ISR;
- pISR_EINT8_23 = (unsigned)Eint11_19_ISR;
- }
- /*********** 开外部中断 ************/
- void Enable_Eint(void)
- {
- rEINTPEND = 0xffffff; //to clear the previous pending states
- rSRCPND |= BIT_EINT0|BIT_EINT2|BIT_EINT8_23;
- rINTPND |= BIT_EINT0|BIT_EINT2|BIT_EINT8_23;
- rEINTMASK=~( (1<<11)|(1<<19) );
- rINTMSK=~(BIT_EINT0|BIT_EINT2|BIT_EINT8_23);
- }
- int xmain()
- {
- ChangeClockDivider(1,1);
- ChangeMPllValue(0xa1,0x3,0x1);
- Port_Init();
- Uart_Select(0);
- Uart_Init(0,115200);
- Eint_Init();
- Enable_Eint();
- while(1)
- { //等待中断,死循环
- Uart_Printf("the main is runningn");
- Delay(5000);
- }
- }