simulator

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

simulator

2,893件の閲覧回数
DanielMorley
Contributor I
 
 
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("         ");
       }
 }
 
 
ラベル(1)
タグ(1)
0 件の賞賛
返信
4 返答(返信)

879件の閲覧回数
King_Eddie85
Contributor I
Hi there,

i saw that you used the SendMsg() function to view Messages or any values or sothing else. I just wanted to know which ~.h (headerfile) i have to include in order to to make it possible to use this function.

thanks...
cheers eddie
0 件の賞賛
返信

879件の閲覧回数
CrasyCat
Specialist III
Hello
 
The message is generated in the simulator only as far as I remember.
It indicates that you are reading from an address, which has not been initialized previously.
 
I assume the issue is related to the variable/macro POS1, POS2, POS3, POS4. I do not know where these variables are located, but they need to be initialized with something first.
 
You have several solution to make sure this happens:
     - In the HCS08FCS menu you have a set of dialog available where you can provide some
       input value to diverse peripheral.
       If POS1, POS2, POS3, POS4 are mapped to any of these registers, just specify an initialization
       value there.
     - There are commands associated with each of the peripheral modules you find in the HCS08FCS
        menu. You can find a list of available commands in {Install}Help\PDF\Debugger_HC08.pdf in Chapter
        "Book III - HCS08 Debug Connections" section "HCS08 Full Chip Simulation" -> "Peripheral Modules
        Commands".
       Just specify the appropriate command in the file {Project}\cmd\postload.cmd.
    - If there is no peripheral modules command available for the variables/macros, you can use
       the debugger command WB, WW or WL to write to the appropriate address.
      These commands are described in {Install}Help\PDF\Debugger_HC08.pdf in Chapter
       "Book V - Commands" section "Debugger Commands".
      Here also, place the commands in the the file {Project}\cmd\postload.cmd .
 
I hope this helps.
 
CrasyCat
0 件の賞賛
返信

879件の閲覧回数
bigmac
Specialist III
Hello Daniel,
 
I think that your problem is with the following code -
 
char Listen(char comand[2])
{
   char adr;
   char ErrorFlag[7];
 
   RecCmd(comand);
   ReadAdress(adr);
   if (adr == '2') {
      ...
     ...
     ...
   }
}
 
You have declared a local variable addr that does not yet have a value allocated to it when the if ... line is reached.  The value returned by the ReadAdress() function is not used in the present code.  The following might give the result you intend -
 
  adr = ReadAdress(0);
 
The parameter of this function is never actually used.  You could have alternatively omitted it, and used a local variable within the function instead.
 
Regards,
Mac
 
0 件の賞賛
返信

879件の閲覧回数
peg
Senior Contributor IV
Hi Daniel,
 
This warning is simply telling you that you are using a reister or memory location that has not been explicitly set to a value. This may not cause any problem, but it is warning you about it.
This often occurs with a COP clearing command such as:
STA   SRS
If this is executed before you ever used A then you get an error even though you don't care what is loaded to SRS just to clear the COP. My code often has some lines commented at the top with "just to keep simulator happy" because of this.
You will have to look at the dissassembly near this location to find what is causing this problem.
 
0 件の賞賛
返信