FPGA_VIVADO_SI_VHDL_Mihael_Cristian_Ignat

(Cristian I.K_ntXI) #1
hh

helloworld.c


#include "xparameters.h"
#include "xgpio.h"
#include "xil_printf.h"


#define LED 0x01 / Assumes bit 0 of GPIO is connected to an LED /
#define LED_DELAY 10000000
#define LED_CHANNEL 1
#define SW_CHANNEL 1


XGpio LedGpio, SwGpio; / The Instance of the GPIO Driver /


int main ( void )
{
int Status;
volatile int Delay;
int sw_value;


/* Initialize the Led GPIO driver */
Status = XGpio_Initialize(&LedGpio, XPAR_LED_GPIO_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("Led Gpio Initialization Failed\r\n");
return XST_FAILURE;
}

/* Initialize the Switch GPIO driver */
Status = XGpio_Initialize(&SwGpio, XPAR_SW_GPIO_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("Switch Gpio Initialization Failed\r\n");
return XST_FAILURE;
}

/* Set the direction for all signals as inputs except the LED output */
XGpio_SetDataDirection(&LedGpio, LED_CHANNEL, 0xFFF0);

/* Set the direction for all signals input */
XGpio_SetDataDirection(&SwGpio, SW_CHANNEL, 0xFFFF);

while (1) {
// Read Switch value
sw_value = XGpio_DiscreteRead(&SwGpio, SW_CHANNEL);

/* Send swtich value to leds */
XGpio_DiscreteWrite(&LedGpio, LED_CHANNEL, sw_value);
}

xil_printf("Successfully ran Gpio Example\r\n");
return XST_SUCCESS;
}


demo.vhd


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;

Free download pdf