Referring to bits of a register for variables in XC8? (microchip c compiler)

Status
Not open for further replies.
T

treez

Guest
Hello,
I am writing XC8 (free version) C for PIC18F65K22 in MPLAB.X environment.

I wish to define an 8 bit register, which I am calling “dip8”.
I also wish to refer to each bit of this register.
How do I do this in C?
Do I have to use inline assembler.

Here is how I declare the variable…
Unsigned int dip8;


Here is my code so far
 

It's usually done with unions. I'm not using XC8 but I would expect predefined unions for bit access in GenericTypeDefs.h or a similar include file.

Like this one supplied with C30

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
typedef union
{
    UINT8 Val;
    struct
    {
        __EXTENSION UINT8 b0:1;
        __EXTENSION UINT8 b1:1;
        __EXTENSION UINT8 b2:1;
        __EXTENSION UINT8 b3:1;
        __EXTENSION UINT8 b4:1;
        __EXTENSION UINT8 b5:1;
        __EXTENSION UINT8 b6:1;
        __EXTENSION UINT8 b7:1;
    } bits;
} UINT8_VAL, UINT8_BITS;

 
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…