Your root issue is that you want to send a set of port pins to a function.
Port Pins are not strings
The identifiers PORTA
and the like are not strings. They are reserved words for the PIC compilers. They represent an addressible location (either port or memory mapped).
The dot notation, PORTA.3
, refers to a bit number of the port.
The counter example would be copying a value to `"PORT_FROG.8".
Have you tried using the following:
const char port_a_3[] = "PORTA.3";
*port_a_3 = 5;
The problem is that the last statement modifies a text literal and does't write to the port.
Passing Port Pins to a function
You will need to look up the syntax for passing the address of a port bit, and how to pass the address of a port. If there is no documentation or examples, things will get complex.
The most portable method would be to create a Port
class and pass around instances of that or you could use some kind of std::pair
where you supply a port ID and a bit number.
More efficient hardware design
A more intriguing question: Is your platform designed efficiently?
Usually, you can convince hardware folk to place lines of similar functionality next to each other. This way, you can take a snapshot of their status by reading the entire port instead of reading different bits from different ports.
Unifying Port Bits
I highly suggest that you write a function that reads the specified disjoint bits into one number and another function that can write them. In this concept, you will have all the status in one unit and can pass that status around to functions. If you need to write to the disjoint pins as a group, you can call your write
function.
Summary
The root requirement is that you want to pass a set of port pin addresses to functions so that they can read and write to port pins. This is not available in standard C++, so you will have to look at your PIC compiler documentation to see if it is possible. There are other alternatives, such as passing around models of ports; port & bit pairs; coding functions that read and write multiple pins into one status unit; or changing the hardware to make the software easier to develop. Sorry, but the port identifiers are not text literals or strings and cannot be manipulated that way.
Edit 1:
You may be able to pass a structure that is mapped to a port. Again, look at the compiler documentation.
Example:
struct MyPort_Model
{
unsigned int bit_0 : 1;
unsigned int bit_1 : 1;
unsigned int bit_2 : 1;
unsigned int bit_3 : 1;
} my_port_variable @ PORTA;
Another example:
struct Model_4_bit_HW_Item
{
unsigned int MOSI : 1;
unsigned int MISO : 1;
unsigned int clock : 1;
unsigned int chip_select : 1;
unsigned int reserved : 4;
void read_from_port(void)
{
MOSI = PORTA.0;
MISO = PORTA.1;
clock = PORTA.2;
reserved = PORTA.3;
}
};