#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <io.h>
//#include"define.h"
#include"lcd.h"
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "sys/alt_irq.h"
#include "alt_types.h"
volatile alt_u32 edge_capture;
//申明捕获寄存器内容的变量
static void key_interrupts(void* context,alt_u32 id)//按键中断服务函数
{
volatile alt_u32*edge_capture_ptr=(volatile alt_u32*)context;
*edge_capture_ptr=IORD_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);
}
static void init_button_pio()//按键初始化函数
{
void * edge_capture_ptr=(void*)& edge_capture;
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE,0x00ff);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0x0000);
alt_irq_register(KEY_IRQ, edge_capture_ptr, key_interrupts);
}
int main (void) __attribute__ ((weak, alias ("alt_main")));
int alt_main(void)
{alt_u8 led,count;
alt_u8 code_led[]={0xf,0x0};
alt_irq_init(ALT_IRQ_BASE); //使能中断
init_button_pio();
while(1)
{
while(edge_capture)
{
edge_capture=0;
if(count<0xf)
{count++;}
else
{count=0;}
led=code_led[count];
//IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE,0);
IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE,led);
}
}
return 0;
}
其中alt_irq_init(ALT_IRQ_BASE);不能忘记。