After Execution of BSET Instruction
Explanation: To execute the BSET instruction, the CPU begins by reading port 4. Since P4
7
and P4
6
are input pins, the CPU reads the level of these pins directly, not the value in the data
register. It reads P4
7
as Low ("0") and P4
6
as High ("1").
Since P4
5
to P4
0
are output pins, for these pins the CPU reads the value in the data register
("0"). The CPU therefore reads the value of port 4 as H'40, although the actual value in P4DR
is H'80.
Next the CPU sets bit 0 of the read data to "1," changing the value to H'41.
Finally, the CPU writes this value (H'41) back to P4DR to complete the BSET instruction.
As a result, bit P4
0
is set to "1," switching pin P4
0
to High output. In addition, bits P4
7
and
P4
6
are both modified, changing the on/off settings of the MOS pull-up transistors of pins P4
7
and P4
6
.
Programming Solution: The switching of the pull-ups for P4
7
and P4
6
in example 2 can be
avoided by storing the same data in both the port-4 data register and in a work area in RAM.
Bit manipulations are performed on the data in the work area, after which the result is moved
into the port-4 data register. In the following example RAM0 is a symbol for the user-selected
address of the work area.
Before Execution of BSET Instruction
MOV.B #80 R0L
;
write data (H'80) for data register
MOV.B R0L @RAM0
;
write to DR work area (RAM0)
MOV.B R0L @PORT4
;
write to DR
P4
7
P4
6
P4
5
P4
4
P4
3
P4
2
P4
1
P4
0
Input/output
Input
Input
Output Output Output Output Output Output
Pin state
Low
High
Low
Low
Low
Low
Low
High
DDR
0
0
1
1
1
1
1
1
DR
0
1
0
0
0
0
0
1
Pull-up
Off
On
Off
Off
Off
Off
Off
Off
19
Содержание H8/300 Series
Страница 2: ...H8 300 Programming Manual...