volatile int edge_capture;
#ifdef KEY_BASE
static void handle_button_interrupts(void* context, alt_u32 id)
{
volatile int* edge_capture_ptr = (volatile int*) context;
/* 存储按钮的值到边沿捕获寄存器中 */
*edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE);
/* 复位边沿捕获寄存器 */
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE, 0);
}
/* 初始化button_pio */
static void init_button_pio()
{
/* Recast the edge_capture pointer to match the alt_irq_register() function
* prototype. */
void* edge_capture_ptr = (void*) &edge_capture;
/* 开放全部4个按钮的中断 */
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE, 0xf);
/* 复位边沿捕获寄存器*/
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE, 0x0);
/* 登记中断源 */
alt_irq_register( KEY_IRQ, edge_capture_ptr, handle_button_interrupts );
}
#endif
int main (void)
{
init_button_pio();
while(1)
{
switch(edge_capture)
{
case 0x01:
printf("key=1");
break;
case 0x02:
printf("key=2");
break;
}
}
}
完整程序如上,按一次按键1后,照理说应该只进行了一次边沿触发,可是屏幕上却不断打印出key=1,为什么?是不是要清除什么标志?
[此贴子已经被作者于2007-9-22 14:32:37编辑过]
版主太不负责任了.我们能找的到还会来求救吗?
楼上的,说话不应该这样吧!
LZ的这个程序问题我看出来了,与ISR无关,主程序有问题
我建议你用硬件断点一步步调试就很快可以找出来,哥们我只是想让你知道怎么样解决问题,祝你好运!
[em01][em01][em01]欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |