int a, b, c, x, portaval; // Declare variables for loop
main()
{
PORTA = 0;
PORTC = 0;
CMCON0 = 7; // Turn off comparators
ANSEL = 0; // Turn off ADC
TRISA0 = 0; // Make RA0/RA1/RA2/RA4/RA5/RC0/RC1/RC2/RC3/RC4/RC5 outputs
TRISA1 = 0;
TRISA2 = 0;
TRISA4 = 0;
TRISA5 = 0;
TRISC0 = 0;
TRISC1 = 0;
TRISC2 = 0;
TRISC3 = 0;
TRISC4 = 0;
TRISC5 =0;
TRISA3 = 1; // Make RA3 input
a = 0;
b = 0;
c = 0;
x = 0;
portaval=x;
while (1==1) // Loop forever
{
if (RA3==1) // button is pressed
{
b = b + 1; // Counter
} // fi
if (b==1) // button is pressed for the first time
{
x = showrider();
blinkled(x);
}
else if (b==3) // button is pressed for the third time
{
x = showrider();
blinkled(x);
}
else if (b==5) // button is pressed for the fifth time
{
x = showrider();
blinkled(x);
}
else if (b==7) // button is pressed for the seventh time
{
x = showrider();
blinkled(x);
}
else if (b==9) // button is pressed for the nineth time
{
x = showrider();
blinkled(x);
}
} //elihw
} // end main
int showrider()
/* Knight Rider Effect*/
{
while (RA3==1) // wait for the user to lift finger after pressing button
{
} // elihw
while (RA3==0) //while button is not being pressed
{
PORTA = 0b000001;
for (a=0; a<255; a++); // Simple delay loop
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
return 1;
}
PORTA = 0b000010;
for (a=0; a<255; a++); // Simple delay loop
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
return 2;
}
PORTA = 0b000100;
for (a=0; a<255; a++); // Simple delay loop
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
return 3;
}
PORTA = 0b010000;
for (a=0; a<255; a++); // Simple delay loop
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
return 4;
}
PORTA = 0b100000;
for (a=0; a<255; a++); // Simple delay loop
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
return 5;
}
} //elihw
}
void blinkled(portaval)
{
while (RA3==0) //while button is not being pressed
{
if (portaval==1)
{
while (1==1)
(
PORTA = 0b000001;
simpledelayloop();
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
break;
}
} //fi
}
}
else if (portaval==2)
{
while (1==1)
(
PORTA = 0b000010;
simpledelayloop();
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
break;
}
} //fi
}
}
else if (portaval==3)
{
while (1==1)
(
PORTA = 0b000100;
simpledelayloop();
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
break;
}
} //fi
} //elihw
}
else if (portaval==4)
{
while (1==1)
(
PORTA = 0b010000;
simpledelayloop();
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
break;
}
} //fi
} //elihw
}
else if (portaval==5)
{
while (1==1)
(
PORTA = 0b100000;
simpledelayloop();
if (RA3==1)
{
while (RA3==1)
{
}
while (RA3==0)
{
break;
}
} //fi
} //elihw
}
} //elihw
}
void simpledelayloop()
{
for (a=0; a<255; a++) // Simple Delay Loop
for (c=0; c<127; c++);
PORTA =0b000000;
}
|