hi guys....
I am writing a program. In this program, i have a function which is universal. I am using the GPIO to do serial data sending to several devices connected to my MCU using several pins on a port. The problem now is if this function is universal, how do i pass the pins that i want to the function? i du not want to do the same function for different pins,it will be a waste of space.
Assuming that the function will look like this
Code:
void DataSend(unsigned char data)
{
int a;
for (a = 0;a<8 a++)
{
PORTA.Pin0 = 0; // this will generate the low clock pulse
PORTA.Pin1 = data & 0x01; //this will push the data out
//bit by bit
data >>=1;
PORTA.Pin0 = 1 //this will generate high clock pulse
}
}
If i want to make PORTA.Pinx as universal and i want to use other pin with this function...is it possible?
can i do the following?
Code:
void DataSend(unsigned char data, (dunno what type to use) CLKpin ,(dunno what type to use) DATApin )
{
int a;
for (a = 0;a<8 a++)
{
CLKpin = 0; // this will generate the low clock pulse
DATApin = data & 0x01; //this will push the data out
//bit by bit
data >>=1;
CLKpin = 1 //this will generate high clock pulse
}
}
if in the main i call the function as following
Code:
DATASend('S', PORTA.PIN2,PORTA.pin3)
will this work as if the following?
and
Code:
PORTA.Pin3 = data & 0x01;
As if i am latching the PORTA pin 2 and 3?
Please advise also the type i shuld declare for the pins in the function
thanks