how to define a byte data for bit addressable?

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

how to define a byte data for bit addressable?

3,143件の閲覧回数
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

ラベル(1)
0 件の賞賛
返信
3 返答(返信)

1,194件の閲覧回数
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 件の賞賛
返信

1,194件の閲覧回数
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 件の賞賛
返信

1,194件の閲覧回数
rhinoceroshead
Contributor I
Are you working in C or assembly?
0 件の賞賛
返信