This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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,

Parents
  • 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?

Reply
  • 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?

Children
  • 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.