20 分钟建立一个NIOS II 开发环境
2012-12-04
标签:

编译项目

从 Processing 菜单选Start compilation,或者Cntl+L,开始编译。出现警告信息可以不管,等待编译结束。

配置 FPGA

从Tools 菜单选择Programmer,选择JTAG 模式和对应的sof 文件,点击Start,

开始下载,如果成功,那么开始进入软件调试环境。

启动 NIOS II IDE 环境

关闭 Programmer,打开顶层文件。快捷方法就是点图标

双击 low_cost_1C20 系统模块,进入SOPC Builder。

选择 Run Nios II IDE,进入IDE 开发环境。

建立软件工程文件

选择 File-》New -》Project 选项。

选择 C/C++ Application, 点击Next。

从模板中选择 Hello LED,其他设置按默认设置,点击Finish。

编译工程文件

选中 hello_led_0,按右键,选择 Build Project

结束后,右下方的控制台会提示编译结束。

运行程序

从菜单中选择 Run-》Run…,弹出对话框

点击 New,会自动生成一个系统配置。

点击 Apply,然后点击Run。

开始下载程序到 SDRAM,并运行起来。

观察板上的 4 个LED,大概没隔4 秒,LED 会轮流闪烁一次。

恭喜您,第一个 C 程序在NIOSII CPU 上已经运行起来了。

如果感兴趣,可以修改源文件,然后在编译,运行,看看 LED 有什么变化

以下是一个让 LED 闪烁更频繁的例子:

int main (void) __attribute__ ((weak, alias ("alt_main")));

/*

* Use alt_main as entry point for this free-standing application

*/

int alt_main (void)

{

alt_u8 led = 0x2;

alt_u8 dir = 0;

volatile int i;

/*

* Infinitly shift a variable with one bit set back and forth, and write

* it to the LED PIO. Software loop provides delay element.

*/

while (1)

{

if (led & 0x09) // 我们板上只有4个LED,所以当led的Bit3和Bit0有效的时候,

//就改变方向;

{

dir = (dir ^ 0x1);

}

if (dir)

{

led = led >> 1;

}

else

{

led = led << 1;

}

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);

/*

* The delay element in this design has been written as a while loop

* to avoid confusing the software debugger. A tight, one line software

* delay loop such as:

* for(i=0; i<200000; i++);

* can cause problems when it is stepped through using a software

debugger.

* The while loop below produces the same behavior as the for loop shown

* above, but without causing potential debugger problems.

*/

i = 0;

while (i<100000) //加快闪烁间隔

i++;

}

return 0;

}

共 2 页   上一页12
可能会用到的工具/仪表
相关文章
推荐文章
热门文章
章节目录
本站简介 | 意见建议 | 免责声明 | 版权声明 | 联系我们
CopyRight@2024-2039 嵌入式资源网
蜀ICP备2021025729号