I don't know if there's a way to do exactly what you want - assigning a single name to non-sequential memory areas without a mapping function. I think the best you can do is minimize the time you spend in said function.
Depending on real-time requirements and your tolerance for carrying global state around, you could define a global variable, e.g. unsigned char g_led_data;
, and assign the individual LED states e.g. using g_led_data &= 0xef;
to indicate you want to turn off LED4. Then from your main loop, you can call a function which writes the value from g_led_data
to the hardware:
/* Call this from the main loop. */
void update_leds( void )
{
P1.0 = ( g_led_data & 0x01 );
P1.3 = ( g_led_data & 0x02 ) >> 1;
...
}
The advantage of this approach is that it minimizes the amount of time you're spending in a function call to set the LED values - you only call the function once per iteration of the main loop, rather than every time your code sets the value of a particular LED. The disadvantage is the aforementioned effect on real-time performance and now you have to carry a little bit more global state.