|
#include <stdio.h>
#include "io.h"
#include "sys/alt_irq.h"
#include "system.h"
#define SHOW_SEG(DATA) IOWR(SEG_BASE,0,DATA);
static alt_u8 value = 0;
void handle_button_interrupts(void *content,alt_u32 id)
{
if( value == 10)
value = 0;
usleep(1000);
switch(value)
{
case 0:SHOW_SEG(0x40);break;
case 1:SHOW_SEG(0x79);break;
case 2:SHOW_SEG(0x24);break;
case 3:SHOW_SEG(0x30);break;
case 4:SHOW_SEG(0x19);break;
case 5:SHOW_SEG(0x12);break;
case 6:SHOW_SEG(0x03);break;
case 7:SHOW_SEG(0x78);break;
case 8:SHOW_SEG(0x00);break;
case 9:SHOW_SEG(0x10);break;
default:SHOW_SEG(0x40);break;
}
value ++ ;
IOWR(BUTTON_BASE,3,0x00);//reset the button's edge capture register
}
void init_button_pio()
{
SHOW_SEG(0x10);
//enable button interrupt
IOWR(BUTTON_BASE,2,0x01);
//Reset the edge capture register
IOWR(BUTTON_BASE,3,0x00);
//register the interrupt handler
alt_irq_register(BUTTON_IRQ,NULL,handle_button_interrupts);
}
int main()
{
init_button_pio();
return 0;
}
在这段code中,如果把"IOWR(BUTTON_BASE,3,0x00);//reset the button's edge capture register",调到"usleep(1000);"就会产生两次中断,不调则是一次中断,这是为什么? |
|