TQ2440之按鍵中斷
#include "2440addr.h"
#include"option.h"
#define LED1_ON (rGPBDAT &= ~(1<<5) ) //置0燈亮,置1燈滅
#define LED1_OFF (rGPBDAT |=(1<<5) )
#define LED2_ON (rGPBDAT &= ~(1<<6) )
#define LED2_OFF (rGPBDAT |=(1<<6) )
#define LED3_ON (rGPBDAT &= ~(1<<7) )
#define LED3_OFF (rGPBDAT |=(1<<7) )
#define LED4_ON (rGPBDAT &= ~(1<<8) )
#define LED4_OFF (rGPBDAT |=(1<<8) )
void delay(void)
{
unsigned int i,j;
for(i=0;i<1000;i++)
for(j=0;j<6000;j++)//純粹是為了燈亮的好看不會(huì)閃爍;
;
}
void __irq Key1_ISR(void)//提前定義,不然下邊的pISR_EINT那里會(huì)報(bào)錯(cuò),原因c語(yǔ)言檢測(cè)不到函數(shù)定義
{
rSRCPND |= (1<<1);//清除中斷標(biāo)志位,下面相同
rINTPND |= (1<<1);
LED1_ON;
delay();
LED1_OFF;
}
void __irq Key2_ISR(void)
{
rSRCPND |= (1<<4);
rINTPND |= (1<<4);
rEINTPEND |= (1<<4);//使能EINT4,因?yàn)樗菑?fù)用的,所以要加上這句
rEINTMASK &= (~(1<<4));//中斷屏蔽
LED2_ON;
delay();
LED2_OFF;
}
void __irq Key3_ISR(void)
{
rSRCPND |= (1<<2);
rINTPND |= (1<<2);
LED3_ON;
delay();
LED3_OFF;
}
void __irq Key4_ISR(void)
{
rSRCPND |= (1<<0);
rINTPND |= (1<<0);
LED4_ON;
delay();
LED4_OFF;
}
void led_init(void)//初始化燈
{
rGPBCON = 0x15400;//全部設(shè)置為I/O輸出
rGPBUP = 0x00;//使能上拉電阻
rGPBDAT |= (1<<5)|(1<<6)|(1<<7)|(1<<8);//先讓燈全滅,不然看不到效果
}
void key_init(void)//初始化中斷
{
rGPFCON |= (1<<1)|(1<<3)|(1<<5)|(1<<9); //設(shè)置寄存器為中斷方式
rEXTINT0 |= (1<<1)|(1<<5)|(1<<9)|(1<<17);//設(shè)置外部中斷為下降沿方式觸發(fā)
rEINTMASK &= (~(1<<4));//EINT4中斷有效
rEINTPEND |= (1<<4);//寫(xiě)1清除EINT4中斷標(biāo)志位
rSRCPND |= (1<<0)|(1<<1)|(1<<2)|(1<<4);//EINT0、1、2、4等待請(qǐng)求服務(wù)
rINTMSK &= (~(1<<0))&(~(1<<1))&(~(1<<2))&(~(1<<4));//設(shè)置cpu服務(wù)EINT0、1、2、4
rINTPND |= (1<<0)|(1<<1)|(1<<2)|(1<<4);//優(yōu)先級(jí)的問(wèn)題,IRQ決定服務(wù)哪個(gè)哪個(gè)中斷源先
pISR_EINT0 = (unsigned)Key4_ISR;
pISR_EINT1 = (unsigned)Key1_ISR;
pISR_EINT2 = (unsigned)Key3_ISR;
}
void Main(void)
{
MMU_Init();
led_init();//初始化燈
key_init();//初始化中斷
while(1);//死循環(huán),等待按鍵中斷
}
最近比較懶,好久沒(méi)開(kāi)博客看看了,下次再把串口裸機(jī)程序發(fā)上來(lái),做好了,可是懶得寫(xiě)。最近要復(fù)習(xí)期末考,做到nand flash的操作裸機(jī)程序就暫且放一放,等考完試后再把它完成之后就正式進(jìn)入驅(qū)動(dòng)的學(xué)習(xí),同時(shí)可能會(huì)學(xué)習(xí)一下UC/OS ii。
評(píng)論