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

MicroprocessorBasedSystems Term-II Lec7 LogicOperations and ExternalPeripheralInterface 8255

Uploaded by

Abubakr Sherif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

MicroprocessorBasedSystems Term-II Lec7 LogicOperations and ExternalPeripheralInterface 8255

Uploaded by

Abubakr Sherif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

E1322

Microprocessor based Systems II

‘Logic Operations and External


Peripheral Interface (8255)’

Dr. Ahmed El-Awamry

Date: 25.03.2023, Time: 10:45


Objective

▪ Be able to perform Logic operations, compare


instructions and data serialization in
assembly language for 8051 MCU.

© Dr. Ahmed El-Awamry 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 5


XOR Instruction

© Dr. Ahmed El-Awamry 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 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 24.03.2023 15


Serializing Data

AGAIN

© Dr. Ahmed El-Awamry 24.03.2023 16


Serializing Data

© Dr. Ahmed El-Awamry 24.03.2023 17


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

© Dr. Ahmed El-Awamry 24.03.2023 18


Single-bit Operations with CY

© Dr. Ahmed El-Awamry 24.03.2023 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 24.03.2023 20


SWAP

© Dr. Ahmed El-Awamry 24.03.2023 21


BCD AND ASCII Application Programs

© Dr. Ahmed El-Awamry 24.03.2023 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 24.03.2023 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 24.03.2023 24


ASCII to Packed BCD Conversion

© Dr. Ahmed El-Awamry 24.03.2023 25


ASCII to Packed BCD Conversion, with LUT

© Dr. Ahmed El-Awamry 24.03.2023 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 24.03.2023 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 24.03.2023 28


Checksum Byte in ROM

© Dr. Ahmed El-Awamry 24.03.2023 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 24.03.2023 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
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 24.03.2023 31
8255 Interfacing

© Dr. Ahmed El-Awamry 24.03.2023 32


8255 Interfacing

© Dr. Ahmed El-Awamry 24.03.2023 33


8255 Interfacing
▪ PA0 - PA7 (8-bit port A)
▪ Can be programmed as all input or output, or all
bits as bidirectional input/output
▪ PB0 - PB7 (8-bit port B)
▪ Can be programmed as all input or output, but
cannot be used as a bidirectional port
▪ PC0 – PC7 (8-bit port C)
▪ Can be all input or output
▪ Can also be split into two parts:
▪ CU (upper bits PC4 - PC7)
▪ CL (lower bits PC0 – PC3)
each can be used for input or output
▪ Any of bits PC0 to PC7 can be programmed
individually
© Dr. Ahmed El-Awamry 24.03.2023 34
8255 Interfacing
▪ D0 – D7
▪ are connected to the data pins of the
microcontroller
▪ allowing it to send data back and forth between the
controller and the 8255 chip
▪ RESET
▪ An active-high signal input
▪ Used to clear the control register
▪ When RESET is activated, all ports are initialized as input
ports

© Dr. Ahmed El-Awamry 24.03.2023 35


8255 Interfacing

© Dr. Ahmed El-Awamry 24.03.2023 36


8255 Interfacing

© Dr. Ahmed El-Awamry 24.03.2023 37


Appendix

You might also like