AnsweredAssumed Answered

C compiler passing a variable

Question asked by Daniel Morley on Dec 28, 2006
Latest reply on Dec 28, 2006 by Daniel Morley
I am using a C compiler to program a MC9S08GT16A
 
I have the following function
 void ReadPosition( int pos){
        
     if ( POSSW1==DOWN&&POSSW2==DOWN&&POSSW3==DOWN&&POSSW4==DOWN)
       pos=0;
    
    if ( POSSW1==DOWN&&POSSW2==DOWN&&POSSW3==DOWN&&POSSW4==UP)
     pos=1;
   
    if ( POSSW1==DOWN&&POSSW2==DOWN&&POSSW3==UP&&POSSW4==DOWN)
      pos=2;
 
    if ( POSSW1==DOWN&&POSSW2==DOWN&&POSSW3==UP&&POSSW4==UP)
     pos=3; 
        
    if ( POSSW1==DOWN&&POSSW2==UP&&POSSW3==DOWN&&POSSW4==DOWN)
     pos=4; 
        
    if ( POSSW1==DOWN&&POSSW2==UP&&POSSW3==DOWN&&POSSW4==UP)
     pos=5; 
        
    if ( POSSW1==DOWN&&POSSW2==UP&&POSSW3==UP&&POSSW4==DOWN)
     pos=6; 
        
    if ( POSSW1==DOWN&&POSSW2==UP&&POSSW3==UP&&POSSW4==UP)
     pos=7; 
        
    if ( POSSW1==UP&&POSSW2==DOWN&&POSSW3==DOWN&&POSSW4==DOWN)
     pos=8; 
        
    if ( POSSW1==UP&&POSSW2==DOWN&&POSSW3==DOWN&&POSSW4==UP)
     pos=9; 
        
    if ( POSSW1==UP&&POSSW2==DOWN&&POSSW3==UP&&POSSW4==DOWN)
     pos=10; 
        
    if ( POSSW1==UP&&POSSW2==DOWN&&POSSW3==UP&&POSSW4==UP)
     pos=11; 
     
        
    if ( POSSW1==UP&&POSSW2==UP&&POSSW3==DOWN&&POSSW4==DOWN)
     pos=12; 
        
    if ( POSSW1==UP&&POSSW2==UP&&POSSW3==DOWN&&POSSW4==UP)
     pos=13 ;       
    if ( POSSW1==UP&&POSSW2==UP&&POSSW3==UP&&POSSW4==DOWN)
     pos=14; 
     
        
    if ( POSSW1==UP&&POSSW2==UP&&POSSW3==UP&&POSSW4==UP)
     pos=15;
    
       
       
 }
 
 
Which works fine.  However it does not allow me to pass the pos value back to the main program. 
int x;
 ReadPosition(x);
   if (x==0){
   Forward(); 
   Delay(3);
   Brake();
    }
 
 
 
How should I set this up to pass the variable back to the main program
 
 

Outcomes