新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 在20分钟内建立一个NIOS II开发环境的方法

在20分钟内建立一个NIOS II开发环境的方法

作者:时间:2012-03-17来源:网络收藏

经过以上处理,就可以编译和下载程序了。
编译项目
从 Processing 菜单选Start compilation,或者Cntl+L,开始编译。出现警告信息可以不管,等待编译结束。

配置 FPGA
从Tools 菜单选择Programmer,选择JTAG 模式和对应的sof 文件,点击Start,
开始下载,如果成功,那么开始进入软件调试

启动 IDE
关闭 Programmer,打开顶层文件。快捷就是点图标

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

选择 Run Nios 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 程序在 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; i200000; 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 (i100000) //加快闪烁间隔
i++;
}
return 0;
}

本文引用地址:http://www.eepw.com.cn/article/149395.htm
上一页 1 2 下一页

评论


相关推荐

技术专区

关闭