
Hi I'm a very new to programming microcontroller and have been trying to set RA4 as an input and as the switch is hit RB1 shall light and after 4 pulses RB2 should light and RB1 stop and after 10 input pulses it should reset. But for some reason it does not do this.
Also RB7 AND RB6 remain on constantly why. If you change the bounce time it cause RB0 to light also why ?
Why do Ra0-ra3 work as input switches are they by default analog and have to be told to be digital ?
Any help greatly recieved as i've fallen at the first hurdle !
Dave
[
unsigned char count=0;
unsigned char oldv, newv ;
unsigned char key ( void ) // Routine from Matrix teaching disk
{
unsigned char count=0;
unsigned char oldv, newv ;
oldv = input_pin_port_b(4);
while ( count<20 )
{
newv = input_pin_port_b(4);
if ( oldv==newv )
{
count++ ;
}
else
{
count=0 ;
oldv=newv ;
}
}
return oldv ;
}
void main ()
{
int x=0; // Set count
set_tris_a (0xff) ; /* set all of PORTB for input */
set_tris_b (0x00) ; /* set bit 0 of PORTA for output */
while(1)
{
while (key()==0) // when switch not depress no LED light
{
output_low_port_b(1);
output_low_port_b(2);
}
while(key()==1)
{
x=x+1;
if (x==10) // Once x=10 reset 'X'
{
x=0;
}
}
while((key()==1)&&(x<4)) //Light LED 2 for first 4 presses
{
output_high_port_b(2);
}
while((key()==1)&&(x>4)) // After 4 press light led 1
{
output_high_port_b(1);
}
}
}
][/code]