SX Users Manual Rev. 3.1
144
© 2000 Scenix Semiconductor, Inc. All rights reserved.
www.scenix.com
Chapter 5 Input/Output Ports
The second mov instruction in this example writes the Port A data register (RA), which controls the
output levels of the four Port A pins, RA0 through RA3. Because Port A has only four I/O pins in this
example, only the four least significant bits of this register are used. The four high-order register bits
are dont care bits.
To use all four Port A pins as inputs, you would first configure them to operate as inputs and then read
them using code such as the following:
mov
W,$05
;move data from Port A into W
Note that pins can be individually configured within a port. For example, you could use some pins of
Port A as inputs and others as outputs. For information on configuring the port pins, see Section 5.3.
When a write is performed to a bit position for a port that has been configured as an input, a write to
the port data register is still performed, but it has no immediate effect on the pin. If later the pin is
configured to operate as an output, it will reflect the value that has been written to the data register.
For the SX48/52BD, a control bit called PORTRD in the T2CNT2 register determines how the device
reads data from its I/O ports. Clear this bit to 0 to have the device read data directly from the port I/O
pins (the default operating mode). Set this bit to 1 to have the device read data from the port data
registers. Under normal conditions, it should not matter which method you use to read the port data.
However, if a port pin is configured as an output and an external circuit forces the pin to the wrong
value, the value read from the port will depend on the reading mode used.
The SX18/20/28AC and SX18/20/28AC75 always reads data directly from the port I/O pin, like the
default operating mode of the SX48/52BD.
When you read from a bit position for a port in the default operating mode, you are actually reading
the voltage level on the pin itself, not necessarily the bit value stored in the port data register. This is
true whether the pin is configured to operate as an input or an output. Therefore, with the pin
configured to operate as an input, the data register contents have no effect on the value that you read.
With the pin configured to operate as an output, what you read generally matches what has been written
to the register.
When you use two successive read-modify-write instruction on the same I/O port with a very high
clock rate, the write part of one instruction might not occur soon enough before the read part of
the very next instruction, resulting in getting old data for the second instruction. To ensure
predictable results, avoid using two successive read-modify-write instructions that access the same
port data register if the clock rate is high. For more information on this topic, see Section 2.5.3.
5.3
Port Configuration
Each port pin offers the following configuration options:
data direction
input voltage levels (TTL or CMOS)
pullup type (enable or disable)