#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);//Call inbyte receive a byte input function extern xgpiops _config Xgpiops_configtable[xpar_xgpiops_num_instances];//intmain () {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 are connected to mio pin 50*/int iPinNumberbtn9 = 51;/* Btn9 is connected to MIO pin 51*/int ipinnumberbtnu = 54;/*btnu are 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) because there is no error. 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:P s 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:P S 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:p ress 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);p rint ("###################### Demo starts ########################\r\n"); OLED_ Showstring (0,0, "DALE I Love U"), Oled_showstring (0,16, "Btnr to Go"), Oled_refresh_gram (); }end=xgpiops_readpin (&psgpioinstanceptr, IPINNUMBERBTN9); if (end) {Xgpiops_writepin (&psgpioinstanceptr, ipinnumberld9,0); Oled_clear (); break; }} while (1) {Readstatus1 = Xgpio_discreteread (&gpioinstance_ptr, 1);//Read BTNR if (READSTATUS1) {oled_showstring (0,0, "Does U love ME?""); Oled_showstring (0,16, "Btnu to Go"); Oled_refresh_gram (); Break }} while (1) {Readstatus2 = Xgpiops_readpin (&psgpioinstanceptr, IPINNUMBERBTNU);//Read BTNU if (READSTATUS2) {Oled_c Lear (); 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 in the OLED source code