您的位置:首页 > 移动开发 > IOS开发

nios II--实验7——数码管IP软件部分

2016-02-29 21:08 387 查看

软件开发

首先,在硬件工程文件夹里面新建一个software的文件夹用于放置软件部分;打开toolsàNios II 11.0 Software Build Tools for Eclipse,需要进行Workspace Launcher(工作空间)路径的设置,需要注意的是路径中不要含有空格等,然后单击OK即可。





新建工程。单击File -> New -> Nios II Application and BSP from Template,弹出Nios II Application and BSP from Template对话框。先选择对应的SOPC系统,单击SOPC Information File name后面的浏览按钮,选择之前硬件部分做好的软核文件,后缀名为.sopcinfo,这里一定要注意,选择的文件一定要对应起来,否则会因为软硬不匹配导致系统失败。这里选择的lab6_seg.sopcinfo,然后系统会自动读取CPU name,不用再进行设置,下面填写Project name,这里填写为lab6_seg,工程模板(Project template)使用默认的即可。然后单击Finish完成即可。这时候会在左侧的Project Explorer中生成两个工程文件。



代码设计具体看源工程



右击工程,选择Nios II -> BSP Editor,进入Nios II BSP Editor配置界面。主要在main选项卡下hall中进行配置。然后单击Generate,生成BSP库。生成完成后,单击Exit退出即可。





编译工程。右击选择Build Project。第一次编译的话,时间也会比较常,耐心等待一下。

编译完成后,先将.sof文件下载到FPGA;

 

右击工程,选择Run As -> Nios II Hardware,弹出Run Configurations对话框,默认Project选项卡中Project name和Project ELF file name应该都是有内容的,没有的选一下。然后进入Target Connection选项卡,Connections中如果没有东西的话,单击右侧的Refresh Connection来查找下载器,查找后单击System ID Prroperties…,进行系统ID检测,检查是否是之前设置的ID号,无误后点击Apply,然后再点击Run,这是程序会被自动下载,最终在Nios II Console选项卡中会显示下载完成后程序运行的结果。





运行结果,板子上的数码管进行计数显示。



实验代码

/*

* "Hello World" example.

*

* This example prints 'Hello from Nios II' to the STDOUT stream. It runs on

* the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example

* designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT

* device in your system's hardware.

* The memory footprint of this hosted application is ~69 kbytes by default

* using the standard reference design.

*

* For a reduced footprint version of this template, and an explanation of how

* to reduce the memory footprint for a given application, see the

* "small_hello_world" template.

*

*/

 

#include "system.h"

#include "altera_avalon_pio_regs.h"

#include "altera_avalon_timer_regs.h"

#include "alt_types.h"

#include "sys/alt_irq.h"

#include <stdio.h>

#include <unistd.h>

#include <io.h>

#include <string.h>

/********************************

Variables

********************************/

// 数码管显示字符对应的 16 进制数

alt_u8 segtab[16]
=
{0xc0,
0xf9,
0xa4,
0xb0,
0x99,
0x92,
0x82,
0xf8,

0x80,
0x90,
0x88,
0x83,
0xc6,
0xa1,
0x86,
0x8e};
// 0-F

unsigned
char led_buffer[8]={0};

unsigned
char bittab[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};

static
unsigned
char cnt=4;

/********************************

Functions

********************************/

void init_timer(void);

/*

*================================functions================================

Name: main

Description:

*=========================================================================

*/

int main(void)

{

unsigned
char i=0,k=0;

unsigned
char buf[20];

int j=0;

init_timer();

while(1){

sprintf(buf,"%06u",j++);

for(i=0;i<6;i++){

led_buffer[i]
= buf[5-i]-'0';

}

usleep(500000);

}

return
0;

}

void ISR_handle_timer(void
*context)

{

IOWR_ALTERA_AVALON_PIO_DATA(SEG_WEI_BASE,
0xff);

IOWR_ALTERA_AVALON_PIO_DATA(SEG_WEI_BASE, bittab[cnt]);

IOWR_ALTERA_AVALON_PIO_DATA(SEG_DUAN_BASE, segtab[led_buffer[cnt]]);//

cnt++;

if(cnt==4)

cnt=0;

IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE,
0x00);// 清除中断标志寄存器

}

void init_timer(void)

{

IOWR_ALTERA_AVALON_TIMER_STATUS( TIMER_BASE,
0x00
);
// 清除中断标志寄存器

IOWR_ALTERA_AVALON_TIMER_PERIODL( TIMER_BASE,
200000
);
// 设置定时周期 1s

IOWR_ALTERA_AVALON_TIMER_PERIODH( TIMER_BASE,
200000>>16
);

IOWR_ALTERA_AVALON_TIMER_CONTROL( TIMER_BASE,
0x07
);
// 使能中断

alt_ic_isr_register( TIMER_IRQ_INTERRUPT_CONTROLLER_ID, TIMER_IRQ,

ISR_handle_timer,
NULL,
0x0
);
// 注册中断

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: