in C if we have a structure defined as
struct PortBreg {
unsigned int B0 :1;
unsigned int B1 :1;
unsigned int B2 :1;
unsigned int B3 :1;
unsigned int B4 :1;
unsigned int B5 :1;
unsigned int B6 :1;
unsigned int B7 :1;
};
#define Breg (*(volatile struct PortBreg *)(0x38)),
If I want to read value from port B bit B3 and write value to port B bit B2, can I do like
int i=Breg.B3; //to read
Breg.B2=i; //to write ?
That might depend if the port is readable and writable, but for a plain variable this code works: copying B3 to B2. Please be consistent with your types,
int i
is notunsigned int i
. Note too that I print each member in the usual sequence, but the struct definition of an actual port read might need to be reversed, so that B7 is first.Program output: