/***************************************************** Getting Started Guide for Zybo This demo displays the status of the switches on the LEDs and prints a message to the serial communication when a button is pressed. Terminal Settings: -Baud: 115200 -Data bits: 8 -Parity: no -Stop bits: 1 1/6/14: Created by MarshallW ****************************************************/ #include #include "platform.h" #include #include "xparameters.h" #include "sleep.h" #include "xil_io.h" //#define MY_PWM XPAR_MY_PWM_CORE_0_S00_AXI_BASEADDR //Because of a bug in Vivado 2015.3 and 2015.4, this value is not correct. #define MY_PWM 0x43C00000 //This value is found in the Address editor tab in Vivado (next to Diagram tab) int main() { XGpio input, output; int button_data = 0; int switch_data = 0; int num=0; //int i; XGpio_Initialize(&input, XPAR_AXI_GPIO_0_DEVICE_ID); //initialize input XGpio variable XGpio_Initialize(&output, XPAR_AXI_GPIO_1_DEVICE_ID); //initialize output XGpio variable XGpio_SetDataDirection(&input, 1, 0xF); //set first channel tristate buffer to input XGpio_SetDataDirection(&input, 2, 0xF); //set second channel tristate buffer to input XGpio_SetDataDirection(&output, 1, 0x0); //set first channel tristate buffer to output init_platform(); while(1){ switch_data = XGpio_DiscreteRead(&input, 2); //get switch data XGpio_DiscreteWrite(&output, 1, switch_data); //write switch data to the LEDs button_data = XGpio_DiscreteRead(&input, 1); //get button data if(num == 1024) num = 0; else num++; //print message dependent on whether one or more buttons are pressed if(button_data == 0b0000){} //do nothing else if(button_data == 0b0001){ xil_printf("button 0 pressed\n\r"); Xil_Out32(MY_PWM, num); } else if(button_data == 0b0010){ xil_printf("button 1 pressed\n\r"); Xil_Out32((MY_PWM+4), num); } else if(button_data == 0b0100){ xil_printf("button 2 pressed\n\r"); Xil_Out32((MY_PWM+8), num); } else if(button_data == 0b1000){ xil_printf("button 3 pressed\n\r"); Xil_Out32((MY_PWM+12), num); } else xil_printf("multiple buttons pressed\n\r"); usleep(200000); //delay } cleanup_platform(); return 0; }