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

Programable relationship between pins

Dear members,

I have the following problem: I need that the state of some pins of an 8051 being a logical function of the state of other pins. The difficult is that the logical function must be programmable.
For example: I need that logical state of pin P1.0 must be a logical function of pins P1.1 and P1.2 and the logical functions could be "AND", "OR", or "XOR". I am using an AT89S8252 with 2K of internal EEPROM.
I need some advice, tips, ideas, etc. about how to implement this.
Thanks in advance for your help.

best regards,
JLR
(rodribaires@hotmail.com)

  • You might enjoy an internet search on Mealy and Moore state machines. What are you trying to implement?
    1. scan your input port
    2. evaluate an internal variable for each possible logic function.
    3. send the appropriate variable to the output port
    4.repeat steps 1-3.

  • the logical function must be programmable\

    Programmable by whom, with what tools, and on what timescale?

    The 8051 itself allows you to program an arbitrary logic function. You read some pins, write some code to calculate the output, and write the output. To change the function calculated, of course, you need your compiler/assembler and the ability to update the program store on the 8051.

    Presumably, though, you want to update the actual logic function implemented without actually changing the 8051 program. That is, you need some sort of user interface (DIP switches connected to yet other input port pins, command line interface over a RS-232 link). You might then write a program that has a number of pre-defined functions, and take input from the user to set the function used. Adding new functions would again require you to drag out the compiler and flash programmer.

    Yet another alternative is to create a generic program that takes a table that defines the function to be produced from inputs. This table would have some sort of syntax to describe inputs, outputs, and the functions in between. Users would then have to alter that table to change the function -- perhaps by uploading a new table over the UART, or by reprogramming a designated section of flash, or toggling in a new table with DIP switches. The "table" could even be executable code, in which case you essentially have field-upgraded firmware for your system. A simpler version might just be a bunch of tuples that describe one of the 16 possible binary logic operators, operands for each, and where the result goes.

    You need to refine your requirements to be a little more precise before you can really answer the question.

  • Thanks for the hint :D

    I am trying to implement some sort of PLC, so the user sends the relationship between pins to the uC using the serial port, and I am looking for ideas about how to implement it, i.e: how to store the relationship, how to evaluate the relationship, etc. I am starting with pins only but I also need to add counters and relationships like P3.2 = (P3.1 & (counter > 0x7F))
    By the way, I am using C as programming language

    cheers,
    JLR

  • Dear Drew,

    Thanks for your point, I see that the original post is a bit confusing, I need to implement some sort of PLC, so the user downloads the relationships to the uC using the serial port, the user could change the relationships any time. I am starting with pin relationships, but I also need to add relationships with counters, like P3.2 = (P3.1 & (counter > 0x7F))
    I am using C as programming language, so I am looking for ideas about how to implement this, i.e: how to store the relationship, how to evaluate the relationship, etc.

    cheers,
    JLR

  • I am trying to implement some sort of PLC
    Hang it up. No PLC user I have ever met would be willing to use anything but ladder logic.
    Making the PLC unit is trivial compared to the PC software for entering and interpreting the ladder.

    This does not mean that some PLC applications, namely those where the same program is loaded in many units, can not be replaced by dedicated '51 boards. Just do not call it a PLC (end user programmable), it never will be. I know of a cases where companies that did a PLC replacement ended up spending so much on programming support of the units that replacing the PLCs came out as a huge loss.

    Erik