#include"xparameters.h"#include"xgpio.h"#include"xil_printf.h"#include"sleep.h"//axi_gpio ID#define AXI_GPIO_DEV_ID XPAR_AXI_GPIO_0_DEVICE_ID//channel1#define BTN_CHANNEL 1//channel2#define LED_CHANNEL 2
XGpio Gpio;intmain(void){int Status;
u32 Btn_val;/* Initialize the GPIO driver */
Status =XGpio_Initialize(&Gpio, XPAR_AXI_GPIO_0_DEVICE_ID);if(Status != XST_SUCCESS){xil_printf("Gpio Initialization Failed\r\n");return XST_FAILURE;}/* Set the direction for all signals as inputs or output ,Bits set to 0 are output and bits set to 1 are input.*/XGpio_SetDataDirection(&Gpio, BTN_CHANNEL,1);XGpio_SetDataDirection(&Gpio, LED_CHANNEL,0);/* Write to discretes register for the specified GPIO channel */while(1){/*Read state of discretes for the specified GPIO channnel.*/
Btn_val =XGpio_DiscreteRead(&Gpio, BTN_CHANNEL);if(Btn_val){XGpio_DiscreteWrite(&Gpio, LED_CHANNEL,0x0);}else{XGpio_DiscreteWrite(&Gpio, LED_CHANNEL,0xf);}}}