關(guān)于mini2440的一個裸機(jī)程序——LED與按鍵中斷
/* *File:main.c
*Description:Whenyoupressthekey,
*theLEDwillshowthekey_valueofkeybythebinary
*andproducethebuzzer.
*Author:Cong
*Copyright:Cong
*
*
*History
*---------------------
*Rev:0.0
*Date:2011/11/26
*Creat.
*--------------------
*
*
*/
//--------------------IncludeFiles------------------------------------//
#include"2440addr.h"
#include"2440slib.h"
//---------------------DefineValurable-------------------------------//
#defineGLOBAL_CLK1
#defineLED1_ON~(1<<5)
#defineLED2_ON~(1<<6)
#defineLED3_ON~(1<<7)
#defineLED4_ON~(1<<8)
#defineLED1_OFF(1<<5)
#defineLED2_OFF(1<<6)
#defineLED3_OFF(1<<7)
#defineLED4_OFF(1<<8)
#defineBEEP0
#defineLED110
#defineLED212
#defineLED314
#defineLED416
#defineKEY10
#defineKEY26
#defineKEY310
#defineKEY412
#defineKEY514
#defineKEY622
//--------------------FunctionPrototype------------------------------//
staticvoidLEDKEY_port_init(void);
staticvoidShow_num(intnum);
staticvoidBeep_run(void);
staticvoiddelay(unsignedinttimes);
staticvoid__irqkey_handler(void);
/*
*
*程序入口
*/
voidMain(void)
{
LEDKEY_port_init();
while(1)
{
}
}
/*
*===================Function======================
*Name:Port_init
*Discription:inittheGPIO
*=================================================
*/
staticvoidLEDKEY_port_init(void)
{
//初始化LED與BEEP所要用到的IO用到的這五個端口都配置為輸出
rGPBCON&=~((3<
rGPBCON|=(1<
//初始化KEY所用的IO所有的KEY端口都初始化為中斷方式
rGPGCON&=~((3<
rGPGCON|=(2<
//中斷初始化EINT8
//rEXTINT1&=~((0xf)|(0xf<<12)|(0xf<<20)|(0xf<<24)|(0xf<<28));//設(shè)置K1的低電平中斷
rEXTINT1&=~0xfff0f00f;
rEXTINT2&=~(0xf<<12);
rEINTPEND|=(1<<8)|(1<<11)|(1<<13)|(1<<14)|(1<<15)|(1<<19);//清除K1的中斷標(biāo)志
rEINTMASK=~((1<<8)|(1<<11)|(1<<13)|(1<<14)|(1<<15)|(1<<19));//打開EINT8的中斷使能
pISR_EINT8_23=(U32)key_handler;
EnableIrq(BIT_EINT8_23);//外部中斷8-23共用的中斷位使能,與ClearPending對應(yīng)
}
/*
*===================Function======================
*Name:Show_num
*Discription:inittheGPIOofKey
*=================================================
*/
staticvoidShow_num(intdata)
{
if(data&0x08)rGPBDAT=rGPBDAT&(LED4_ON);
elserGPBDAT=rGPBDAT|(LED4_OFF);
if(data&0x04)rGPBDAT=rGPBDAT&(LED3_ON);
elserGPBDAT=rGPBDAT|(LED3_OFF);
if(data&0x02)rGPBDAT=rGPBDAT&(LED2_ON);
elserGPBDAT=rGPBDAT|(LED2_OFF);
if(data&0x01)rGPBDAT=rGPBDAT&(LED1_ON);
elserGPBDAT=rGPBDAT|(LED1_OFF);
}
/*
*===================Function======================
*Name:Beep_run
*Discription:producethebuzzer
*=================================================
*/
staticvoidBeep_run(void)
{
rGPBDAT|=(0x1<<0);
delay(50);
rGPBDAT&=(0x0<<0);
delay(50);
}
/*
*===================Function======================
*Name:delay
*Discription:producedelay,thetimeistimes.
*=================================================
*/
staticvoiddelay(unsignedinttimes)
{
unsignedinti;
for(;times>0;times--)
{
for(i=400;i>0;i--);
}
}
/*
*===================Function======================
*Name:key_handler
*Discription:whenthekeyispressed,
*theIRQservicewillberun.
*=================================================
*/
staticvoid__irqkey_handler(void)
{
Beep_run();
if(rEINTPEND&(1<<8))
{