Hello:
I'm deveoping a simple IO driver for the Renesas 78K0R family of microcontrollers.
For now I have 2 functions:
bool Get_Port (unsigned char port_id, unsigned char pin_mask)
void Set_port (unsigned char port_id, unsigned char pin_mask, bool value).
For example in the Set_port function I have a switch case which checks for all the ports that belong to this micro, something like:
#define PORT1 0
#define PORT2 1
switch(port_id):
case PORT1:
value == TRUE? (P1|=pin_mask1 &= ~pin_mask);
case PORT2:
value == TRUE? (P2|=pin_mask2 &= ~pin_mask);
.
.
.
.
As you can see the logic is very simple. If for example I want to turn on a LED I just pass a value of 1. If I want to turn it off I pass a value of 0.
Is there any way to make the port number as a parameter so I don't have to use a lot of switch..case statements?
Otherwise if I have 10 different ports I will have to create 10 different switch..case statements.
Thanks and help is greatly appreciated
I'm deveoping a simple IO driver for the Renesas 78K0R family of microcontrollers.
For now I have 2 functions:
bool Get_Port (unsigned char port_id, unsigned char pin_mask)
void Set_port (unsigned char port_id, unsigned char pin_mask, bool value).
For example in the Set_port function I have a switch case which checks for all the ports that belong to this micro, something like:
#define PORT1 0
#define PORT2 1
switch(port_id):
case PORT1:
value == TRUE? (P1|=pin_mask1 &= ~pin_mask);
case PORT2:
value == TRUE? (P2|=pin_mask2 &= ~pin_mask);
.
.
.
.
As you can see the logic is very simple. If for example I want to turn on a LED I just pass a value of 1. If I want to turn it off I pass a value of 0.
Is there any way to make the port number as a parameter so I don't have to use a lot of switch..case statements?
Otherwise if I have 10 different ports I will have to create 10 different switch..case statements.
Thanks and help is greatly appreciated