passing a sbit to a function

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
SteveH
Posts: 36
Joined: 13 Mar 2008 23:10
Location: UK

passing a sbit to a function

#1 Post by SteveH » 19 Sep 2022 23:02

Hi,

I have the following bit defined

sbit MY_BIT at GPIOA_ODR.B0

Is it possible to pass this to a function, possibly like this ? - ditto for an IDR bit

MyFunction(MY_BIT) ;

void MyFunction(unsigned long mySbit) { // probably unsigned long is wrong type ?
...
mySbit = 1 ;
...
}

Any help on this appreciated - it would save repeating a large code block six times that is only different by two sbits.
Steve

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: passing a sbit to a function

#2 Post by Thomas.Pahl@t-online.de » 20 Sep 2022 14:43

a bit has no adress
perhaps pass the port and the bit number

SteveH
Posts: 36
Joined: 13 Mar 2008 23:10
Location: UK

Re: passing a sbit to a function

#3 Post by SteveH » 20 Sep 2022 17:00

Thanks for the reply.

After much testing, head scratching and every syntax I could think of I've given up on a direct solution. I've ended up just passing an index to the function that I can use in a switch statement to get to the correct sbits in a short a space as possible.

Steve

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: passing a sbit to a function

#4 Post by filip » 21 Sep 2022 12:42

Hi,

The sbit type cannot be used for argument lists, and function-return values.

Regards,
Filip.

Post Reply

Return to “mikroC PRO for ARM General”