一. 实现功能: 流水灯;

二. 实验进程:

  1. 建立工程RunningLED,SOPC系统RunningLED_System; 

[笔记]RunningLED Experiment

Note: 1. 定时器在系统中主要是产生一个固定间隔的中断信号,让CPU改变LED的状态。因此Period设置为500ms,表示灯的状态500ms改变一次;

   2. Timer组件需要分配一个IRQ号;系统IRQ号可以是0到31的整数,数值越小优先级越高;  

  2. 用符号框图完成顶层实体,分析综合,分配引脚;

[笔记]RunningLED Experiment

  3. Open Nios II ID, Switch Workspace, 新建Blank Project,执行相关优化(Release & -Os);

[笔记]RunningLED Experiment

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);
}

  

相关文章:

  • 2021-12-09
  • 2021-10-05
  • 2022-12-23
  • 2021-11-19
  • 2021-08-23
  • 2021-08-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-06
  • 2021-06-13
  • 2021-10-08
  • 2021-11-06
  • 2021-10-04
  • 2022-01-01
相关资源
相似解决方案