Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 MPLAB
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
molten_rock01




PostPosted: Sat Jun 11, 2005 7:55 pm   Post subject: 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?

code:
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<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;

 }


When ever we build this program, the
code:
void blinkled(portaval)
gives a syntax error. We've looked over the code a thousand times.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: