Over the decades (yes, plural) I've been using this compiler, I keep coming across cases where I have to divide port bits, for a particular context, across two or more different ports. Often, it's because I've already used bits from various ports, usually because of dedicated functionality constraints, and have no nice, pretty set of port pins, all in a row, on one port. Also, moving port bits around can solve PCB layout conundrums.
Example:
Code: Select all
// Some LED indicators to show which DUT (Device Under Test) is currently active.
sbit bo_dut_led01 at LATA.B3;
sbit bo_dut_led02 at LATA.B4;
sbit bo_dut_led03 at LATB.B6;
sbit bo_dut_led04 at LATC.B2;
For instance, wouldn't it be grand if I could do something like this (not sure if the syntax is kosher, but hopefully it gets the idea across):
Code: Select all
// Assign LAT addresses to all those scattered port bits.
sbit bo_dut_led01 at LATA.B3;
sbit bo_dut_led02 at LATA.B4;
sbit bo_dut_led03 at LATB.B6;
sbit bo_dut_led04 at LATC.B2;
// Create a cohesive bit field.
struct t__dut_led_lats {
sbit *led01, *led02, *led03, *led04;
} dut_leds = {
*bo_dut_led01,
*bo_dut_led02,
*bo_dut_led03,
*bo_dut_led04
};
// Create a way to map an unsigned int onto my cohesive bit field
union t__dut_led_map {
struct t__dut_led_lats s_dut_led_bits;
unsigned int i_dut_led_bits;
} mapper;
// Assign my organized bit structure to the mapper union
mapper.s_dut_led_bits = dut_leds;
// Write to my contrived "port" with one assign, turning on only one DUT LED indicator with one bold stroke!
mapper.i_dut_led_bits = 0x04;
Now, I know there is no such thing as a "bit" variable type in standard C, let alone a pointer to a bit, but MikroC has crazy/wonderful things like 'bit' and 'sbit', so why not take that to the next level? This would be such a powerful and even more wonderful compiler -- one that addresses one of the most common activities in an MCU -- moving bits around!
Am I barking up the wrong C-tree?!?