hi all,
Currently I'm using bit field style for I/O and I'm making the definitions of I/O bit field as below.
typedef struct { unsigned char b0:1; unsigned char b1:1; unsigned char b2:1; unsigned char b3:1; unsigned char b4:1; unsigned char b5:1; unsigned char b6:1; unsigned char b7:1; } bit_field; typedef union { unsigned char byte; bit_field bit; } io_reg; #define ioPORTB ((volatile io_reg*)&PORTB)->byte #define ioPORTB0 ((volatile io_reg*)&PORTB)->bit.b0 #define ioPORTB1 ((volatile io_reg*)&PORTB)->bit.b1 #define ioPORTB2 ((volatile io_reg*)&PORTB)->bit.b2 #define ioPORTB3 ((volatile io_reg*)&PORTB)->bit.b3 #define ioPORTB4 ((volatile io_reg*)&PORTB)->bit.b4 #define ioPORTB5 ((volatile io_reg*)&PORTB)->bit.b5 #define ioPORTB6 ((volatile io_reg*)&PORTB)->bit.b6 #define ioPORTB7 ((volatile io_reg*)&PORTB)->bit.b7 #define ioPORTC ((volatile io_reg*)&PORTC)->byte #define ioPORTC0 ((volatile io_reg*)&PORTC)->bit.b0 #define ioPORTC1 ((volatile io_reg*)&PORTC)->bit.b1 #define ioPORTC2 ((volatile io_reg*)&PORTC)->bit.b2 #define ioPORTC3 ((volatile io_reg*)&PORTC)->bit.b3 #define ioPORTC4 ((volatile io_reg*)&PORTC)->bit.b4 #define ioPORTC5 ((volatile io_reg*)&PORTC)->bit.b5 #define ioPORTC6 ((volatile io_reg*)&PORTC)->bit.b6 #define ioPORTC7 ((volatile io_reg*)&PORTC)->bit.b7
Usage
ioPORTB = 0xff; ioPORTC0 = 1;
But I would like to making some macro that able to fill in a name and address of I/O bit field for instead of above definitions. But same usage.
#define SOME_MACRO(__NAME, __ADDR) \ ------------------------------------------------------\ ------------------------------------------------------\ ------------------------------------------------------\ ------------------------------------------------------\ SOME_MACRO(ioPORTB, &PORTB); SOME_MACRO(ioPORTB, &PORTC);
Any someone guide me for achieve this macro ?
Regards,