
Before Execution of BSET Instruction
Execution of BSET Instruction
BSET.B #0, @PORT4
;set bit 0 in data register
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 reserving a byte in RAM as a temporary register for P4DR and using it as follows.
RAM0 is a symbol for the user-selected address of the temporary register.
P4
7
Input
Low
0
1
On
P4
6
Input
High
0
0
Off
P4
5
Output Output Output Output Output Output
Low
Low
Low
1
1
1
0
0
0
Off
Off
Off
P4
4
P4
3
P4
2
P4
1
P4
0
Input/output
Pin state
DDR
DR
Pull-up Mos
Low
1
0
Off
Low
1
0
Off
Low
1
0
Off
P4
7
Input
Low
0
0
Off
P4
6
Input
High
0
1
On
P4
5
Output Output Output Output Output Output
Low
Low
Low
1
1
1
0
0
0
Off
Off
Off
P4
4
P4
3
P4
2
P4
1
P4
0
Input/output
Pin state
DDR
DR
Pull-up
Low
1
0
Off
Low
1
0
Off
High
1
1
Off
44