
-----------------------------------
molten_rock01
Sat Jun 11, 2005 7:55 pm

MPLAB
-----------------------------------
Hi. I'm new at C and am doing a project for a class. My project partner just learned to use sub routines but we're having trouble. Could someone suggest what might be wrong?

 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	                                                                     
   // Make RA0/RA1/RA2/RA4/RA5/RC0/RC1/RC2/RC3/RC4/RC5 outputs
                TRISA0 =0; 
	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 7th time
		{
		     x = showrider();
		     blinkled(x);		  
		}
		else if (b==9)// button is pressed for the 9th 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
	{
	} // elihw

	while (RA3==0)   //while button is not being pressed
	{
		PORTA = 0b000001;
		for (a=0; a