ZedBord AXI_GPIO 使用教程

转载:http://www.cnblogs.com/rocbomb/archive/2014/07/29/3876683.html

前面我做了几个实验 都没有用过 开关,这一次用一用

发现 vivado 真的挺方便 所以 使用 vivado 开发

1.建工程

我使用 vivado 2013.4

image

创建新工程 –》 next –》next

image

勾选 Do not specify sources at this time   //这样跳过后面两个添加文件页面

image

选择 board –》 zedboard –》next –》finsh

就创建完了。

 

2.PL端 IP核添加与连线

image

创建一个空的 Diagram

Create Block Design -》点 ok

image

接下来 添加 IP核  可以点击 提示 Add IP  也可以点击 image

image

搜索 zynq 点 第一个

image

然后 点击 Run Block Automation  自动配置

imageimage

点击 image 添加 GPIO

image

接下来 会提示 Run Connection Automation 自动连线

选择 S_AXI    变成下图  

image

系统自动添加了 一些IP核

继续点击 Run Connection Automation  -》 GPIO

image

选择 led_8bits  -》 OK

image

同样的方法 添加  GPIO IP核  -》 Run Connection Automation 两次  选择 sws_8bits

就完成了

image

image  

点击  红圈处 验证 一下。

3.生成 bit 的过程

image

点击 Source  -》 design_1  右键 –》 Create HDL Wrapper  -》 OK

然后  Synthesis 、 Implementation 、Bitstream 依次过一遍

image

这个过程费时间。。  Synthesis 以后 一直点ok    最后 点击 Generate Bitstream

4.输出到SDK

 

image

image

选上 launch SDk 点 OK  就启动SDK 了

我的 SDK 是

点击 FILE –》 new –>  Application project

image

选一个 helloworld

复制以下代码

复制代码
 1 #include <stdio.h>
 2 #include "platform.h"
 3 #include "xparameters.h"
 4 #include "xgpio.h"
 5 #include "sleep.h"
 6 #include "platform.h"
 7 #include "xil_types.h"
 8 #include "xgpiops.h"
 9 
10 
11 /************************** Constant Definitions *****************************/
12 
13 /*
14  * The following constant maps to the name of the hardware instances that
15  * were created in the EDK XPS system.
16  */
17 #define XPAR_LEDS_ID XPAR_AXI_GPIO_0_BASEADDR  //AXI_GPIO_0 是添加的第一个 gpio 所以是 leds
18 #define XPAR_SWS_ID XPAR_AXI_GPIO_1_BASEADDR   //那么 这个自然是 开关了
19 
20 int main()
21 {
22     static XGpio LED_Ptr;//定义GPIO指针
23     static XGpio SWS_Ptr;
24     int XStatus;
25     int num = 0;
26     //初始化 LED
27     XStatus = XGpio_Initialize(&LED_Ptr,XPAR_AXI_GPIO_0_DEVICE_ID);
28     if(XST_SUCCESS != XStatus)
29             print("GPIO INIT FAILED\n\r");
30     XGpio_SetDataDirection(&LED_Ptr, 1,0x00);//通道1;设置方向 0 输出 1输入, 0x00表示8位都是输出
31     XGpio_DiscreteWrite(&LED_Ptr, 1,0x00);
32 
33     //初始化 开关
34     XStatus = XGpio_Initialize(&SWS_Ptr,XPAR_AXI_GPIO_1_DEVICE_ID);
35     if(XST_SUCCESS != XStatus)
36             print("GPIO INIT FAILED\n\r");
37     XGpio_SetDataDirection(&SWS_Ptr, 1,0xFF);//通道1;设置方向 0 输出 1输入 0xFF表示8位都是输入
38 
39 
40 
41     while(1){
42         num = XGpio_DiscreteRead(&SWS_Ptr, 1);  //从开关处 读数据
43         printf("Numb %d\n\r", num);
44         XGpio_DiscreteWrite(&LED_Ptr, 1,num);   //直接写入 led
45         usleep(1000);      //delay 1ms
46     }
47 
48     printf("end\n\r \n\r");
49     return 0;
50 }
复制代码

确保 zedboard 已经连到电脑上 并打开电源

先 xilinx Tools –> ProgramFPGA

image

然后 image  -> Run As –> Launch on Hardware (GDB)

image

可以看到 结果  64 + 1

image

IMG_20140729_223929

第 7 个 和 第 1 个  开关 是开的

表示 所以 led 也亮了

猜你喜欢

转载自blog.csdn.net/MaoChuangAn/article/details/85255654