how to define a byte data for bit addressable?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to define a byte data for bit addressable?

3,145 Views
eos33
Contributor I
hi all,
i am the newbie of the Freescale MCU and trying to learn it base on the DEMO9S08QQ8 demo board.
how to define a byte that stores the status(or control) flag and access the bit independently?
like Bit7=LED7,Bit6=LED6...
then
LED7=1
LED6=0....etc..
 
thank you for your kindly help.:smileywink:

Message Edited by eos33 on 06-05-2006 09:15 PM

Labels (1)
0 Kudos
Reply
3 Replies

1,196 Views
bigmac
Specialist III

Hello,

If you were assembly programming, there are instructions to do bit manipulations directly, however I assume you will be working in C where the situation is a little more complex.

Firstly, if you are referencing any of the defined I/O registers for the device, CW has already done the preparation (within the file MC9S08QG8.h), so the following would work -

#define LED6  PTBD_PTBD6
#define LED7  PTBD_PTBD7

LED6 = 1;
LED7 = 0;
if (LED6 == 1) {

}

etc.

If you are creating your own status register in RAM, you will need to do the setup yourself.  The following example uses a similar method to the CW header file.

/* LDSTAT - LED Status register */
typedef union {
 byte Byte;
 struct {
   byte        :1;
   byte        :1;
   byte        :1;
   byte        :1;
   byte        :1;
   byte        :1;
   byte LED6   :1;
   byte LED7   :1;
 } Bits;
} LDSTATSTR;

LDSTATSTR _LEDSTAT;
#define LDSTAT  _LDSTAT.Byte
#define LED6    _LDSTAT.Bits.LED6
#define LED7    _LDSTAT.Bits.LED7


Regards,
Mac

0 Kudos
Reply

1,196 Views
eos33
Contributor I
hi all,
i am working in C.
refer to bigmac's example i have done it and really works fine.
thank you..:smileyvery-happy:
0 Kudos
Reply

1,196 Views
rhinoceroshead
Contributor I
Are you working in C or assembly?
0 Kudos
Reply