putting a variable into bit addressable memory.CW5.1

cancel
Showing results for 
Search instead for 
Did you mean: 

putting a variable into bit addressable memory.CW5.1

2,005 Views
stevec
Contributor III
I've set up a structure of bits to serve as flags.
struct {
    unsigned char flag1:1
    unsigned char flag2:1
    unsigned char flag3:1
} flags

 How do I get this to sit in the bit addressable area of RAM?
Labels (1)
0 Kudos
2 Replies

15 Views
CrasyCat
Specialist III
Hello
 
I assume you are using a HC08 CPU and you want to place the variable flags in the direct memory area (between 0x00 and 0xFF).
 
Am I right?
I also assume you are using a project created using the project wizard. Is that correct?
This is done as follows:
 
#pragma DATA_SEG __SHORT_SEG  MY_ZEROPAGE
struct {
    unsigned char flag1:1
    unsigned char flag2:1
    unsigned char flag3:1
} flags;
#pragma DATA_SEG DEFAULT
 
If you have an external declaration for this variable, make sure to declare it in the same section.
#pragma DATA_SEG __SHORT_SEG  MY_ZEROPAGE
extern struct {
    unsigned char flag1:1
    unsigned char flag2:1
    unsigned char flag3:1
} flags;
#pragma DATA_SEG DEFAULT
 
There is an alternate notation.
 
If you have the following definition in a header file, which is included in all project source file:
#pragma DATA_SEG __SHORT_SEG  MY_ZEROPAGE
#pragma DATA_SEG DEFAULT

You can then define the variable as follows:

struct {
    unsigned char flag1:1
    unsigned char flag2:1
    unsigned char flag3:1
} flags @"MY_ZEROPAGE";

The declaration will then look as follows:

extern struct {
    unsigned char flag1:1
    unsigned char flag2:1
    unsigned char flag3:1
} flags @"MY_ZEROPAGE";

CrasyCat

0 Kudos

15 Views
stevec
Contributor III
Thanks very much CrasyCat. That's exactly what I wanted. Works a treat.
0 Kudos