background image
© 2005 Ubicom, Inc. All rights reserved.
- 9 -
www.ubicom.com
SX20AC/SX28AC
3.1.1 Read-Modify-Write Considerations
When two successive instructions are used on the same
I/O port (except "mov Rx,W") 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 or, insert 3 NOP
instructions between the successive read-modify-write
instructions (if SYNC bit in the FUSE register is enabled,
5 NOP instructions are required), for operating frequen-
cies of 50 MHz or lower.
Also note that reading an I/O port is actually reading the
pins, not the output data latches. That is, if the pin output
driver is enabled and driven high while the pin is held low
externally, the port pin will read low.
3.2 Port Configuration
Each port pin offers the following configuration options:
· direction (input or output)
· input voltage levels (TTL or CMOS)
· pullup type (pullup resistor enable or disable)
· Schmitt trigger input (for Port B and Port C only)
Port B offers the additional option to use the port pins for
the Multi-Input Wakeup/Interrupt function and/or the ana-
log comparator function.
Port configuration is performed by writing to a set of
direction registers associated with the port. A special-pur-
pose instruction is used to write these direction registers:
· mov !RA,W (move W to Port A direction register)
· mov !RB,W (move W to Port B direction register)
· mov !RC,W (move W to Port C direction register)
Each one of these instructions writes a port direction reg-
ister for Port A, Port B, or Port C. There are multiple
direction registers for each port. To specify which one you
want to access, you use another register called the
MODE register.
3.2.1 MODE Register
The MODE register controls access to the port configura-
tion registers. Because the MODE register is not mem-
ory-mapped, it is accessed by the following special-
purpose instructions:
· mov M, #lit (move literal to MODE register)
· mov M,W (move W to MODE register)
· mov W,M (move MODE register to W)
The value contained in the MODE register determines
which port direction register is accessed by the "mov
!rx,W" instruction as indicated in Table 3-3. MODE regis-
ter values not listed in the table are reserved for future
expansion and should not be used. Therefore, the MODE
register should always contain a value from 08h to 0Fh.
Upon reset, the MODE register is initialized to 0Fh, which
enables access to the port direction registers.
After a value is written to the MODE register, that setting
remains in effect until it is changed by writing to the
MODE register again. For example, you can write the
value 0Eh to the MODE register just once, and then write
to each of the three pullup configuration registers using
the three "mov !rx,W" instructions.
The following code example shows how to program the
pullup control registers.
First the MODE register is loaded with 0Eh to select
access to the pullup control registers (PLP_A, PLP_B,
and PLP_C). Then the MOV !rx,W instructions are used
to specify which port pins are to be connected to the
internal pullup resistors. Setting a bit to 1 disconnects the
corresponding pullup resistor, and clearing a bit to 0 con-
nects the corresponding pullup resistor.
3.2.2 Port Configuration Registers
The port configuration registers that are controlled with
the MOV !rx,W instruction operate as described below.
RA, RB, and RC Direction Registers (MODE=0Fh)
Each register bit sets the direction for one port pin. Set
the bit to 1 to make the pin operate as a high-impedance
input. Clear the bit to 0 to make the pin operate as an out-
put.
Table 3-3. MODE Register and Port
Direction Register Access
MODE Reg. mov !RA,W mov !RB,W mov !RC,W
08h
not used
CMP_B
not used
09h
not used
WKPND_B
not used
0Ah
not used
WKED_B
not used
0Bh
not used
WKEN_B
not used
0Ch
not used
ST_B
ST_C
0Dh
LVL_A
LVL_B
LVL_C
0Eh
PLP_A
PLP_B
PLP_C
0Fh
RA Direction
RB Direction
RC Direction
mov M,#$0E
;MODE=0Eh to access port pullup
;registers
mov W,#$03
;W = 0000 0011
mov !RA,W
;disable pullups for A0 and A1
mov W,#$FF
;W = 1111 1111
mov !RB,W
;disable all pullups for B0-B7
mov W,#$00
;W = 0000 0000
mov !RC,W
;enable all pullups for C0-C7