首页 > 代码库 > zedboard中OLED源码

zedboard中OLED源码

#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, "DALE I LOVE U");

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, "DO U LOVE ME ?

"); 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, "HAHA BYE"); 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; }


zedboard中OLED源码