实验 使用 vivado zedboard GPIO 开关 开控制 LED

1.建工程

我使用 vivado 2013.4

创建新工程 next –next

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

选择 board – zedboard –next –finsh

就创建完了。

 

2.PL端 IP核添加与连线

创建一个空的 Diagram

Create Block Design -》点 ok

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

搜索 zynq 第一个

然后点击 Run Block Automation  自动配置

点击  添加 GPIO

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

选择 S_AXI    变成下图  

系统自动添加了一些IP

继续点击 Run Connection Automation  - GPIO

选择 led_8bits  - OK

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

就完成了

  

点击  红圈处验证一下。

 

3.生成 bit 的过程

点击 Source  - design_1  右键 Create HDLWrapper  - OK

然后  Synthesis Implementation Bitstream 依次过一遍

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

4.输出到SDK

 

选上 launch SDk OK  就启动SDK

我的 SDK

点击 FILE – new –>  Application project

选一个 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 ofthe 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 XGpioLED_Ptr;//定义GPIO指针

23    staticXGpio SWS_Ptr;

24    intXStatus;

25    intnum = 0;

26    //初始化 LED

27    XStatus = XGpio_Initialize(&LED_Ptr,XPAR_AXI_GPIO_0_DEVICE_ID);

28    if(XST_SUCCESS !=XStatus)

29             print("GPIOINIT 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("GPIOINIT 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

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

可以看到结果  64 + 1

7 1   开关是开的

表示所以 led 也亮了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kobesdu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值