标签:
?
代码设计如下,具体看源工程
?
/* * "Hello World" example. * * This example prints ‘Hello from Nios II‘ to the STDOUT stream. It runs on * the Nios II ‘standard‘, ‘full_featured‘, ‘fast‘, and ‘low_cost‘ example * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT * device in your system‘s hardware. * The memory footprint of this hosted application is ~69 kbytes by default * using the standard reference design. * * For a reduced footprint version of this template, and an explanation of how * to reduce the memory footprint for a given application, see the * "small_hello_world" template. * */ ? #include <stdio.h> #include "system.h" #include "unistd.h" #include "alt_types.h" #include "altera_avalon_pio_regs.h" #include "sys/alt_irq.h" alt_u8 key_flag = 0; void ISR_handle_button( void* context ) { key_flag = ~key_flag; printf("button interrupt!\n"); IOWR_ALTERA_AVALON_PIO_EDGE_CAP( BNT_PIO_BASE, 0x0 ); // clear the interrupt } void init_button_pio( void ) { IOWR_ALTERA_AVALON_PIO_IRQ_MASK( BNT_PIO_BASE, 0x1 ); // 使能按钮中断 IOWR_ALTERA_AVALON_PIO_EDGE_CAP( BNT_PIO_BASE, 0x0 ); // 清边沿捕获寄存器 alt_ic_isr_register(BNT_PIO_IRQ_INTERRUPT_CONTROLLER_ID, BNT_PIO_IRQ, ISR_handle_button, NULL,0x0 ); } int main() { int i; printf("Hello from Nios II!\n"); init_button_pio(); for( i=0; i<4; i++ ) { IOWR_ALTERA_AVALON_PIO_DATA( LED_PIO_BASE, 1<<i ); usleep( 10000 );//each one 0.5s delay } while(1) { if( key_flag ) { IOWR_ALTERA_AVALON_PIO_DATA( LED_PIO_BASE, 1); } else { IOWR_ALTERA_AVALON_PIO_DATA( LED_PIO_BASE, 0); } } return 0; } |
标签:
原文地址:http://www.cnblogs.com/logic3/p/5228888.html