Hueestory

07 PS MIO 본문

FPGA(중단)/zynq

07 PS MIO

히명 2023. 3. 3. 20:49

Vitis C Code

#include <stdio.h>
#include "xgpiops.h"
#include "platform.h"


int main()
{
    static XGpioPs psGpioInstancePtr;
    XGpioPs_Config * GpioConfigPtr;
    int xStatus;
    int BtnPinDirection = 0, BtnPinNumber = 50;
    int LedPinDirection = 1, LedPinNumber = 7;
    int Readstatus = 0, OldReadstatus = 0;

    init_platform();

    print("Hello World\n\r");
    // step 1 : PS GPIO Initialization //
    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 2-1 : Push Button Input //
    XGpioPs_SetDirectionPin(&psGpioInstancePtr, BtnPinNumber, BtnPinDirection);
    XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, BtnPinNumber, 0);
    // step 2-2 : LED Output //
    XGpioPs_SetDirectionPin(&psGpioInstancePtr, LedPinNumber, LedPinDirection);
    XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, LedPinNumber, 1);

    xStatus = 0;
    while(1)
    {
    	Readstatus = XGpioPs_ReadPin(&psGpioInstancePtr, BtnPinNumber);
    	if( (Readstatus == 1) && (OldReadstatus == 0))
    	{
    		print("BTN8(PB1-MI050) PUSH Button pressed \n\r");
    		if(xStatus == 1)
    		{
    			xStatus = 0;
    			XGpioPs_WritePin(&psGpioInstancePtr, LedPinNumber, 0);
    			print("LED(LD9) is OFF\r\n");
    		}else
    		{
    			xStatus = 1;
    			XGpioPs_WritePin(&psGpioInstancePtr, LedPinNumber, 1);
    			print("LED(LD9) is ON\r\n");
    		}

    	}
    	OldReadstatus = Readstatus;
    }
    print("\r\n");
    print("***********\r\n");
    print("BYE \r\n");
    print("***********\r\n");
    cleanup_platform();
    return 0;
}

 

'FPGA(중단) > zynq' 카테고리의 다른 글

09 LED toggle  (0) 2023.03.22
08 PL with AXI  (0) 2023.03.14
06 BRAM tutorial  (0) 2023.02.18
05 Keypad tutorial  (0) 2023.02.18
04 VGA tutorial  (0) 2023.02.18
Comments