Page 1 of 1

Function Question.

Posted: 23 Nov 2010 08:01
by iamspeedbump
How would you pass a port into a function so that you can read or write to a givin pin? Code example below

int SampleCode(unsigned short MyPort, unsigned int PortPin)
{
if(MyPort.PortPin == 1)
{
return 100;
}
else
{
return 10;
}
}

void DoSomething()
{
PORTB = SampleCode(PORTC,3);
}

Re: Function Question.

Posted: 01 Dec 2010 13:50
by slavisa.zlatanovic
Hi!

Following routines use port and pin number as input parameters:

Code: Select all

SetBit(unsigned short *port,   unsigned short pin {
 *port |=  1 << pin;
}

ClearBit(unsigned short *port,   unsigned short pin {
 *port &=  ~(1 << pin);
}

Re: Function Question.

Posted: 02 Dec 2010 05:05
by iamspeedbump
Thank you. That was very helpful.