/*
One input two outputs
Initial state both outputs low.
Remain at this state while input is high.
When input is grounded, O1 goes low, O2 high
Remain at this state while input is grounded, and when it goes high
When input is grounded, O1 goes high, O2 low
Remain at this state while input is grounded, and when it goes high
RB0 is input (because PortB has weak pullups; J17 is set to pull to ground)
RA0,RA1 are outputs
*/
void main()
{
char stat;
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
WPUB=1; // enable pull-up resistors
TRISB=1; // enable PORTB.0 as input
TRISA=0; // PORTA 0,1 output
PORTA=0; // initial state both outputs low
stat=0;
for (;;)
{
switch (stat)
{
case 0:
if (PORTB & 1)
{
// button is up, do nothing
}
else
{
// button is pressed; go to stat=1 and debounce
Delay_ms(100);
stat=1;
PORTA=2;
}
break;
case 1: // Button is down, A0=0, A1=1
if (PORTB & 1)
{
// button is up; go to stat=2 and debounce
Delay_ms(100);
stat=2;
}
else
{
// button is down; remain here
}
break;
case 2: // Button is up, A0=0, A1=1
if (PORTB & 1)
{
// button is up; do nothing
}
else
{
// button down; go to stat=3 and debounce
Delay_ms(100);
stat=3;
PORTA=1;
}
break;
case 3: // button is down, A0=1, A1=0
if (PORTB & 1)
{
// button is up, go to stat=4 and debounce
Delay_ms(100);
stat=4;
}
else
{
// button is down; stay here
}
break;
case 4: // button is up; A0=1, A1=0
if (PORTB & 1)
{
// button is up, do nothing
}
else
{
// button down; go to stat=1 and debounce
Delay_ms(100);
stat=1;
PORTA=2;
}
break;
}
}
}