
Rev. 1.00
1�� of ���
�an�a�� 1�� �01�
Standard 8051 8-Bit Flash MCU
HT85F2260/HT85F2270/HT85F2280
Input/Output Ports
Input/Output Ports
Programming Considerations
Within the user program, one of the first things to consider is port initialisation. After a reset, the
I/O data register will be set high and I/O port mode registers will be cleared to low. This means that
all I/O pins will default to a Quasi-bidirectional structure. The I/O pins can be re-assigned to some
other mode for each I/O using the control registers, PnM0 and PnM1. Ports P0~P3 provide four I/O
structure modes option while the P4 and P5 only provide a Quasi-bidirectional I/O structure mode.
Care should be taken to setup the correct I/O structure for each I/O pin, otherwise unexpected data
will be input or output on the I/O pins.
The data registers, P0~P5, reflect the value of the corresponding I/O port, however, they do not
necessarily reflect the I/O pin logic state. During reading and writing of data to these registers,
what actually happens is dependent upon whether the corresponding pin is setup as an output or
input. A write operation is only effective when the corresponding pin is setup as an output. In such
cases a write operation will setup the logic level, low or high, on the pin. A read operation will read
the current logic level, low or high, on the corresponding pin.
If any pins are setup to be used as A/D input pins then it is important to ensure that the I/O Port
Mode registers setup the pins as inputs, which are essentially high impedance inputs. In this way
the I/O logic circuits will have a minimal influence on the A/D input impedance.
When using these bit control instructions, a read-modify-write operation takes place. The
microcontroller must first read in the data on the entire port, modify it to the required new bit
values and then rewrite this data back to the output ports, such as using CLR or SET bit write
instructions. Care should be taken that some instructions, the Read-Modify-Write instructions,
operate on the Pn register, such as “INC P0” or “ANL P2, A”, while others can operate directly
onto the external port input, such as “MOV A, P1”. Note that P4 and P5 cannot be modified by
bit manipulation instructions as their registers are not located in bit addressable space. In case of
reading, the state of P4 and P5 registers reflects the value of the corresponding I/O port.
The accompanying table illustrates the Read-Modify-Write related instructions.
Mnemonic
Instruction
Example
Bit Manipulation
ANL
Logical AND
ANL P3� A
—
ORL
Logical OR
OR P3� A
—
XRL
Logical XOR
XRL P3� A
—
�BC
��mp if bit set and then clea� bit
�BC P3.0� (LABEL)
—
CPL
Complement bit
CPL P3.0
—
INC
Inc�ement
INC P3
—
DEC
Dec�ement
DEC P3
—
D�NZ
Dec�ement and j�mp if not ze�o
D�NZ P3� (LABEL)
—
MOV Px.�� C
Move carry flag to Bit y of Port x
MOV P3.0� C
V
CLR Px.�
Clea� Bit � of Po�t x
CLR P3.0
V
SET Px.�
Set Bit � of Po�t x
SET P3.0
V