/* Include Files */
#include "xparameters.h"
#include "xgpio.h"
#include "xstatus.h"
#include "xil_printf.h"
/* Definitions */
#define GPIO_DEVICE_ID XPAR_AXI_GPIO_0_DEVICE_ID /* GPIO device that LEDs are connected to */
#define LED 0xFC /* Initial LED value - XX0000XX */
#define PMOD 0xFC /* Initial LED value - XX0000XX */
#define LED_DELAY 1000000000 /* Software delay length */
#define LED_CHANNEL 1 /* GPIO port for LEDs */
#define PMOD_CHANNEL 1 /* GPIO port for PMODs */
#define printf xil_printf /* smaller, optimised printf */
#define PMOD_JA1_DEVICE_ID XPAR_AXI_GPIO_1_DEVICE_ID
XGpio Gpio, GpioP; /* GPIO Device driver instance */
int LEDOutputExample(void)
{
volatile int Delay;
int Status;
int led = LED; /* Hold current LED value. Initialise to LED definition */
int pmod = PMOD;
u32 x;
/* GPIO driver initialisation */
Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
Status = XGpio_Initialize(&GpioP, PMOD_JA1_DEVICE_ID);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
/*Set the direction for the LEDs to output. */
XGpio_SetDataDirection(&Gpio, LED_CHANNEL, 0x00);
/*Set the direction for the LEDs to output. */
XGpio_SetDataDirection(&GpioP, PMOD_CHANNEL, 0x11111111);
/* Loop forever blinking the LED. */
while (1) {
/* Write output to the LEDs. */
XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, led);
/* Flip LEDs. */
led = ~led;
/* Write output to the LEDs. */
//XGpio_DiscreteWrite(&GpioP, PMOD_CHANNEL, pmod);
x = XGpio_DiscreteRead(&GpioP,PMOD_CHANNEL);
printf("The voltage on pin 3 is %d",x);
/* Flip LEDs. */
// pmod = ~pmod;
/* Wait a small amount of time so that the LED blinking is visible. */
for (Delay = 0; Delay < LED_DELAY; Delay++);
}
return XST_SUCCESS; /* Should be unreachable */
}
/* Main function. */
int main(void){
int Status;
/* Execute the LED output. */
Status = LEDOutputExample();
if (Status != XST_SUCCESS) {
xil_printf("GPIO output to the LEDs failed!\r\n");
}
return 0;
}
No comments:
Post a Comment