English
Language : 

HD6433802H Datasheet, PDF (71/435 Pages) Hitachi Semiconductor – Single-Chip Microcomputer
2. Bit manipulation in a register containing a write-only bit
Example 3: BCLR instruction executed designating port 3 control register PCR3
As in the examples above, P37 and P36 are input pins, with a low-level signal input at P37 and a
high-level signal at P36. The remaining pins, P35 to P31, are output pins that output low-level
signals. In this example, the BCLR instruction is used to change pin P31 to an input port. It is
assumed that a high-level signal will be input to this input pin.
[A: Prior to executing BCLR]
P37
Input/output Input
P36
Input
P35
P34
P33
P32
P31
—
Output Output Output Output Output —
Pin state Low level High level Low level Low level Low level Low level Low level —
PCR3
0
0
1
1
1
1
1
1
PDR3
1
0
0
0
0
0
0
1
[B: BCLR instruction executed]
BCLR #1 , @PCR3
The BCLR instruction is executed designating PCR3.
[C: After executing BCLR]
P37
P36
P35
P34
P33
P32
P31
—
Input/output Output Output Output Output Output Output Input —
Pin state Low level High level Low level Low level Low level Low level High level —
PCR3
1
1
1
1
1
1
0
1
PDR3
1
0
0
0
0
0
0
1
[D: Explanation of how BCLR operates]
When the BCLR instruction is executed, first the CPU reads PCR3. Since PCR3 is a write-only
register, the CPU reads a value of H'FF, even though the PCR3 value is actually H'3F.
Next, the CPU clears bit 1 in the read data to 0, changing the data to H'FD. Finally, this value
(H'FD) is written to PCR3 and BCLR instruction execution ends.
As a result of this operation, bit 1 in PCR3 becomes 0, making P31 an input port. However, bits 7
and 6 in PCR3 change to 1, so that P37 and P36 change from input pins to output pins.
To avoid this problem, store a copy of the PCR3 data in a work area in memory. Perform the bit
manipulation on the data in the work area, then write this data to PCR3.
53