0% found this document useful (0 votes)
7 views

MicroprocessorBasedSystems_Term-I_lec7_LogicOperations

hhhh

Uploaded by

israwagd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

MicroprocessorBasedSystems_Term-I_lec7_LogicOperations

hhhh

Uploaded by

israwagd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

E1321

Microprocessor based Systems I

‘Logic Operations and Programming’

Dr. Ahmed El-Awamry

Date: 09.11.2024, Time: 13:00


Objective

▪ Acquire the proficiency to execute logic


operations, perform data comparisons, and
implement data serialization using assembly
language programming for the 8051
microcontroller. This involves utilizing logical
instructions such as AND, OR, XOR, and NOT
to manipulate data, effectively comparing
values for decision-making processes, and
managing the serialization of data to ensure
efficient communication between devices or
systems, all while optimizing code
performance for the 8051 MCU.
© Dr. Ahmed El-Awamry 30.10.2024 2
AND Instruction

ANL destination,source
;dest = dest AND source
▪ This instruction will perform a logic AND on
the two operands and place the result in the
destination
▪ The destination is normally the accumulator
▪ The source operand can be a register, in memory,
or immediate

© Dr. Ahmed El-Awamry 30.10.2024 3


OR Instruction
ORL destination,source
;dest = dest OR source

▪ The destination and source operands are


ORed and the result is placed in the
destination
▪ The destination is normally the accumulator
▪ The source operand can be a register, in memory,
or immediate

© Dr. Ahmed El-Awamry 30.10.2024 4


XOR Instruction

XRL destination,source
;dest = dest XOR source
▪ This instruction will perform XOR operation
on the two operands and place the result in
the destination
▪ The destination is normally the accumulator
▪ The source operand can be a register, in memory,
or immediate

© Dr. Ahmed El-Awamry 30.10.2024 5


XOR Instruction

© Dr. Ahmed El-Awamry 30.10.2024 6


Complement Accumulator

CPL A ;complements the register A

▪ This is called 1’s complement

▪ To get the 2’s complement, all we have to do


is to to add 1 to the 1’s complement

© Dr. Ahmed El-Awamry 30.10.2024 7


Compare Instruction

CJNE destination,source,rel. addr.


▪ The actions of comparing and jumping are
combined into a single instruction called CJNE
(compare and jump if not equal)
▪ The CJNE instruction compares two operands, and
jumps if they are not equal
▪ The destination operand can be in the accumulator
or in one of the Rn registers
▪ The source operand can be in a register, in
memory, or immediate
▪ The operands themselves remain unchanged
▪ It changes the CY flag to indicate if the destination
operand is larger or smaller
© Dr. Ahmed El-Awamry 30.10.2024 8
Compare Instruction

▪ Notice in the CJNE instruction that any Rn


register can be compared with an immediate
value
▪ There is no need for register A to be involved
© Dr. Ahmed El-Awamry 30.10.2024 9
Compare Instruction

▪ The compare instruction is really a


subtraction, except that the operands remain
unchanged
▪ Flags are changed according to the execution of
the SUBB instruction

© Dr. Ahmed El-Awamry 30.10.2024 10


Rotating Right and Left
RR A ;rotate right A
▪ In rotate right
▪ The 8 bits of the accumulator are rotated right one
bit, and
▪ Bit D0 exits from the LSB and enters into MSB, D7

D7 D0

© Dr. Ahmed El-Awamry 30.10.2024 11


Rotating Right and Left
RL A ;rotate left A
▪ In rotate left
▪ The 8 bits of the accumulator are rotated left one
bit, and
▪ Bit D7 exits from the MSB and enters into LSB, D0

D7 D0

© Dr. Ahmed El-Awamry 30.10.2024 12


Rotating Through Carry
RRC A ;rotate right through carry
▪ In RRC A
▪ Bits are rotated from left to right
▪ They exit the LSB to the carry flag, and the carry
flag enters the MSB

D7 D0

© Dr. Ahmed El-Awamry 30.10.2024 13


Rotating Through Carry
RLC A ;rotate left through carry
▪ In RLC A
▪ Bits are shifted from right to left
▪ They exit the MSB and enter the carry flag, and the
carry flag enters the LSB

D7 D0

© Dr. Ahmed El-Awamry 30.10.2024 14


