Daniel Morley

simulator

Discussion created by Daniel Morley on Feb 27, 2007
Latest reply on Nov 20, 2007 by Edmond Hameli
 
 
I am programing a MC9S08GT8A to read a position form a sensor using the digital I/O.  When I use the simulator I get the following error.
 
 
 
Error: At location 014C -
Error: Attempt to use invalid or uninitialized memory
 
 
This occurs when I reach the following function.
 
char ReadAdress( char address){
 
       if ( POS1==UP&&POS2==UP&&POS3==UP&&POS4==UP)
       address='0';
       if ( POS1==DOWN&&POS2==UP&&POS3==UP&&POS4==UP)
       address='1';
  
       if ( POS1==UP&&POS2==DOWN&&POS3==UP&&POS4==UP)
       address='2';
            
    
       if ( POS1==DOWN&&POS2==DOWN&&POS3==UP&&POS4==UP)
       address='3';
  
       if ( POS1==UP&&POS2==UP&&POS3==DOWN&&POS4==UP)
       address='4';
       
       if ( POS1==DOWN&&POS2==UP&&POS3==DOWN&&POS4==UP)
       address='5';
  
       if ( POS1==UP&&POS2==DOWN&&POS3==DOWN&&POS4==UP)
       address='6';
            
    
       if ( POS1==DOWN&&POS2==DOWN&&POS3==DOWN&&POS4==UP)
       address='7';
  
       if ( POS1==UP&&POS2==UP&&POS3==UP&&POS4==DOWN)
       address='8';
       
       
       if ( POS1==DOWN&&POS2==UP&&POS3==UP&&POS4==DOWN)
       address='9';
  
       if ( POS1==UP&&POS2==DOWN&&POS3==UP&&POS4==DOWN)
       address='A';
            
    
       if ( POS1==DOWN&&POS2==DOWN&&POS3==UP&&POS4==DOWN)
       address='B';
  
       if ( POS1==UP&&POS2==UP&&POS3==DOWN&&POS4==DOWN)
       address='C';
       
       
       
       if ( POS1==DOWN&&POS2==UP&&POS3==DOWN&&POS4==DOWN)
       address='D';
       
       
  
       if ( POS1==UP&&POS2==DOWN&&POS3==DOWN&&POS4==DOWN)
        address='E';
       
       
  
       if ( POS1==DOWN&&POS2==DOWN&&POS3==DOWN&&POS4==DOWN)
        address='F';  
    
  
    
        return (address);    
       
 } 
 
 
When I actually run a device with this code It appears to work find.  I can read the address of the position sensor.  The simulator doesn't actually step into the program it stops at the function.
 
 char Listen( char comand[2]){
      char adr  ;
      char ErrorFlag[7];
      RecCmd(comand);
          
       
           
               
        ReadAdress(adr);
       if(adr=='2')    {
       
      SendMsg("  Yes Yes  ");     
        adr=ReadAdress( adr) ;
         ErrorFlag[1] =  ' ' ;
              ErrorFlag[2] =  ReadAdress( adr) ;
              ErrorFlag[3] =  ' ' ;
              ErrorFlag[4] =  adr ;
              ErrorFlag[5] =  ' ' ;
              ErrorFlag[6] =  ' ' ;
           //   SendMsg(ErrorFlag) ; // incorrect ending to command  
            
       SendMsg(comand);
      SendMsg("         ");
       }
 }
 
 

Outcomes