BiscuitDuke
Newbie level 6
I am taking an Embedded Computing class and as a final project I must design a traffic light system. I am using a XC5VLX110T and so far this is my code.
What I want this code to do is to display "green", "yellow", "red", repeat as long as a pedestrian button is not pushed. If a pedestrian pushes a button, then it should display "pedestrian walking, stop." Right now I'm having the problem of it not repeating, as well as the button not working. I'm more concerned about the button right now? Is the code for the button in the right place? Am I using while loops correctly? Anything you may find wrong with the code please let me know. Thanks in advance!
Code:
int main()
{
xil_printf("orange");
XromLCDPrintString(" GO!! ");
//==================================================================================
//
// PUSH BUTTON
//
//==================================================================================
XGpio dip, push;
int i, dip_current, push_current, dip_old, push_old;
//XGpio_Initialize(&dip, XPAR_DIP_DEVICE_ID);
XGpio_Initialize(&dip, XPAR_DIP_DEVICE_ID);
XGpio_SetDataDirection(&dip, 1, 0xffffffff);
//XGpio_Initialize(&push, XPAR_PUSH_DEVICE_ID);
XGpio_Initialize(&push, XPAR_PUSH_DEVICE_ID);
XGpio_SetDataDirection(&push, 1, 0xffffffff);
dip_old = 0xFF;
push_old = 0xFF;
while(1) {
push_current = XGpio_DiscreteRead(&push, 1);
dip_current = XGpio_DiscreteRead(&dip, 1);
if(push_current != push_old) //|| (dip_current != dip_old))
{
push_old = push_current;
pedestrian_walk = 1;
//dip_old = dip_current;
}
// Enable MicroBlaze Interrupts
// microblaze_enable_interrupts();
/* Register the Timer interrupt handler in the vector table */
XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
XPAR_XPS_INTC_0_DELAY_INTERRUPT_INTR,
(XInterruptHandler) timer_int_handler,
(void *)XPAR_DELAY_BASEADDR);
/* Initialize and set the direction of the GPIO connected to LEDs */
XGpio_Initialize(&gpio, XPAR_LEDS_8BIT_DEVICE_ID);
XGpio_SetDataDirection(&gpio,LEDChan, 0);
/* Start the interrupt controller */
XIntc_MasterEnable(XPAR_XPS_INTC_0_BASEADDR);
XIntc_EnableIntr(XPAR_XPS_INTC_0_BASEADDR, 0x1);
/* Set the gpio as output on high 8 bits (LEDs)*/
XGpio_WriteReg(XPAR_LEDS_8BIT_DEVICE_ID,LEDChan, ~count);
//xil_printf("The value of count = %d\n\r", count);
/* Set the number of cycles the timer counts before interrupting */
XTmrCtr_SetLoadReg(XPAR_DELAY_BASEADDR, 0, (timer_count*timer_count+1) * 80000000);
/* Reset the timers, and clear interrupts */
XTmrCtr_SetControlStatusReg(XPAR_DELAY_BASEADDR, 0, XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
/* Enable timer interrupts in the interrupt controller */
XIntc_EnableIntr(XPAR_DELAY_BASEADDR, XPAR_DELAY_INTERRUPT_MASK);
/* Start the timers */
XTmrCtr_SetControlStatusReg(XPAR_DELAY_BASEADDR, 0, XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
/* Enable MB interrupts */
microblaze_enable_interrupts();
/*Wait for interrupts to occur
while(1) {
push_current = XGpio_DiscreteRead(&push, 1);
dip_current = XGpio_DiscreteRead(&dip, 1);
if( pedestrian_walk) {
count=0;
push_old = push_current;
XromLCDClear();
while (count< 31)
{
XromLCDPrintString(" PEDESTRIAN WALK ");
xil_printf("PED");
XromLCDSetLine(2);
XromLCDPrintString(" STOP!! ");
count ++;
}
one_second_flag=0;
pedestrian_walk=0;
count=0;
}
}*/
XromLCDInit();
XromLCDOn();
while(count>0 && count<6)
{
XromLCDClear();
xil_printf("Green");
XromLCDPrintString(" GREEN ");
XromLCDSetLine(2);
XromLCDPrintString(" GO!! ");
}
while(count>5 && count<16)
{
XromLCDClear();
xil_printf("Yellow");
XromLCDPrintString(" YELLOW ");
XromLCDSetLine(2);
XromLCDPrintString(" SLOW ");
}
while(count>15 && count<26)
{
XromLCDClear();
xil_printf("Red");
XromLCDPrintString(" RED ");
XromLCDSetLine(2);
XromLCDPrintString(" STOP!! ");
}
if(count >= 26)
{
count = 0;
}
}
//exit(0);
}
What I want this code to do is to display "green", "yellow", "red", repeat as long as a pedestrian button is not pushed. If a pedestrian pushes a button, then it should display "pedestrian walking, stop." Right now I'm having the problem of it not repeating, as well as the button not working. I'm more concerned about the button right now? Is the code for the button in the right place? Am I using while loops correctly? Anything you may find wrong with the code please let me know. Thanks in advance!