This is an embedded C question for 8-bit PIC microcontrollers.
Let's say there is a 7-Segment LED display that is connected to different pins of different ports and let's say they are defined as follows:
#define _7seg_A PORTCbits.RC6
#define TRIS_7seg_A TRISCbits.TRISC6
#define _7seg_B PORTCbits.RC5
#define TRIS_7seg_B TRISCbits.TRISC5
#define _7seg_C PORTAbits.RA5
#define TRIS_7seg_C TRISAbits.TRISA5
#define _7seg_D PORTBbits.RB6
#define TRIS_7seg_D TRISBbits.TRISB6
#define _7seg_E PORTBbits.RB5
#define TRIS_7seg_E TRISBbits.TRISB5
#define _7seg_F PORTBbits.RB7
#define TRIS_7seg_F TRISBbits.TRISB7
#define _7seg_G PORTCbits.RC7
#define TRIS_7seg_G TRISCbits.TRISC7
#define _7seg_DP PORTAbits.RA4
#define TRIS_7seg_DP TRISAbits.TRISA4
Also, here is a port definition from the microcontroller definitions header file of the compiler:
typedef union {
struct {
unsigned RA0 :1;
unsigned RA1 :1;
unsigned RA2 :1;
unsigned RA3 :1;
unsigned RA4 :1;
unsigned RA5 :1;
};
} PORTAbits_t;
extern volatile PORTAbits_t PORTAbits @ 0x005;
Now, I want to have something called _7seg_DATA
which contains all eight of _7seg_X bits and when I write data to it, it will automatically put it into defined pins. Can this be done by unions?
For example, if I do _7seg_DATA = 0x00;
it will shut down all the LEDs..
And if I do _7seg_DATA = 0xFF;
it will light all of them.