Bit Manipulation - Motorola MC6805R Series Advance Information

8-bit microcomputers
Table of Contents

Advertisement

10.1 BIT MANIPULATION
SECTION 10
SOFTWARE
The microcomputers have the ability to set or clear any single RAM or liD bit (except the data direc-
tion registers) with a single instruction (BSET, BCLR) (see Caution below). Any bit in page zero
can be tested using the BRSET and BRCLR instructions and the program branches as a result of its
state. The carry bit equals the value of the bit references by BRSET or BRCLR. The capability of
working with any bit in RAM, ROM, or liD allows the user to have individual flags in RAM or to
handle single liD bits as control lines.
CAUTION
The corresponding data direction registers for ports A, B, and C are write-only registers
(locations $004, $005, and $006), A read operation on these registers is undefined. Since
BSET and BCLR are read-modify-write functions, they cannot be used to set a data direc-
tion regiser bit (all "unaffected" bits would be set). It is recommended that all data direc-
tion register bits in a port be written using a single-store instruction.
The coding examples shown in Figure 10-1 illustrate the usefulness of the bit manipulation and test
instruction. Assume that the microcomputer is to communicate with an external serial device. The
external device has a data ready signal, a data output line, and a clock line to clock data one bit at a
time, least significant bit first out of the device. The microcomputer waits until the data is ready,
clocks the external device, picks up the data in the carry flag, clears the clock line, and finally
accumulates the data bit in a random-access memory location.
READY
Serial
Clock
Device
Data
I - - -
2 p
,
~
T
OA
-
MCU
SELF
BRSET
2,PORTA,SELF
BSET
1 ,PORTA
BRCLR
O,PORTA,CONT
CONT
BCLR
I,PORTA
ROR
RAMLOC
Figure 10-1. Bit Manipulation Examples
10-1

Advertisement

Table of Contents
loading

Table of Contents