Discussion Forum

Syntax? "sbit * ptr2sbit;"

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Dave S.
Posted
7-Aug-2001 17:04 GMT
Toolset
C166
New! Syntax? "sbit * ptr2sbit;"
Is it possible using the C16x tools to create a variable that's a pointer
to an sbit? I'm trying to find a way to allow a function in a custom
library to not need to know where an I/O pin is until the user of the
library informs it via a library initialization function call.

For example, if there was a blink LED function, where that LED was on a
different I/O port pin on different pcbs, the user of the library could
inform the library function where the I/O pin was, by passing it the
address of the sfr bit. It seems to me that in order to be able to make
this work, I need to be able to create a "pointer to sbit" type of variable
in my library.

Help,
Dave.
Read-Only
Author
Mike Kleshov
Posted
7-Aug-2001 18:05 GMT
Toolset
C166
New! RE: Syntax?
As it is said in C166 compiler description, pointers to bits are not supported (which is easy to understand: there are no such instructions in C166/C167 instruction set). It seems that the only way to do what you want is to pass to the library function address of I/O port and bit number. For example:

void SetPortBit(int* PortAddress, int BitNumber)
{
*PortAddress |= (1 << BitNumber);
}

void main(void)
{
DP2 = 0xFFFF;
SetPortBit(&P2, 15);
}
Read-Only
Author
Dave S.
Posted
7-Aug-2001 19:12 GMT
Toolset
C166
New! RE: Syntax? Thanks!
Thanks...! I was pretty sure I remembered reading that somewhere in
the C166 manual, but I didn't find that text when I went back and
looked for it. Your suggestion will probably work just fine for what I
want to do.

Thanks again,
Dave.
Read-Only
Author
Jon Ward
Posted
7-Aug-2001 21:27 GMT
Toolset
C166
New! RE: Syntax?
You can create an EXTERNAL definition for the bit in your library. Then, in your main program, declare the bit.

Refer to the following for an example of doing this with the 8051 tools:

http://www.keil.com/support/docs/168.htm

Jon

Next Thread | Thread List | Previous Thread Start a Thread | Settings