实验 使用 vivado zedboard GPIO 开关 开控制 LED
2015-07-31 18:33
666 查看
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
也亮了
我使用 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
也亮了
相关文章推荐
- datalist 的用法。也是增删改查,但是比较智能。用数据绑定的方式,可以有不同的显示方法,下面是对一个表的增删改查的参考代码
- Activity的生命周期,BACK键和HOME键生命周期
- Windows 10使用体验
- docker是个好东西啊
- redis3.0.3集群安装详细步骤
- Vivado+Zedboard之OLED驱动
- Oracle rownum详解
- CryEngine的Modular Behavior Tree简介
- js判断数据类型
- SDWebImage
- 五毛的cocos2d-x学习笔记07-计时器、数据读写、文件读写
- Haproxy 主备配置
- A. Set of Strings
- 记:XE8下的UTF8DECODE函数与D7的有区别。
- Bootstrap组件之导航条
- 自定义ArcView-构造拓展性高的view
- Jax
- 手动编译安装LAMP架构,并且实现nagios图形化监控(九)
- [LeetCode] Search in Rotated Sorted Array II
- HDU1210