Testing all ports on a reset

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

Reply to
SpeedPig
Loading thread data ...

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... etc. 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 etc.

Reply to
TTman

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.

Reply to
Jim Stewart

VERY TRUE ! :)

Reply to
TTman

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

Regards,

Chris

Reply to
ChrisQ

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; /*...*/

Reply to
Hans-Bernhard Bröker

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

Regards,

Chris

Reply to
ChrisQ

No

r

Thank you - I kept my original idea. Will play around with the "P0 ^=3D

0xff;" idea - looks like it can work Thanks and regards Lodewicus Maas
Reply to
SpeedPig

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.