nios 自定义IP

本文详细介绍了一种使用Verilog语言实现的数码管驱动模块设计方法,并通过具体实例验证其功能。从模块定义到顶层文件编写,再到软件编程,全面展示了IP模块的设计流程。

首先用Verilog语言或者VHDL编写、或者用原理图来画硬件驱动,以数码管驱动为例子,编写Verilog如下:

复制代码
1 module sg7IP( 2 3  input reset, 4  input clk, 5  input avs_s1_write, 6  input [31:0]avs_s1_writedata, 7  input avs_s1_address, 8  output wire [7:0] oSEG7 9 ); 10 11  reg [7:0] sg7_r; 12  always @(posedge clk or posedge reset) 13 begin 14 if(reset) 15 sg7_r<=8'hf; 16 else if(avs_s1_write&&avs_s1_address==0) 17 sg7_r[7:0]<=avs_s1_writedata[7:0]; 18 19 end 20 assign oSEG7=~sg7_r; 21 endmodule 22
复制代码

 

 

然后编写一个顶层文件来调用sg7IP.v来测试验证上面的驱动是正常的。我这里编写了sg7top.v来作为顶层文件。

 

复制代码
1 module seg7top( 2 input iCLK_50, 3 input [0:0]iKEY, 4 output wire [6:0] oHEX0_D, 5 output wire oHEX0_DP 6 ); 7 8 9 sg7IP sg7ipu0( 10 .reset(!iKEY[0]), 11 .clk(iCLK_50), 12 .avs_s1_write(1'b1), 13 .avs_s1_writedata(32'd113), 14 .avs_s1_address(1'b0), 15 .oSEG7({oHEX0_DP,oHEX0_D[6:0]}) 16 17 endmodule 18
复制代码

分配管教,编译后下载到DE2-70的开发板中,数码管HEX0显示为F则表示硬件驱动正常。

 

 

然后打开SOPCBuilder,新建一个component。过程如下图。

 

 

 

添加sg7IP、onchipmemory、cpu、jtag uart组件,点击“生成”

 

 

完了后在QUARTUS II中修改sg7top.v

 

 

 

复制代码
1 module seg7top( 2 input iCLK_50, 3 input [0:0]iKEY, 4 output wire [6:0] oHEX0_D, 5 output wire oHEX0_DP 6 ); 7 8 9 nios_cpu nios_cpu_inst 10 ( 11 .clk_0 (iCLK_50), 12 .oSEG7_from_the_sg7IP_0 ({oHEX0_DP,oHEX0_D[6:0]}), 13 .reset_n (iKEY[0]) 14 ); 15 16 endmodule 17
复制代码

 

 

重新编译,下载。

打开NISO IDE。

新建空工程。

建立sg7.h

 

 

复制代码
1 #ifndef SEG7_H_ 2 #define SEG7_H_ 3 4 void SEG7_NUM(alt_u8 num); 5 6 7 #endif /*SEG7_H_*/ 8
复制代码

 

 

建立sg7.c

 

 

复制代码
1 #include "io.h" 2 #include "alt_types.h" 3 4 #include "system.h" 5 6 #include "SEG7.h" 7 8 #define SEG7_SET(seg_mask) IOWR(SG7IP_0_BASE,0,seg_mask) 9 10 static unsigned char szMap[] = { 11 63, 6, 91, 79, 102, 109, 125, 7, 12 127, 111, 119, 124, 57, 94, 121, 113 13 }; // 0,1,2,....9, a, b, c, d, e, f 14 15 16 void SEG7_NUM(alt_u8 num) 17 { 18 SEG7_SET(szMap[num]); 19 } 20
复制代码

 

建立main.c

 

复制代码
1 #include <stdio.h> 2 #include "system.h" 3 #include "unistd.h" 4 #include "alt_types.h" 5 #include "SEG7.h" 6 7 int main(void) { 8 alt_u8 i=0; 9 printf("My first IP"); 10 while(1){ 11 for(i = 0; i <10; i++) { 12 SEG7_NUM(i); 13 printf("Now print:%d\n",i); 14 usleep(1 * 1000 * 1000); 15 } 16 } 17 return 0; 18 } 19
复制代码

CTRL+B编译。

run as  NIOS II  hardware。

开发板中的数码管从0到9不断变化。IP编写测试完毕。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值