Quantcast
Channel:
Viewing all articles
Browse latest Browse all 59170

Forum Post: RE: [iodefine] create a custom port

$
0
0
No way. It is not possible to create a bitfield, where single bits are located at different addresses. This is not a limitation of the compiler but a limitation of C. You could write some kind of macro to set all bits, bit the direct access to each LED might more clear. The macro might look like this: #define Set_MyPort(DATA)  (DATA&0x01)?((PORT6.DR.BIT.B1)=1):((PORT6.DR.BIT.B1)=0); \                           (DATA&0x02)?((PORT6.DR.BIT.B2)=1):((PORT6.DR.BIT.B2)=0); \                           (DATA&0x04)?((PORT7.DR.BIT.B4)=1):((PORT7.DR.BIT.B4)=0); \                           (DATA&0x08)?((PORT7.DR.BIT.B5)=1):((PORT7.DR.BIT.B5)=0); \                           (DATA&0x10)?((PORT7.DR.BIT.B6)=1):((PORT7.DR.BIT.B6)=0); \                           (DATA&0x20)?((PORT7.DR.BIT.B7)=1):((PORT7.DR.BIT.B7)=0); \                           (DATA&0x40)?((PORT2.DR.BIT.B1)=1):((PORT2.DR.BIT.B1)=0); \                           (DATA&0x80)?((PORT2.DR.BIT.B2)=1):((PORT2.DR.BIT.B2)=0);

Viewing all articles
Browse latest Browse all 59170

Trending Articles