Zedboard不同GPIO形式 控制OLED显示

参考链接:
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;
}

送自己一朵小花~~♪(^∇^*)
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值