参考链接:
1. http://blog.chinaaet.com/yyiyy/p/39029# 从0开始学Zedboard(3)GPIO控制OLED
2. http://blog.chinaaet.com/carlpc/p/39775# GPIO控制–MIO和EMIO的使用(VIVADO+PS+PL)
3. http://blog.chinaaet.com/cuter521/p/35978 Vivado的嵌入式开发 ——PS+PL实践
4. http://blog.csdn.net/shangguanyunlan/article/details/53222673 使用vivado进行zedboard的OLED测试(创建IP核)
这次实验,利用AXI_GPIO连接BTNR,PS通过EMIO连接BTNU,通过PS GPIO连接BTN8、BTN9,对三种方式的GPIO均进行了控制演示。如果没有做过OLED的测试,建议先进行参考链接4.
利用PS_GPIO、AXI_GPIO、EMIO分别控制OLED来显示不同的页面。
首先是建立VIVADO工程。OLEDIP核建立参考链接4,里面有详尽的说明。按照下图建立工程。(里面部分内容参考链接2.4)
1.vivado硬件设计如下:
2.添加自己已经创建的IP核(没有,就自己创建,步骤参考链接4)
在vivado中,添加IP视图空白处,右键选择IP Setting
打开对话框后,点击IP Repositories的+号,找到之前创建的IP核地址(仓库),点击添加后,IP核自动出现,如下图:
3.I/O口约束文件配置如下:
4.板子效果:
5.主函数:
/*
* main.c
*/
#include <stdio.h>
#include "platform.h"
#include "xil_types.h"
#include "xgpio.h"
#include "xparameters.h"
#include "xgpiops.h"
#include "xil_io.h"
#include "oled.h"
//extern char inbyte(void);//调用inbyte接收一个字节输入函数
extern XGpioPs_Config XGpioPs_ConfigTable[XPAR_XGPIOPS_NUM_INSTANCES];
//int
main()
{
static XGpioPs psGpioInstancePtr;
XGpioPs_Config*GpioConfigPtr;
static XGpio GPIOInstance_Ptr;
int xStatus,start,end;
u32 Readstatus1,Readstatus2;
int iPinNumberld9 = 7; /*Ld9 is connected to MIO pin 7*/
int iPinNumberbtn8 = 50;/*Btn8 is connected to MIO pin 50*/
int iPinNumberbtn9 = 51;/*Btn9 is connected to MIO pin 51*/
int iPinNumberBTNU = 54;/*BTNU is connected to EMIO pin 54*/
init_platform();
print("##### Application Starts #####\n\r");
print("\r\n");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-1 :AXI GPIO Initialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define XPAR_AXI_GPIO_0_DEVICE_ID 0//因为没有报错的错误,自己添加的define
xStatus = XGpio_Initialize(&GPIOInstance_Ptr,XPAR_AXI_GPIO_0_DEVICE_ID);
if(XST_SUCCESS != xStatus)
print("GPIO INIT FAILED\n\r");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-2 :AXI GPIO Set the Direction
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XGpio_SetDataDirection(&GPIOInstance_Ptr, 1, 1);//input
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-3 :PS GPIO Intialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
if(GpioConfigPtr == NULL)
return XST_FAILURE;
xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr,
GpioConfigPtr,
GpioConfigPtr->BaseAddr);
if(XST_SUCCESS != xStatus)
print(" PS GPIO INIT FAILED \n\r");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-4 :PS GPIO pin setting to Output
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumberld9,1);
XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberld9,1);
XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumberbtn8,0);
XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberbtn8,1);
XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumberbtn9,0);
XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberbtn9,1);
XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumberBTNU,0);
XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberBTNU,1);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-5 :OLED Intialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OLED_Init();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-6 :press btn8 to start Demo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OLED_ShowString(0,0, "BTN8 to start");
OLED_Refresh_Gram();
while (1){
start=XGpioPs_ReadPin(&psGpioInstancePtr, iPinNumberbtn8);
if(start){
XGpioPs_WritePin(&psGpioInstancePtr,iPinNumberld9,1);
print("###################### Demo Starts ########################\r\n");
OLED_ShowString(0,0, "zed is good");
OLED_ShowString(0,16, "BTNR to go on");
OLED_Refresh_Gram();
break;
}
end=XGpioPs_ReadPin(&psGpioInstancePtr, iPinNumberbtn9);
if(end){
XGpioPs_WritePin(&psGpioInstancePtr,iPinNumberld9,0);
OLED_Clear();
break;
}
}
while(1){
Readstatus1 = XGpio_DiscreteRead(&GPIOInstance_Ptr, 1) ;//读BTNR
if(Readstatus1){
OLED_ShowString(0,0, "zed is girl");
OLED_ShowString(0,16, "BTNU to go on");
OLED_Refresh_Gram();
break;
}
}
while(1){
Readstatus2 = XGpioPs_ReadPin(&psGpioInstancePtr, iPinNumberBTNU) ;//读BTNU
if(Readstatus2){
OLED_Clear();
OLED_ShowString(0,0, "glad to see you");
OLED_ShowString(0,16, "BTN9 to end");
OLED_Refresh_Gram();
}
end=XGpioPs_ReadPin(&psGpioInstancePtr, iPinNumberbtn9);
if(end){
XGpioPs_WritePin(&psGpioInstancePtr,iPinNumberld9,0);
OLED_Clear();
break;
}
}
print("\r\n");
print("***********\r\n");
print("BYE \r\n");
print("***********\r\n");
cleanup_platform();
return 0;
}
送自己一朵小花~~♪(^∇^*)