Hello All,
I'm seeking some advice on how to control program flow. I've just made a small breakout board that uses a shift register to drive a 2-digit seven segment display. Currently I have it doing several tricks, the outer segments "chase" around in a circle, it counts up in hex, blinks the decimal points, and counts down in decimal.
When I designed the board I also included a button which I would now like to implement. I know how to handle the debounce, etc, but my current implementation calls a function from main that I have to wait to get back from... for example:
void Chase(u8 direction, volatile u8 *buffer_address) { if (direction == 1) { u8 display = 0x80; while (display > 2) { *buffer_address = display; Delay_ms(50); display >>= 1; } } else { u8 display = 0x02; while (1) { display <<= 1; *buffer_address = display; Delay_ms(50); if (display == 0x80) break; } } }
As you can see there is a 50ms delay before the next segment is lit up. This means that as currently implemented I have to wait 400ms before this function returns to main in order to make any changes due to a button press.
Is there a better way to implement this type of behavior so that button presses will have an immediate effect on program flow?
Thanks!