#include"xparameters.h" #include"xgpio.h" #include"xil_printf.h" /************************** Constant Definitions *****************************/ #define LED 0x01 /* Assumes bit 0 of GPIO is connected to an LED */ #define GPIO_EXAMPLE_DEVICE_ID XPAR_GPIO_0_DEVICE_ID #define LED_DELAY 10000000 #define LED_CHANNEL 1 XGpio Gpio; /* The Instance of the GPIO Driver */
intmain(void) { int Status; volatileint Delay; Status = XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID);//初始化驱动器 if (Status != XST_SUCCESS) { xil_printf("Gpio Initialization Failed\r\n"); return XST_FAILURE; } XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~LED);//将驱动器上,指定通道,设置为输出方向,写 XGPIO_TRI_OFFSET while (1) { XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, LED);//信号变为高电平,LED灯点亮,写 XGPIO_DATA_OFFSET for (Delay = 0; Delay < LED_DELAY; Delay++); XGpio_DiscreteClear(&Gpio, LED_CHANNEL, LED);//信号变为低电平。LED灯熄灭 for (Delay = 0; Delay < LED_DELAY; Delay++); } }