1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Testing all ports on a reset

Discussion in 'Embedded' started by SpeedPig, Sep 24, 2009.

  1. SpeedPig

    SpeedPig Guest

    HI All

    Is there a quick way to step sequentially through all the I/O Lines of
    the 4 ports in the AT89???? microcontroller

    Currently I'm doing it in 4 seperate steps in Assembly language, but
    my gut feel tells me it can be done in one subroutine

    Port1 : CPL P0.1
    CPL P0.7
    Port2: CPL P1.1
    CPL P1.7
    .... and so on

    I need to test that all ports are working everytime I reset my
    circuit, and all 32 ports are fed through AND gates to give me either
    a '1' or '0' should any port of the microcontroler maybe goes faulty

    Thank you in advance
    SpeedPig, Sep 24, 2009
    1. Advertisements

  2. SpeedPig

    TTman Guest

    A bit pointless.. but
    The ports are at addresses 80 90 A0 B0.
    So set the msb in 80, 90 A0 and B0.
    Then ROR 80 90 A0 and B0...
    Use a register to set a lop count of 8...
    Or maybe you just want to set all ports to 0 so the outputs of the nand
    gates are(should) all go hi.
    something like
    clr acc
    mov P0,acc
    mov P1,acc
    TTman, Sep 24, 2009
    1. Advertisements

  3. SpeedPig

    Jim Stewart Guest

    Leave it as-is.

    Five years from now some poor tech will be looking
    through your code and he/she will appreciate your
    lack of cleverness.
    Jim Stewart, Sep 24, 2009
  4. SpeedPig

    TTman Guest

    VERY TRUE ! :)
    TTman, Sep 24, 2009
  5. SpeedPig

    ChrisQ Guest

    You don't need to do it in asm. Do it in C, declare a structure of two
    elements, port address and expected value, Use a table of these to
    represent the ports of interest. Then, a simple loop to read the port
    and compare against table value.

    The advantage is that you can add or delete as many ports as you like
    and it's portable to other projects for similar tasks. You can use the
    same trick to initialise the ports to start with, even the same table
    with added structure elements...


    ChrisQ, Sep 25, 2009
  6. Nice plan, but impossible. We're dealing with an 8051 derivate here.
    No such thing as a pointer to a port (SFR) or pin (bit addressing) on
    those, so no way to put the address of one into a C data structure.

    Depending on what the OP even means by "testing" ports, it may be easier
    to change all pins of one ports in a single operation, though:

    P0 ^= 0xff;
    P1 ^= 0xff;
    Hans-Bernhard Bröker, Sep 25, 2009
  7. SpeedPig

    ChrisQ Guest

    You're right, checked and no indirect addressing to sfr map. You can
    still use c and a table, though for 4 ports it's trivial to do as
    straight line comparison with the expected values as defines...


    ChrisQ, Sep 25, 2009
  8. SpeedPig

    SpeedPig Guest

    Thank you - I kept my original idea. Will play around with the "P0 ^=
    0xff;" idea - looks like it can work
    Thanks and regards
    Lodewicus Maas
    SpeedPig, Sep 28, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.