简单的nios II 流水灯 软件部分

声明:本文为灵. yāo编写,版权所有,欢迎学习讨论,如需转载请标明出处http://www.cnblogs.com/China_memory

Nios II 流水灯的 硬件部分已经完成

现在进行软件部分

打开Nios II IDE

New 一个 Project >>> Nios II C/C++ Application

工程项目配置

Next>    Finish

设置 工程 Properties

设置如下图

然后是C/C++ Build设置

设置完成后,先编译一次,产生system.h文件

快捷键 Ctrl + B

第一次便宜较慢,耐性等待,可以做一下眼保健操什么的,很有必要的啊。

编译完成,提示

**** Build of configuration Debug for project led_syslib ****

make -s all includes
Build completed in 2.235 seconds

这下我们有必要查看一下系统头文件system.h

 

这些都是必须要了解的,以后的编程就得依据这个文件对硬件的描述,其中主要包含了 NAME名字、TYPE类型、 BASE基地址、IRQ中断号 等等

由于该程序模板已经包含了hello_word.c,能够用Jat guart 输出 “hello form Nios II”

于是我们可以直接使用hello_word.c

这样我们直接run as Nios hardware

不过结果出乎意料,不是我想要的结果

Console 栏内

总是收到的是收到的如此乱码

不知道是什么原因,有知道原因的可以和我交流一下,谢谢。

于是我把hello_word.c改了一下

 
  
#include < stdio.h >

int main()
{

while ( 1 )
{
printf(
" hello form Nios II!\n " );
}
return 0 ;
}

这样,一直就收到了hello form Nios II

出现上面的问题好像是printf后还要关printf一样,不知是jtag uart 还是哪里的问题

期待有人和我交流。谢谢

接下来进行流水灯

我还是用黒金的方式来做,这是一种良好的编程习惯

首先新建一个inc文件夹用于保存头文件,在inc内新建一个sopc.h

 
  
#ifndef SOPC_H_
#define SOPC_H_

#include
" system.h "

#define _LED

typedef
struct
{
unsigned
long int DATA;
unsigned
long int DIRECTION;
unsigned
long int INTERRUPT_MASK;
unsigned
long int EDGE_CAPTURE;
}PIO_STR;

#ifdef _LED
#define LED ((PIO_STR *)LED_PIO_BASE)
#endif

#endif /*SOPC_H_*/

以上的方法借鉴了黑金开发板教程,在此致谢。

然后新建一个mian文件夹,在内新建一个mian.c,删除hello_word.c

 
  
#include < stdio.h >
#include
" ../inc/sopc.h "
void delay( void )
{
unsigned
int i;
i
= 3000000 ;
while (i > 0 )
{
i
-- ;
}
}
int main()
{
int i;
while ( 1 )
{
for (i = 0 ;i < 4 ;i ++ )
{
LED
-> DATA = ~ ( 1 << i);
printf(
" D%d灯在亮\n " ,i);
delay();
}
}

return 0 ;
}

然后 Build Project

Info: (led.elf) 53 KBytes program size (code + initialized data).
Info:           8138 KBytes free for stack + heap.
Hardware simulation is not enabled for the target SOPC Builder system. Skipping creation of hardware simulation model contents and simulation symbol files. (Note: This does not affect the instruction set simulator.)
Post-processing to create cfi_flash.flash
Build completed in 7.797 seconds

编译成功

接上jtag

下载硬件的led.sof

然后 run as Nios hardware

现在你看到效果了

如果需要调试的话,就 Debug as Nios hardware

Nios 流水灯就完成了。

讨论:

我用NIOS II IDE提供的API来写时。

mian.c内容

 
  
#include < stdio.h >
#include
" system.h "
#include
" altera_avalon_pio_regs.h "
void delay( void )
{
unsigned
int i;
i
= 3000000 ;
while (i > 0 )
{
i
-- ;
}
}

int alt_main( void )
{
unsigned
char led_data;

while ( 1 )
{
for (led_data = 0 ;led_data < 4 ;led_data ++ )
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE,
~ ( 1 << led_data));
printf(
" D%d灯在亮\n " ,led_data);
delay();
}
}
return 0 ;
}

流水灯能工作,但Console没收到哪个灯在亮的信息

编译后的存储器占用也不一样

Info: (led.elf) 39 KBytes program size (code + initialized data).
Info:           8152 KBytes free for stack + heap.
Hardware simulation is not enabled for the target SOPC Builder system. Skipping creation of hardware simulation model contents and simulation symbol files. (Note: This does not affect the instruction set simulator.)
Post-processing to create cfi_flash.flash
Build completed in 7.609 seconds

不知道是什么原因的。

 期待与您交流

转载于:https://www.cnblogs.com/China_memory/archive/2010/09/29/1837769.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值