Function Question.

General discussion on mikroC.
Post Reply
Author
Message
iamspeedbump
Posts: 6
Joined: 19 Jan 2007 21:41

Function Question.

#1 Post by iamspeedbump » 23 Nov 2010 08:01

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);
}

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: Function Question.

#2 Post by slavisa.zlatanovic » 01 Dec 2010 13:50

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);
}
Best regards
Slavisa

iamspeedbump
Posts: 6
Joined: 19 Jan 2007 21:41

Re: Function Question.

#3 Post by iamspeedbump » 02 Dec 2010 05:05

Thank you. That was very helpful.

Post Reply

Return to “mikroC General”