Board logo

标题: [求助]按键中断问题? [打印本页]

作者: cxm23    时间: 2007-9-21 08:07     标题: [求助]按键中断问题?

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

执行这段程序,按一次按键后就会重复执行那个按键的中断程序,为什么??

怎么让它停下来[em06]
作者: kzw    时间: 2007-9-22 01:21

不会重复执行中断服务程序的,你看看我们论坛上或者altera官方的关于按键中断程序。
作者: cxm23    时间: 2007-9-22 14:28

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编辑过]


作者: jack4211    时间: 2008-5-16 11:20

QUOTE:
以下是引用kzw在2007-9-22 1:21:00的发言:
不会重复执行中断服务程序的,你看看我们论坛上或者altera官方的关于按键中断程序。

版主太不负责任了.我们能找的到还会来求救吗?


作者: thanksat    时间: 2008-5-16 20:51

楼上的,说话不应该这样吧!

LZ的这个程序问题我看出来了,与ISR无关,主程序有问题

我建议你用硬件断点一步步调试就很快可以找出来,哥们我只是想让你知道怎么样解决问题,祝你好运!

[em01][em01][em01]




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0