原创 MicroBlaze控制LED实验三(编写简单的LED控制IP核)

2010-1-21 13:44 4922 11 11 分类: FPGA/CPLD
软件环境为Xilinx Platform studio 11.3,开发板为红色飓风2代Xilinx版
1.在XPS中创建一个新的Project,加入一个GPIO核,GPIO的Data Width改为4,直到finish
2.Create or Import Peripheral
3.Create templates for a new peripheral, next
4.To an XPS Project,next
5.name:led_ip, next
6.IPIF Services:选择User logic software register,next
7.Peripheral implement support:选择in verilog和generate template driver files,直至finish
8.打开MPD文件,在“ports”下面加入PORT led_o = "", DIR = O, VEC = [0:3],save
9.打开led_ip.vhd
在“USER ports added here”下面加入“led_o  : out std_logic_vector(0 to 3);”(有两处)
在“USER ports mapped here”下面加入"led_o => led_o,",save
10.打开user_logic.v文件
在“USER ports added here” 下面加入“led_o,”
在第二个USER ports added here下面加入“output [0:3] led_o;”
在“USER nets declarations added here, as needed for user logic”下面加入“reg [0:3] led_r;”
在“USER logic implementation added here”下面加入如下代码:
always@(posedge Bus2IP_Clk)begin
if(Bus2IP_Reset)
led_r<=4'b0000;
else
if(slv_reg_write_sel)
led_r<=Bus2IP_Data[0:3];
end

always@(posedge Bus2IP_Clk)begin
if(Bus2IP_Reset)
led_o<=4'b0000;
else
begin
case(led_r)
4'b1000:led_o<=4'b1000;
4'b0100:led_o<=4'b1100;
4'b0010:led_o<=4'b1110;
4'b0001:led_o<=4'b1111;
default:led_o<=4'b0000;
endcase
end
end
保存文件
12.在IP Catalog中找到刚建立的IP(在最下面),Add,并连接到PLB总线上
13.在Ports标签栏中把IP核连上(make external)
13.在Addresses标签栏中“generate addresses"
14.在UCF文件中设置好管脚,其中led_ip的管脚连接如下所示:
Net led_ip_0_led_o_pin<0> LOC=p204;
Net led_ip_0_led_o_pin<1> LOC=p203;
Net led_ip_0_led_o_pin<2> LOC=p200;
Net led_ip_0_led_o_pin<3> LOC=p199;
save
15.硬件部分弄完了就可以生成bitstream,添加软件部分的程序
16.generate bitstream结束以后,在Application标签栏中把"Project:TestApp_Memory_microblaze_0"中的.c文件去掉,在Sources里Add new file,加入如下代码:
#include "xparameters.h"
#include "xgpio.h"
#include "led_ip.h"

//====================================================

int main (void) 
{
XGpio push;
       int i, psb_check;
       // define instance pointer for LEDs device
       
       XGpio_Initialize(&push, XPAR_PUSH_BUTTONS_DEVICE_ID);
       XGpio_SetDataDirection(&push, 1, 0xffffffff);
       
       while (1)
       {
         psb_check = XGpio_DiscreteRead(&push, 1);   
         psb_check=psb_check<<28;
         // output pushbuttons value on LEDs device
         LED_IP_mWriteReg(XPAR_LED_IP_0_BASEADDR, 0x00000000, ~psb_check);
         
         for (i=0; i<999999; i++);
       }
}
save
17.generate libraries and BSPs
18.把“Project:TestApp_Memory_microblaze_0”中的”headers"中的文件去掉,加入led_ip.h文件(led_ip.h文件的路径为lab3_3/drivers/led_ip_v1_00_a/src/led_ip.h)
19.在Application标签中,右键点击”Project:TestApp_Memory_microblaze_0“,选择Build Project
20.Download Bitstream






文章评论0条评论)

登录后参与讨论
我要评论
0
11
关闭 站长推荐上一条 /2 下一条