发布网友 发布时间:2022-04-08 03:52
共2个回答
懂视网 时间:2022-04-08 08:14
#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 ##### "); print(" "); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //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 "); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //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 "); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //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 ######################## "); 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(" "); print("*********** "); print("BYE "); print("*********** "); cleanup_platform(); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
zedboard中OLED源代码
标签:
热心网友 时间:2022-04-08 05:22
什么是oled