beautypg.com

2 input function, Nput, Unction – Maxim Integrated Secure Microcontroller User Manual

Page 103

background image

Secure Microcontroller User’s Guide

103 of 187

Figure 12-5. Parallel Port Output Buffers (Ports 1, 2, and 3)

12.2 Input Function

Any port pin can be used as a general purpose input by simply writing a logic 1 into the associated SFR
latch. Ports 1, 2, and 3 have weak pullups, so they will go to a logic 1 state. However, the pullup is
sufficiently weak that an external circuit can easily overdrive it with a logic 0. Thus an output of 1 and an
input are the same state. After setting the latch to a 1, the port can be read. If an external circuit drives
high, reading the port will show a 1. If the external circuit drives low, the internal pullup will be
overcome and the pin will be low. Thus the read operation will see a logic 0. Port 0 is different in that it
has no pullup. Thus writing a 1 into the Port 0 latch causes the pin to tri-state. An external pullup should
be used. In the input state, the external circuit would overdrive the external pullup on Port 0.

It can be seen in

Figure 12-1

through

Figure 12-4

that the CPU can read the latch or the pin. These need

not have identical values. A normal read instruction reads the state of the pin. It neither reads nor
modifies the state of the latch. For example, if software writes the latch of Port 1 with an FFh, the port
will output all high values, and also be configured as an input. If an external circuit pulls down the lower
four bits, a read instruction would see F0h. The latch would still contain FFh. If the external circuit were
to release the four lower bits, the port would return to the value of FFh.

There are a selected number of instructions that read the latch instead of the pin. These are called Read-
Modify-Write instructions. These instructions read the state of the latch, possibly modify it, then write the
result back to the latch. This means that the operation takes place on the value that was originally written
to the latch by the software.