一. 实现功能: 流水灯;
二. 实验进程:
1. 建立工程RunningLED,SOPC系统RunningLED_System;
Note: 1. 定时器在系统中主要是产生一个固定间隔的中断信号,让CPU改变LED的状态。因此Period设置为500ms,表示灯的状态500ms改变一次;
2. Timer组件需要分配一个IRQ号;系统IRQ号可以是0到31的整数,数值越小优先级越高;
2. 用符号框图完成顶层实体,分析综合,分配引脚;
3. Open Nios II ID, Switch Workspace, 新建Blank Project,执行相关优化(Release & -Os);
Notes: 1. 取消Clean exit & Support C++前的勾,因为程序不会退出,也不包含C++库;
2. 选中Program never exits, Reduced device drivers, Small C library以减小程序体积;
3. 当有LCD输出时,则不能勾选Reduced device drivers;
4. 新建Source File->main.c;
#include"system.h" #include<sys/alt_irq.h> //Timer need interrupt; #include"alt_types.h" #include<io.h> //Internal Timer Overflow interrupt static void timer_overflow(void* context, alt_u32 id) { IOWR(TIMER_BASE, 0, 0); if(*(alt_u8 *)context&0x80) { *(alt_u8 *)context=0x01; } else { *(alt_u8 *)context=*(alt_u8 *)context<<1; } IOWR(PIO_LEDG_BASE, 0, *(alt_u8 *)context); return; } int main() { alt_u8 led=0x01; //Register Interrupt Service Routine(ISR) alt_irq_register(TIMER_IRQ, (void*)&led, timer_overflow); while(1); }