Microcontroller Lecture #8
Microcontroller Lecture #8
1
Week 8
Biomedical Engineering Department
College of Engineering
Imam Abdulrahman Bin Faisal University, Saudi Arabia
Today's topic
5-Arithmetic, Logic
3-Branch, Call and Time 4-PIC I/O Port
Instructions, and
Delay Loop Programming
Programs
2
Today’s lecture
Code addition instructions for unsigned data
Perform addition of BCD data
Using DAW command
3
ARITHMETIC INSTRUCTIONS
Unsigned numbers are the data in which all the bits are used to
represent data, and no bits are set aside for the positive or
negative sign.
4
Addition of unsigned numbers
In PIC 18, WREG register is used to add the numbers together.
one form of the ADD instruction is
5
Example 5-1
Show how the flag register is affected by the following
instructions.
6
ADDWF and addition of individual bytes
Notice the use of ADDWF for the lower byte and ADDWFC for
the higher byte. 10
BCD (binary coded decimal) number system
BCD stands for binary coded decimal. BCD is needed because
in everyday life we use the digits 0 to 9 for numbers, not
binary or hex numbers.
11
Unpacked BCD
In unpacked BCD, the lower 4 bits of the number represent the BCD
number, and the rest of the bits are 0
A BCD number can only have digits from 0000 to 1001 (or 0 to 9). In
other words, adding two BCD numbers must give a BCD result
The DAW instruction will add 6 to the lower nibble or higher nibble
if needed; otherwise, it will leave the result alone. The following
example will clarify these points
In reality there is no use for the DC (auxiliary carry) flag bit
other than for BCD addition and correction
16
Examine the case of adding 55H and 77H. This will result in
CEH, which is incorrect as far as BCD is concerned
The PIC does not require the use of arithmetic instructions prior
to execution of the "DAW" instruction.
(0C)
17
Example 5-4
Assume that 4 BCD data items are stored in RAM locations starting at 40H, as shown
below. Write a program to find the sum of all the numbers. The result must be in BCD.
18