- for (;;)
- {
- dwVal = rINTPND;
- if ((dwVal & MASK_BIT(21)) == 0)
- {
- continue;
- }
- //EXTINTPND 寄存器,判断是哪个外部中断触发
- dwVal = rEXTINTPND;
- if ((dwVal & MASK_BIT(EXTINT4)) != 0)
- {
- rEXTINTPND |= MASK_BIT(EXTINT4);
- //外部中断4 产生了,点亮LED1
- if(rPDATC & MASK_BIT(LED1))
- {
- sysUtilsLightLed (LED1, FALSE);
- printf("Turn off %s",leds[LED1 - 1]);
- }
- else
- {
- sysUtilsLightLed (LED1, TRUE);
- printf("Turn on %s",leds[LED1 - 1]);
- }
- printf(" *** rINTPND = %02X , rPDATC = %02X ***\n",rINTPND, rPDATC);
- sysUtilsDelay(10000000); //延时
- rEXTINTPND &= ~MASK_BIT(EXTINT4);//在这里清零
- rINTPND = 8; //还原rINTPND
- continue;
- }
- if ((dwVal & MASK_BIT(EXTINT5)) != 0)
- {
- //......
- }
- if ((dwVal & MASK_BIT(EXTINT6)) != 0)
- {
- //......
- }
- if ((dwVal & MASK_BIT(EXTINT7)) != 0)
- {
- rEXTINTPND |= MASK_BIT(EXTINT7);
- //外部中断7 产生了,点亮LED1,2,3
- sysUtilsLightLed (LED_ALL, FALSE);
- }
- //最后清除中断位
- rI_ISPC |= MASK_BIT(21);
- rI_ISPC = dwVal;
- }
我用以上代码实现按键控制LED(按一次灯亮,再按一次灯熄灭),开始的时候灯不亮,按下按键,灯亮后进入sysUtilsDelay延时,但是延时完之后灯又熄灭了
是不是我代码有问题?
我用ARM7+S3C44B0X(SUMSUNG)
if(rPDATC & MASK_BIT(LED1))
{
sysUtilsLightLed (LED1, FALSE);
printf("Turn off %s",leds[LED1 - 1]);
}
看了一下,像是没有中断的时候
你这句执行了,呵呵,把你的灯给关了
再理一下逻辑看看
感谢两位参与,后来我发现是键盘缓存的问题,用以下方法解决了:
#define INTERNVAL 0x0000a000 //有效间隔
void KeyLedTest (void)
{
U32 dwVal;
int internval = INTERNVAL;
int i;
//设置IO 口PORT G
rPCONG |= 0xff00;
//设置中断
rINTMOD &= ~MASK_BIT(21);
rINTCON &= ~MASK_BIT(1);
//设置EXTINT4,5,6,7中断模式,我们这里使用低电平触发
rEXTINT &= 0xffff; //先清除EXTINT4,5,6,7的相应设置bit位
for (;;)
{
dwVal = rINTPND;
internval++;
if(internval >= INTERNVAL)
internval = INTERNVAL;
if((dwVal & MASK_BIT(21)) == 0)
{
for(i = 0;i < 10000;i++){}
continue;
}
//EXTINTPND 寄存器,判断是哪个外部中断触发
dwVal = rEXTINTPND;
if (((dwVal & MASK_BIT(EXTINT4)) != 0) && (internval >= INTERNVAL))
{
printf("Status of LED1 is going to be changed.");
internval = 0;
rEXTINTPND |= MASK_BIT(EXTINT4);
//外部中断4 产生了,点亮LED1
if(rPDATC & MASK_BIT(LED1))
{
sysUtilsLightLed (LED1, FALSE);
printf("Turn off %s",leds[LED1 - 1]);
}
else
{
sysUtilsLightLed (LED1, TRUE);
printf("Turn on %s",leds[LED1 - 1]);
}
}
if ((dwVal & MASK_BIT(EXTINT5)) != 0)
{
//......
}
if (((dwVal & MASK_BIT(EXTINT6)) != 0) && (internval >= INTERNVAL))
{
//......
}
if (((dwVal & MASK_BIT(EXTINT7)) != 0) && (internval >= INTERNVAL))
{
rEXTINTPND |= MASK_BIT(EXTINT7);
//外部中断7 产生了,点亮LED1,2,3
sysUtilsLightLed (LED_ALL, FALSE);
}
//最后清除中断位
rI_ISPC |= MASK_BIT(21);
//rI_ISPC = dwVal;
rEXTINTPND &= ~(MASK_BIT(EXTINT4)|MASK_BIT(EXTINT5)|MASK_BIT(EXTINT6));
}
}