Hello
I assume you are using an HC12 MCU and you are running the application on the simulator. Am I right?
The full chip simulator is able to detect read access to uninitialized memory and in that particular case it detects one of these access.
Basically when you write
Port1.Stat.High=0;
The compiler generates a "BCLR 2,SP,#8" instruction.
BCLR instruction is performing a read set bit and write on the local variable So basically it reads an un-initialized memory address.
You have two solutions to prevent that from happening:
1- Configure the debugger so that it does not stop on read access to undefined memory location
This is done as follows:
- Start the debugger
- Select "HCS12FCS" -> "Configure ..."
- uncheck the box "Stop on Read undefined"
- Click on the "Save" button
- Save the configuration in a file called default.mem located in your project directory.
- Click OK to save the memory configuration
Starting from now debugger will not stop anymore on read to undefined memory location.
2- Make sure the whole bitfield is initialized before you attempt to set a bit in there.
If you want to continue to track read access to undefined memory location you need to explicitly
initialize the whole structure in the application.
If the variable is a global variable this is performed automatically by the startup code (as soon as
you are using the delivered ANSI C startup code in your application).
If the structure is a local variable, I would suggest you to initialize it as a whole at the beginning
of the function.
In that case it is good practice to define a union allowing to access the variable wither as a
whole byte of as single bits
In your case define the variable as follows:
typedef union {
byte StatusByte ;
struct status
{
byte Mode0 :1; /* b0 */
byte Mode1 :1; /* b1 */
byte Mode_Read :1; /* b2 */
byte High :1; /* b5 */
byte Active :1; /* b6 */
// byte Master :1; /* b7 */
} StatusBits;
}Status;
main function will then be implemented as follows.
void main(void)
{
Port Port1;
Port1.Stat.StatusByte = 0;
while(1)
{
Port1.Stat.StatusBits.High++;
}
}
I hope this helps a bit.
CrasyCat