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 : :
(Empty)
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?
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.
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
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)
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