Consolidation of scattered port bits into one contrived port

Post your requests and ideas on the future development of mikroC PRO for PIC.
Post Reply
Author
Message
steve42lawson
Posts: 183
Joined: 06 Mar 2008 17:35
Location: St. George, UT
Contact:

Consolidation of scattered port bits into one contrived port

#1 Post by steve42lawson » 20 Dec 2017 03:49

Unless I'm missing something, there doesn't seem to be a way to group port bits from different ports and write to them in parallel. The sbit type seems to be some sort of pointer, but there doesn't seem to be any other functionality than, writing a bit to it, or reading a bit from it.

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;
It would be just lovely if I didn't have to write bits one at a time, or have to do all of that bit fiddling. That's what compilers are supposed to do, right?!

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;

I mean, isn't that supposed to be the beauty of C?!?

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?!?
Humility is the lack of the desire to impress, not the lack of being impressive.

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: Consolidation of scattered port bits into one contrived

#2 Post by lana.arsic » 21 Dec 2017 17:21

Hi,

Thank you for the suggestion, it is very interesting.

Unfortunately it is not possible in the compiler
because it would not be possible on the hardware
to assign at once value to different ports.

Kind regards,
Lana

Post Reply

Return to “mikroC PRO for PIC Wish List”