除是普通引脚的输入外,还可以用外部中断
普通引脚输入读取 代码如下
#define MP0_4CON (*(vola
tile unsigned long *)0xE0200340)
#define MP0_4DAT (*(volatile unsigned long *)0xE0200344)
#define MP0_4PUD (*(volatile unsigned long *)0xE0200348)
#define GPD0CON (*(volatile unsigned long *)0xE02000A0)//buzzer
#define GPD0DAT (*(volatile unsigned long *)0xE02000A4)//buzzer
#define GPH0CON (*(volatile unsigned long *)0xE0200C00)//key
#define GPH0DAT (*(volatile unsigned long *)0xE0200C04)//key
void init(void)
{
GPD0CON&= ~(0xF << 0);
MP0_4CON = (MP0_4CON & ~0xFFFF0000) | 0x11110000;
MP0_4PUD=(0x55<<16)&MP0_4PUD;
MP0_4DAT =0xf<<4;
GPH0CON &=0x00000FFF;
}
void main(void)
{
init();
while(1)//循环检测按键是否按下
{
if(GPH0DAT &(1<<3))//按键1未按下 k1 back
{
MP0_4DAT |=1<<4;//off
}
else//按键1按下
{
MP0_4DAT &=~(1<<4);//on
}
if(GPH0DAT &(1<<4))//k2 home
{
MP0_4DAT |=1<<5;//off
}
else
{
MP0_4DAT &=~(1<<5);//on
}
if(GPH0DAT &(1<<5))//k3 menu
{
MP0_4DAT |=1<<6;//off
}
else
{
MP0_4DAT &=~(1<<6);//on
}
if(GPH0DAT &(1<<6))//k4 power
{
MP0_4DAT |=1<<7;//off
}
else
{
MP0_4DAT &=~(1<<7);//on
}
if(GPH0DAT &(1<<7))//k5 search
{
MP0_4DAT |=0xf<<4;//all off
}
else
{
MP0_4DAT &=~(0xf<<4);//all on
}
}
}