I have basic knowledge of C++ and MicroControllers. Please Consider the following code excerpt from the header file of MC9s08aw60(freescale), i am working with Codewarrior V5.9.

typedef union {
  byte Byte;
  struct {
    byte PTFD0       :1;                                /* Port F Data Register Bit 0 */
    byte PTFD1       :1;                                /* Port F Data Register Bit 1 */
    byte PTFD2       :1;                                /* Port F Data Register Bit 2 */
    byte PTFD3       :1;                                /* Port F Data Register Bit 3 */
    byte PTFD4       :1;                                /* Port F Data Register Bit 4 */
    byte PTFD5       :1;                                /* Port F Data Register Bit 5 */
    byte PTFD6       :1;                                /* Port F Data Register Bit 6 */
    byte PTFD7       :1;                                /* Port F Data Register Bit 7 */
  } Bits;

Now, as far as i understand its defined as a struct and an object names "Bits" is also created but when i try to use the object in the CPP file, it shows an error such as: Bits not declared. Classname not specified. ';' missing.

Please tell me a simple reason for the same. And if this is not the right forum it,advise about an alternative.

Edit: Sorry for the obtuse expectation: this is how i used the code stated above;

Bits PTFD0 = 0x00; //considering logic 1 is low.

Thanks in Advance.

  • 3
    \$\begingroup\$ How are you using it in your program? Show us the code. \$\endgroup\$ – Igor Skochinsky Nov 29 '12 at 12:40
  • 2
    \$\begingroup\$ This looks like a pure C problem. What does it have to do with the IDE? \$\endgroup\$ – Olin Lathrop Nov 29 '12 at 14:14

First of all make sure that you are including the header file where the structure is defined in your file. The way to access it would be:

PTFDSTR example;
// access the byte
example.Byte = 0xA5;
// access a bit in the byte
example.Bits.PTFD5 = 1;

Not the answer you're looking for? Browse other questions tagged or ask your own question.