And this version still doesn't do any debouncing. You're kind of making it hard on yourself trying to do too many things at once -- debouncing two buttons, waiting for one to be pushed, and blinking an LED -- which is hard to get right. Once you get there it will probably look something like:
which is a bit of a mouthful.
Code:
#pragma vector = PORT1_VECTOR
__interrupt void Port_1(void) //Engine - for engine to gain control, bridge must accept!
{
__delay_cycles(DEBOUNCE_PERIOD); // Debounce P1:ECR_TAKE
if ((P1IN & ECR_TAKE) == 0) // Pushed, not released
{
P2OUT &= ~BRIDGE_CMD_LED; // Commit
while(1) //Loop While NOT pressed is it supposed to be
{
if ((P2IN & BRIDGE_TAKE) == 0) // Button pressed, see if it stays
{
__delay_cycles(DEBOUNCE_PERIOD); // Debounce P2:BRIDGE_TAKE
if ((P2IN & BRIDGE_TAKE) == 0)
break; // Pushed for real
}
P1OUT ^= ECR_CMD_LED; //Toggle engine command while waiting for bridge to accept
__delay_cycles(220000); //Blink, blink
}
P1OUT |= ECR_CMD_LED;
}
P1IFG &= ~ECR_TAKE; // We dealt with the ECR request
P2IFG &= ~BRIDGE_TAKE; // We dealt with the bridge acceptance
}