Serializing Data

▪ Serializing data is a way of sending a byte of


data one bit at a time through a single pin of
microcontroller
▪ Using the serial port
▪ To transfer data one bit at a time and control the
sequence of data and spaces in between them
▪ Transfer a byte of data serially by
▪ Moving CY to any pin of ports P0 – P3
▪ Using rotate instruction

© Dr. Ahmed El-Awamry 30.10.2024 15


Serializing Data

AGAIN

© Dr. Ahmed El-Awamry 30.10.2024 16


Serializing Data

Again

© Dr. Ahmed El-Awamry 30.10.2024 17


Single-bit Operations with CY
▪ There are several instructions by which the
CY flag can be manipulated directly

© Dr. Ahmed El-Awamry 30.10.2024 18


Single-bit Operations with CY

© Dr. Ahmed El-Awamry 30.10.2024 19


SWAP
SWAP A
▪ It swaps the lower nibble and the higher
nibble
▪ In other words, the lower 4 bits are put into the
higher 4 bits and the higher 4 bits are put into the
lower 4 bits
▪ SWAP works only on the accumulator (A)

© Dr. Ahmed El-Awamry 30.10.2024 20


SWAP

© Dr. Ahmed El-Awamry 30.10.2024 21


BCD AND ASCII Application Programs

© Dr. Ahmed El-Awamry 30.10.2024 22


Packed BCD to ACSII Conversion

▪ The DS5000T microcontrollers have a real-


time clock (RTC)
▪ The RTC provides the time of day (hour, minute,
second) and the date (year, month, day)
continuously, regardless of whether the power is
on or off
▪ However this data is provided in packed BCD
▪ To be displayed on an LCD or printed by the
printer, it must be in ACSII format

© Dr. Ahmed El-Awamry 30.10.2024 23


ASCII to Packed BCD Conversion
▪ To convert ASCII to packed BCD
▪ It is first converted to unpacked BCD (to get rid of
the 3)
▪ Combined to make packed BCD

© Dr. Ahmed El-Awamry 30.10.2024 24


ASCII to Packed BCD Conversion

© Dr. Ahmed El-Awamry 30.10.2024 25


ASCII to Packed BCD Conversion, with LUT

© Dr. Ahmed El-Awamry 30.10.2024 26


Checksum Byte in ROM
▪ To ensure the integrity of the ROM contents,
every system must perform the checksum
calculation
▪ The process of checksum will detect any corruption
of the contents of ROM
▪ The checksum process uses what is called a
checksum byte
▪ The checksum byte is an extra byte that is tagged to the
end of series of bytes of data
▪ To calculate the checksum byte of a series of
bytes of data
▪ Add the bytes together and drop the carries
▪ Take the 2’s complement of the total sum, and it
becomes the last byte of the series
© Dr. Ahmed El-Awamry 30.10.2024 27
Checksum Byte in ROM

▪ To perform the checksum operation, add all


the bytes, including the checksum byte
▪ The result must be zero
▪ If it is not zero, one or more bytes of data have
been changed

© Dr. Ahmed El-Awamry 30.10.2024 28


Checksum Byte in ROM

© Dr. Ahmed El-Awamry 30.10.2024 29


Binary (Hex) to ASCII Conversion

▪ Many ADC (analog-to-digital converter) chips


provide output data in binary (hex)
▪ To display the data on an LCD or PC screen, we
need to convert it to ASCII
▪ Convert 8-bit binary (hex) data to decimal digits, 000 –
255
▪ Convert the decimal digits to ASCII digits, 30H – 39H

© Dr. Ahmed El-Awamry 30.10.2024 30


Binary (Hex) to ASCII Conversion
ORG 000H
SJMP START
RESULT EQU 30H
START : MOV A,#_H /*enter the number to convert*/
MOV B,A
CLR C
SUBB A,#0AH
JC SKIP
MOV A,B
ADD A,#37H
SJMP DOWN
SKIP : MOV A,B
ADD A,#30H
Homework
DOWN : MOV RESULT,A
STOP : SJMP STOP
END

OUTPUT :

sl.no HEX no. ASCII


1 01H 31
2 03H 33
3 0AH 41
© Dr. Ahmed El-Awamry 30.10.2024 31
Appendix

You might also like