Discussion Forum

sbit ptr? (best method for port and bit identification)

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

DetailsMessage
Read-Only
Author
Bahri Okuroglu
Posted
19-Oct-2001 07:19 GMT
Toolset
C51
New! sbit ptr? (best method for port and bit identification)
Dear all,

My board will have several inputs connected to P0-P3. The PC will instruct the microcontroller using RS232, to monitor some of the inputs.

The communication between the PC and the 8051 will be somewhat like below:

PC->8051: 
   count the state changes on P0.3
   count the state changes on P0.6
                :
                :
   inform me on any change of the state of P1.5
   inform me on any change of the state of P3.4
                :
                :

This way, I'm trying to build a generic data acquision board which will be configured by the PC.

However, not to use a "case" statement for every bit of every port on the microcontroller, it should use somewhat like sbit pointer.

Is this possible?

Or what is the best way to find which bit of the which port to listen, using the information of [x, y] provided by PC (where x is the port number, and y is the bit offset in the port).

Regards,
Read-Only
Author
Mike Kleshov
Posted
19-Oct-2001 10:10 GMT
Toolset
C51
New! bitN = (bit)(word & (1 << N));
(Empty)
Read-Only
Author
Bahri Okuroglu
Posted
19-Oct-2001 10:24 GMT
Toolset
C51
New! RE: bitN = (bit)(word & (1 << N));
Mike,

You're right, this is the way I use in some programs. But this time, CPU's main job will be scanning the given ports and your solutions takes too much realtime from the system.

If there exist a simpler method, sampling rate of the inputs will increase automatically.

Besides these, is it possible to define a sfr/sbit array?
Read-Only
Author
Mike Kleshov
Posted
19-Oct-2001 11:12 GMT
Toolset
C51
New! RE: bitN = (bit)(word & (1 << N));
I'm not familiar with the 8051 instruction set since I'm working with C166. But assuming that there is no difference between them in this regard it's impossible to define an array of bits or a pointer to a bit (simply because there are no CPU instructions to support this).
If I tryed to implement the same thing with C166 and was concerned about speed, I would build port-scanning code somewhere in RAM (on the fly, during program execution) and pass control there. Thus I would be able to do whatever testing I wanted at maximum speed.
Read-Only
Author
Jon Ward
Posted
19-Oct-2001 23:25 GMT
Toolset
C51
New! RE: sbit ptr? (best method for port and bit identification)
Take a look at the following knowledgebase article. It allows you to access a generic SFR or SBIT whose value is not known at compile time.

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

Jon
Read-Only
Author
Bahri Okuroglu
Posted
21-Oct-2001 19:36 GMT
Toolset
C51
New! RE: sbit ptr? (best method for port and bit identification)
Jon,

Thanks for the reply. Your link gives a method for libraries which needs access to extarnal SFRs.

As another document says, the structure I described if impossible to do. See below:

"C51: GENERAL PURPOSE SFR INTERFACE" (http://www.keil.com/support/docs/185.htm)
Read-Only
Author
Jon Ward
Posted
23-Oct-2001 02:25 GMT
Toolset
C51
New! RE: sbit ptr? (best method for port and bit identification)
Ahhh. If you pass the Port information to a program that is already compiled and linked then you must do something like the switch statement.

I seem to recall that someone did something similar but either they use von Neuman RAM and wrote the instruction to XDATA (and executed it from CODE) or created an assembly switch that was really efficient.

Jon

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