资源描述:
《Nios II按键中断调试程序及经验》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、NiosII按键中断调试程序及经验软件:QuatusII6.1,NiosII6.1硬件:EP1C3T144FPGA开发板实验目的:熟悉niosII开发,掌握中断程序调试系统配置:CPU+OnChipRam(4K)+LED_PIO+BUTTON_PIO功能描述:按键实现中断,使led亮或灭led配置成开发板上的led0,led1,led2,led3按键采用简单按钮B17,B18,19,B20不给过多注释了(其实注释够多了)#include#include#include"sys/alt_irq.h"#include"altera_
2、avalon_pio_regs.h"#include"system.h"/*Avariabletoholdthevalueofthebuttonpioedgecaptureregister.*/volatileintedge_capture;#ifdefBUTTON_PIO_BASE/*按键中断服务程序*/staticvoidhandle_button_interrupts(void*context,alt_u32id){ /*Castcontexttoedge_capture'stype.Itisimportantthatthisbe *decla
3、redvolatiletoavoidunwantedcompileroptimization. */ volatileint*edge_capture_ptr=(volatileint*)context; /*StorethevalueintheButton'sedgecaptureregisterin*context.*/ *edge_capture_ptr=IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); /*ResettheButton'sedgecaptureregister.*/
4、 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE,0);}/*Initializethebutton_pio.*/staticvoidinit_button_pio(){ /*Recasttheedge_capturepointertomatchthealt_irq_register()function *prototype.*/ void*edge_capture_ptr=(void*)&edge_capture; /*Enableall4buttoninterrupts.*/ IOW
5、R_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE,0xf); /*Resettheedgecaptureregister.*/ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE,0x0); /*Registertheinterrupthandler.*/ alt_irq_register(BUTTON_PIO_IRQ,edge_capture_ptr, handle_button_interrupts);}#endifi
6、ntmain(void)__attribute__((weak,alias("alt_main")));intalt_main(void){ alt_irq_init(ALT_IRQ_BASE);//necessary,enableinterrupts alt_sys_init(); //unnecessary alt_io_redirect(ALT_STDOUT,ALT_STDIN,ALT_STDERR);//unnecessary init_button_pio(); while(1) { switch(edge_cap
7、ture) { case0x01: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xFF); break; case0x02: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0x00); break; case0x04: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xFF); bre
8、ak; case0x08: