//================================================== // Written By: Chia Chen Tan // Program: Basic Up Counter for ChipScope //================================================== // // This program will utilize push button to control // the up counter constant. Chipscope is used to // detect the rapid signal change in the output. //================================================== #include "xparameters.h" #include "xstatus.h" #include "xgpio.h" #define DELAY 1024 #define ENTER 15 //0b01111 #define UP 23 //0b10111 #define DOWN 27 //0b11011 #define LEFT 29 //0b11101 #define RIGHT 30 //0b11110 int main(void) { //================================================= // Initialize and set direction for LED and PB //================================================= XStatus LED_status, PB_status; XGpio GpioOutput, GpioInput; Xuint32 current_PB; LED_status = XGpio_Initialize(&GpioOutput, XPAR_LEDS_4BIT_DEVICE_ID); PB_status = XGpio_Initialize(&GpioInput, XPAR_PUSHBUTTONS_5BIT_DEVICE_ID); XGpio_SetDataDirection(&GpioOutput, 1, 0x0); XGpio_SetDataDirection(&GpioInput, 1, 0xFFFFFFFF); Xuint8 counter = 0; Xuint8 constant = 0; int i; XGpio_DiscreteWrite(&GpioOutput, 1, 0xFFFFFFFF); while(1){ //================================================= // Read the data off of the Push Button //================================================= current_PB = XGpio_DiscreteRead(&GpioInput, 1); //different direction corresponds to different up counter constant switch ( current_PB ){ //+1 up counter case UP: constant = 1; break; //+2 up counter case DOWN: constant = 2; break; //+3 up counter case LEFT: constant = 3; break; //+4 up counter case RIGHT: constant = 4; break; //no addition default: constant = 0; break; } //use a nested for loop to lessen cycle delay in switch operation for (i = 0; i < DELAY; i++) { //================================================= // send the data back out to the LEDs. //================================================= XGpio_DiscreteWrite(&GpioOutput, 1, counter); counter += constant; } //reset counter counter = 0; } return 0; }