View previous topic :: View next topic |
Author |
Message |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
Function with pin in parameter |
Posted: Wed Mar 05, 2008 3:51 am |
|
|
Hello everybody,
I was wondering what is the best way to have a function with a pin in parameter.
for example:
Code: | DoSomethingWithPin(Pin); |
I was thinking to have for parameters a pointer on the port and the number of the pin like that:
Code: | DoSomethingWithPin(unsigned int* Port, unsigned int PinNumber); |
But in this case I have 2 parameters...
Is it possible to do it with just one parameter like an unsigned int?
Thanks for any help.
Franck. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 05, 2008 12:16 pm |
|
|
Use the CCS pin numbers. These numbers encode the port address
and the bit position of the pin in one number. Use the constants that
are listed in the .H file for your PIC, such as PIN_B1, etc.
The pin numbers consists of the bit position in the lower 3 bits, and
the port address in the upper bits (shifted left by 3 bits). |
|
|
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Wed Mar 05, 2008 2:32 pm |
|
|
Thanks,
It's exactly what I need.
I knew that CCS is encoding the pin with just one integer, but I was not able to understand the code .
Thanks a lot,
Franck. |
|
|
|