|
So what's new in this program?
First of all I show a different way of keeping a copy of the output port.
Until now we have kept a copy of the output port in a processor register.
In this example we keep a copy of the output port in the output port itself!
This can be done with the 8255 because reading the port will return a copy of the output latch which holds the actual output pattern.
The IN PORTA instruction makes a copy of the output latch in the Accu.
Be careful though! The 8255 is a rather simple I/O device, very suitable for a novice assembly programmer.
More sophisticated I/O devices can mix inputs and outputs on a single output port.
On those devices it is not recommended to use this technique of keeping a copy of the output port, because that may disrupt the input function of the port.
Here's how this program works:
First both ports are initialized with an arbitrary output pattern.
Any pattern will do, all unaffected bits will not change by the actions of this program.
Then we arrive at the line containing the label COUNT.
There we make a copy of the binary counter into the Accu, after which this copy is truncated to 3 bits by the ANI 00000111B instruction.
No matter how many bits are actually counting internally, we will only show the 3 least significant bits.
Then the XRI 00000111B instruction inverts the 3 remaining bits, to adjust for the fact that the LEDs only light when a "0" is output.
The result is then temporarily stored in register B.
Then we read the present contents of the output port using the IN PORTA instruction.
This pattern is masked with the bits that have to remain unchanged, leaving the 3 least significant bits "0".
A simple ORA B instruction will combine both bytes.
ORA again is the OR function, just like ORI, but this time the second operand is held in a processor register instead of being an immediate value.
Now it's time to send the combined byte to the output again.
The DELAY routine is nothing new.
It is followed by the INR B instruction, which adds one to the binary counter.
This completes the program, and we can loop back to the label COUNT.
|