关于mini2440的一个裸机程序——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));//设置K1的低电平中断
rEXTINT1&=~0xfff0f00f;
rEXTINT2&=~(0xf<<12);
rEINTPEND|=(1<<8)|(1<<11)|(1<<13)|(1<<14)|(1<<15)|(1<<19);//清除K1的中断标志
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对应
}
/*
*===================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))
{