KEMBAR78
MPMC Notes 1 | PDF | Analog To Digital Converter | Central Processing Unit
0% found this document useful (0 votes)
6 views25 pages

MPMC Notes 1

Uploaded by

dandusrinivas
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)
6 views25 pages

MPMC Notes 1

Uploaded by

dandusrinivas
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/ 25

Microcontrollers GOGA SUBRAMANYAM

UNIT – 5: Intel 8051 MICROCONTROLLER: Architecture, hardware concepts, input/output ports and
circuits, external memory, counters/timers, serial data input/output, interrupts. Assembly language
programming: Instructions, addressing modes, simple programs. Interfacing: keyboard, displays (LED, 7-
segment display unit), A/D and D/A converters.
5.0 MICROPROCESSORS AND MICROCONTROLLERS
Microprocessor Microcontroller

Arithmetic and ALU Timer/ IO Ports


logic unit Counter
Accum
ulator
Accumulator Interrupt
Working Registers
Registe
rs
Program Counter Stack Pointer Internal Circuits
Internal RAM ROM
Clock Circuit Interrupt circuit
Stack Pointer Clock

Program Counter
Block diagram of microprocessor Block diagram of microcontroller

Microprocessor contains ALU, General Microcontroller contains the circuitry of


purpose registers, stack pointer, program microprocessor, and in addition it has built in
counter, clock timing circuit, interrupt circuit ROM, RAM, I/O Devices, Timers/Counters etc.
It has many instructions to move data between It has few instructions to move data between
memory and CPU memory and CPU

Few bit handling instruction It has many bit handling instructions

Less number of pins are multifunctional More number of pins are multifunctional

Single memory map for data and code Separate memory map for data and code
(program) (program)

Access time for memory and IO are more Less access time for built in memory and IO.

Microprocessor based system requires It requires less additional hardwares


additional hardware
More flexible in the design point of view Less flexible since the additional circuits which
is residing inside the microcontroller is fixed
for a particular microcontroller
Large number of instructions with flexible Limited number of instructions with few
addressing modes addressing modes

1|Page
Microcontrollers GOGA SUBRAMANYAM

5.1. RISC AND CISC CPU ARCHITECTURES


Microcontrollers with small instruction set are called reduced instruction set computer
(RISC) machines and those with complex instruction set are called complex
instruction set computer (CISC). Intel 8051 is an example of CISC machine whereas
microchip PIC 18F87X is an example of RISC machine.

RISC CISC

Instruction takes one or two cycles Instruction takes multiple cycles

Only load/store instructions are used to access In additions to load and store instructions,
memory memory access is possible with other
instructions also.
Instructions executed by hardware Instructions executed by the micro program

Fixed format instruction Variable format instructions

Few addressing modes Many addressing modes

Few instructions Complex instruction set

Most of the have multiple register banks Single register bank

Highly pipelined Less pipelined

Complexity is in the compiler Complexity in the microprogram

5.2. HARVARD & VON- NEUMANN CPU ARCHITECTURE


Von-Neumann (Princeton architecture) Harvard architecture

Progra Data Data


Data m Memor
Memor CPU Address Bus y
CPU y
Data
Progra
Address Data Address m
Bus Memor Bus Memor
y y
Von-Neumann (Princeton architecture) Harvard architecture

It uses single memory space for both It has separate program memory and data
instructions and data. memory

It is not possible to fetch instruction code and Instruction code and data can be fetched
data simultaneously

2|Page
Microcontrollers GOGA SUBRAMANYAM

Execution of instruction takes more machine Execution of instruction takes less machine
cycle cycle

Uses CISC architecture Uses RISC architecture

Instruction pre-fetching is a main feature Instruction parallelism is a main feature

Also known as control flow or control driven Also known as data flow or data driven
computers computers

Simplifies the chip design because of single Chip design is complex due to separate memory
memory space space

Eg. 8085, 8086, MC6800 Eg. General purpose microcontrollers, special


DSP chips etc.

5.3. FATURES OF 8051 :


Salient features of 8051 microcontroller are given below.
 Eight bit CPU
 On chip clock oscillator
 4Kbytes of internal program memory (code memory) [ROM]
 128 bytes of internal data memory [RAM]
 64 Kbytes of external program memory address space.
 64 Kbytes of external data memory address space.
 32 bi directional I/O lines (can be used as four 8 bit ports or 32 individually
addressable I/O lines)
 Two 16 Bit Timer/Counter :T0, T1
 Full Duplex serial data receiver/transmitter
 Four Register banks with 8 registers in each bank.
 Sixteen bit Program counter (PC) and a data pointer (DPTR)
 8 Bit Program Status Word (PSW)
 8 Bit Stack Pointer
 Five vector interrupt structure (RESET not considered as an interrupt.)
 8051 CPU consists of 8 bit ALU with associated registers like accumulator ‗A‘
, B register, PSW, SP, 16 bit program counter, stack pointer.
 ALU can perform arithmetic and logic functions on 8 bit variables.
 8051 has 128 bytes of internal RAM which is divided into
o Working registers [00 – 1F]
o Bit addressable memory area [20 – 2F]
o General purpose memory area (Scratch pad memory) [30-7F]
=======================================================================
5.4. ARCHITECTYR OF 8051 :
Let's see the internal architecture of 8051 Microcontroller represented in form of block diagram as shown
below: Basic components present internally inside 8051 Microcontroller architecture are:
CPU (Central Processing Unit): CPU act as a mind of any processing machine. It synchronizes and
manages all processes that are carried out in microcontroller. User has no power to control the functioning
of CPU. It interprets the program stored in ROM and carries out from storage and then performs it
projected duty. CPU manage the different types of registers available in 8051 microcontroller.
3|Page
Microcontrollers GOGA SUBRAMANYAM

Interrupts: Interrupts is a sub-routine call that given by the microcontroller when some other program
with high priority is request for acquiring the system buses the n interrupts occur in current running
program.
Interrupts provide a method to postpone or delay the current process, performs a sub-routine task and then
restart the standard program again.

4|Page
Microcontrollers GOGA SUBRAMANYAM

Types of interrupt in 8051 Microcontroller:


Let's see the five sources of interrupts in 8051 Microcontroller:
o Timer 0 overflow interrupt - TF0
o Timer 1 overflow interrupt - TF1
o External hardware interrupt - INT0
o External hardware interrupt - INT1
o Serial communication interrupt - RI/TI
Memory: For operation Micro-controller required a program. This program guides the microcontroller to
perform the specific tasks. This program installed in microcontroller required some on chip memory for the
storage of the program.
Microcontroller also required memory for storage of data and operands for the short duration. In
microcontroller 8051 there is code or program memory of 4 KB that is it has 4 KB ROM and it also
comprise of data memory (RAM) of 128 bytes.
Bus : Bus is a group of wires which uses as a communication canal or acts as means of data transfer. The
different bus configuration includes 8, 16 or more cables. Therefore, a bus can bear 8 bits, 16 bits all
together.
Types of buses in 8051 Microcontroller:
Let's see the two types of bus used in 8051 microcontroller:
o Address Bus: 8051 microcontrollers is consisting of 16 bit address bus. It is generally be used for
transferring the data from Central Processing Unit to Memory.
o Data bus: 8051 microcontroller is consisting of 8 bits data bus. It is generally be used for
transferring the data from one peripherals position to other peripherals.
Oscillator: As the microcontroller is digital circuit therefore it needs timer for their operation. To perform
timer operation inside microcontroller it required externally connected or on-chip oscillator.
Microcontroller is used inside an embedded system for managing the function of devices. Therefore, 8051
uses the two 16 bit counters and timers. For the operation of this timers and counters the oscillator is used
inside microcontroller.

5|Page
Microcontrollers GOGA SUBRAMANYAM

5.5I/O PINS PORTS AND CIRCUITS OF 8051 MICROCONTROLLER


I/O ports and circuits
PORT-0:
Each port of 8051 has bidirectional capability. Port 0 is called 'true bidirectional port' as it floats (tristated)
when configured as input. Port-1, 2, 3 are called 'quasi bidirectional port'. Port-0 Pin Structure Port -0 has 8
pins (P0.0-P0.7).

Port-0 can be configured as a normal bidirectional I/O port or it can be used for address/data interfacing for
accessing external memory. When control is '1', the port is used for address/data interfacing. When the control
is '0', the port can be used as a normal bidirectional I/O port.
PORT-1
Port-1 Pin Structure Port-1 has 8 pins (P1.1-P1.7) .The structure of a port-1 pin is shown in fig below.

Port-1 does not have any alternate function i.e. it is dedicated solely for I/O interfacing. When used as
output port, the pin is pulled up or down through internal pull-up. To use port-1 as input port, '1' has to be
written to the latch. In this input mode when '1' is written to the pin by the external device then it read fine.
But when '0' is written to the pin by the external device then the external source must sink current due to
internal pull-up. If the external device is not able to sink the current the pin voltage may rise, leading to a
possible wrong reading.

6|Page
Microcontrollers GOGA SUBRAMANYAM

PORT-2
PORT 2 Pin Structure Port-2 has 8-pins (P2.0-P2.7) . The structure of a port-2 pin is shown in figure below:

Port-2 is used for higher external address byte or a normal input/output port. The I/O operation is similar to
Port-1. Port-2 latch remains stable when Port-2 pin are used for external memory access. Here again due to
internal pull-up there is limited current driving capability.
ü PORT 3 Pin Structure
PORT-3
Port-3 has 8 pin (P3.0-P3.7). Port-3 pins have alternate functions. The structure of a port-3 pin is shown in
figure

Each pin of Port-3 can be individually programmed for I/O operation or for alternate function. The alternate
function can be activated only if the corresponding latch has been written to '1'. To use the port as input port, '1'
should be written to the latch. This port also has internal pull-up and limited current driving capability.

7|Page
Microcontrollers GOGA SUBRAMANYAM

5.6PIN DIAGRAM

Pinout Description
Pins 1-8 PORT 1. Each of these pins can be configured as an input or an output.
Pin 9 RESET. A logic one on this pin disables the microcontroller and clears the contents
of most registers. In other words, the positive voltage on this pin resets the
microcontroller. By applying logic zero to this pin, the program starts execution
from the beginning.
Pins10-17 PORT 3. Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions

Pin 10 RXD. Serial asynchronous communication input or Serial synchronous


communication output.
Pin 11 TXD. Serial asynchronous communication output or Serial synchronous
communication clock output.
Pin 12 INT0.External Interrupt 0 input
Pin 13 INT1. External Interrupt 1 input
Pin 14 T0. Counter 0 clock input
Pin 15 T1. Counter 1 clock input
Pin 16 WR. Write to external (additional) RAM
Pin 17 RD. Read from external RAM
Pin 18, 19 XTAL2, XTAL1. Internal oscillator input and output. A quartz crystal which
specifies operating frequency is usually connected to these pins.
Pin 20 GND. Ground.

8|Page
Microcontrollers GOGA SUBRAMANYAM

Pin 21-28 Port 2. If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the higher
address byte, i.e. addresses A8-A15 will appear on this port. Even though memory
with capacity of 64Kb is not used, which means that not all eight port bits are used
for its addressing, the rest of them are not available as inputs/outputs.
Pin 29 PSEN. If external ROM is used for storing program then a logic zero (0) appears on
it every time the microcontroller reads a byte from memory.
Pin 30 ALE. Prior to reading from external memory, the microcontroller puts the lower
address byte (A0-A7) on P0 and activates the ALE output. After receiving signal
from the ALE pin, the external latch latches the state of P0 and uses it as a memory
chip address. Immediately after that, the ALE pin is returned its previous logic state
and P0 is now used as a Data Bus.
Pin 31 EA. By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means
that even there is a program written to the microcontroller, it will not be executed.
Instead, the program written to external ROM will be executed. By applying logic
one to the EA pin, the microcontroller will use both memories, first internal then
external (if exists).
Pin 32-39 PORT 0. Similar to P2, if external memory is not used, these pins can be used as
general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when
the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is
driven low (0).
Pin 40 VCC. +5V power supply.
=========================================================================
5.7MEMORY ORGANIZATION
Internal RAM organization
BANK 3

2
F

2
E

2
D

2
C

9|Page
Microcontrollers GOGA SUBRAMANYAM

Working Registers
Register Banks: 00h to 1Fh. The 8051 uses 8 general-purpose registers R0 through R7
(R0, R1, R2, R3, R4, R5, R6, and R7). There are four such register banks. Selection of
register bank can be done through RS1,RS0 bits of PSW. On reset, the default Register
Bank 0 will be selected.
Bit Addressable RAM: 20h to 2Fh . The 8051 supports a special feature which allows
access to bit variables. This is where individual memory bits in Internal RAM can be set or
cleared. In all there are 128 bits numbered 00h to 7Fh. Being bit variables any one variable
can have a value 0 or 1. A bit variable can be set with a command such as SETB and
cleared with a command such as CLR. Example instructions are:
SETB 25h ; sets the bit
25h (becomes 1) CLR
25h ; clears bit 25h
(becomes 0)
Note, bit 25h is actually bit 5 of Internal RAM location 24h.
The Bit Addressable area of the RAM is just 16 bytes of Internal RAM located between 20h and
2Fh.
General Purpose RAM: 30h to 7Fh. Even if 80 bytes of Internal RAM memory are
available for general-purpose data storage, user should take care while using the memory
location from 00 -2Fh
since these locations are also the default register space, stack space, and bit addressable
space. It is a good practice to use general purpose memory from 30 – 7Fh. The general
purpose RAM can be accessed using direct or indirect addressing modes.
================================================================
5.8Interfacing External Memory
We have seen that a typical 8051 Microcontroller has 4KB of ROM and 128B of RAM (most
modern. The designer of an 8051 Microcontroller based system is not limited to the internal RAM and
ROM present in the 8051 Microcontroller. There is a provision of connecting both external RAM and
ROM i.e. Data Memory and Program. The reason for interfacing external Program Memory or ROM is
that complex programs written in high – level languages often tend to be larger and occupy more
memory.
Another important reason is that chips like 8031 or 8032, which doesn‘t have any internal ROM,
have to be interfaced with external ROM.A maximum of 64B of Program Memory (ROM) and Data
Memory (RAM) each can be interface with the 8051 Microcontroller. The following image shows the
block diagram of interfacing 64KB of External RAM and 64KB of External ROM with the 8051
Microcontroller.

10 | P a g e
Microcontrollers GOGA SUBRAMANYAM

5.9ADDRESSING MODES
Various methods of accessing the data are called
addressing modes. 8051 addressing modes are
classified as follows.
1. Immediate addressing.
2. Register addressing.
3. Direct addressing.
4. Indirect addressing.
5. Index addressing
1. Immediate addressing.
In this addressing mode the data is provided as a part of instruction itself. In
other words data immediately follows the instruction.
Eg. MOV A,#30H
ADD A, #83 # Symbol indicates the data is immediate.
2. Register addressing.
In this addressing mode the register will hold the data. One of the eight
general registers (R0 to R7) can be used and specified as the operand.
Eg. MOV A,R0 ADD A,R6
R0 – R7 will be selected from the current selection of register bank. The default register bank will
be bank 0.
3. Direct addressing
There are two ways to access the internal memory. Using direct address and
indirect address. Using direct addressing mode we can not only address the internal
memory but SFRs also. In direct addressing, an 8 bit internal data memory address is
specified as part of the instruction and hence, it can specify the address only in the
range of 00H to FFH. In this addressing mode, data is obtained directly from the
memory. Eg. MOV A,30H
4. Indirect addressing
The indirect addressing mode uses a register to hold the actual address that
will be used in data movement. Registers R0 and R1 and DPTR are the only
registers that can be used as data pointers. Indirect addressing cannot be used to refer
to SFR registers. Both R0 and R1 can hold 8 bit address and DPTR can hold 16 bit
address.
Eg. MOV A,@R0
MOV A,@R1
MOV A,@DPTR
5. Indexed addressing.
In indexed addressing, either the program counter (PC), or the data pointer
(DTPR)—is used to hold the base address, and the A is used to hold the offset
address. Adding the value of the base address to the value of the offset address forms
the effective address. Indexed addressing is used with JMP or MOVC instructions.
Look up tables are easily implemented with the help of index addressing.
Eg. MOVC A, @A+DPTR // copies the contents of memory location pointed by
the sum of the accumulator A and the DPTR into accumulator A.
MOVC A, @A+PC // copies the contents of memory location
pointed by the sum of the accumulator A and the program counter
into accumulator A.
11 | P a g e
Microcontrollers GOGA SUBRAMANYAM

5.10 8051 INTERRUPT STRUCTURE.


8051 has five interrupts. They are maskable and vectored interrupts. Out of
these five, two are external interrupt and three are internal interrupts.

Interrupt source Type Vector address Priority


External interrupt 0 External 0003 Highest
Timer 0 interrupt Internal 000B
External interrupt 1 External 0013
Timer 1 interrupt Internal 001B
Serial interrupt Internal 0023 Lowest

8051 makes use of two registers to deal with interrupts.

1. IE Register
This is an 8 bit register used for enabling or disabling the interrupts. The
structure of IE register is shown below.

2. IP Register.
This is an 8 bit register used for setting the priority of the interrupts.

12 | P a g e
Microcontrollers GOGA SUBRAMANYAM

5.11TIMERS AND COUNTERS


Timers/Counters are used generally for
 Time reference
 Creating delay
 Wave form properties measurement
 Periodic interrupt generation
 Waveform generation
8051 has two timers, Timer 0 and Timer 1.

Timer in 8051 is used as timer, counter and baud rate generator. Timer always
counts up irrespective of whether it is used as timer, counter, or baud rate generator:
Timer is always incremented by the microcontroller. The time taken to count one
digit up is based on master clock frequency.
If Master CLK=12 MHz,
Timer Clock frequency =
Master CLK/12 = 1 MHz
Timer Clock Period =
1micro second
This indicates that one increment in count will take 1 micro second.
The two timers in 8051 share two SFRs (TMOD and TCON) which control the
timers, and each timer also has two SFRs dedicated solely to itself (TH0/TL0 and
TH1/TL1).

The following are timer related SFRs in 8051.


SFR Name Description SFR
Address
TH0 Timer 0 High Byte 8Ch
TL0 Timer 0 Low Byte 8Ah
TH1 Timer 1 High Byte 8Dh
TL1 Timer 1 Low Byte 8Bh
TCON Timer Control 88h
TMOD Timer Mode 89h

13 | P a g e
Microcontrollers GOGA SUBRAMANYAM

TMOD Register

TCON Register

Timer/ Counter Control Logic.

14 | P a g e
Microcontrollers GOGA SUBRAMANYAM

TIMER MODES

Timers can operate in four different modes. They are as follows


Timer Mode-0: In this mode, the timer is used as a 13-bit UP counter as follows.

Fig. Operation of Timer on Mode-0


The lower 5 bits of TLX and 8 bits of THX are used for the 13 bit count.Upper 3 bits
of TLX are ignored. When the counter rolls over from all 0's to all 1's, TFX flag is
set and an interrupt is generated. The input pulse is obtained from the previous stage.
If TR1/0 bit is 1 and Gate bit is 0, the counter continues counting up. If TR1/0 bit is
1 and Gate bit is 1, then the operation of the counter is controlled by input. This
mode is useful to measure the width of a given pulse fed to input.

Timer Mode-1: This mode is similar to mode-0 except for the fact that the Timer
operates in 16-bit mode.

Fig: Operation of Timer in Mode 1

Timer Mode-2: (Auto-Reload Mode): This is a 8 bit counter/timer operation.


Counting is performed in TLX while THX stores a constant value. In this mode
when the timer overflows i.e. TLX becomes FFH, it is fed with the value stored in
THX. For example if we load THX with 50H then the
timer in mode 2 will count from 50H to FFH. After that 50H is again reloaded. This
mode is useful in applications like fixed time sampling.

Fig: Operation of Timer in Mode 2


Timer Mode-3: Timer 1 in mode-3 simply holds its count. The effect is same as

15 | P a g e
Microcontrollers GOGA SUBRAMANYAM

setting TR1=0. Timer0 in mode-3 establishes TL0 and TH0 as two separate
counters.
Fig: Operation of Timer in Mode 3

Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0) in Mode-3
while TR0 and TF0 are available to Timer-0 lower 8 bits(TL0).
============================================================
=======
5.12PROGRAMMING 8051 TIMERS IN ASSEMBLY
In order to program 8051 timers, it is important to know the calculation of initial
count value to be stored in the timer register. The calculations are as follows.
In any mode, Timer Clock period = 1/Timer Clock Frequency.
= 1/(Master Clock Frequency/12)
a. Mode 1 (16 bit timer/counter)
Value to be loaded in decimal = 65536 – (Delay Required/Timer
clock period) Convert the answer into hexadecimal and load
onto THx and TLx register. (65536D = FFFFH+1)
b. Mode 0 (13 bit timer/counter)
Value to be loaded in decimal = 8192 – (Delay
Required/Timer clock period) Convert the answer into
hexadecimal and load onto THx and TLx register. (8192D =
1FFFH+1)
c. Mode 2 (8 bit auto reload)
Value to be loaded in decimal = 256 – (Delay Required/Timer clock
period) Convert the answer into hexadecimal and load onto THx
register. Upon starting the timer this value from THx will be
reloaded to TLx register.
(256D = FFH+1)

Steps for programming timers in 8051


Mode 1:
 Load the TMOD value register indicating which timer (0 or 1)
is to be used and which timer mode is selected.
 Load registers TL and TH with initial count values.
 Start the timer by the instruction ―SETB TR0‖ for timer 0 and ―SETB TR1‖ for timer
1.
 Keep monitoring the timer flag (TF) with the ―JNB TFx,target‖
instruction to see if it is raised. Get out of the loop when TF becomes
high.
 Stop the timer with the instructions ―CLR TR0‖ or ―CLR TR1‖, for
timer 0 and timer 1, respectively.
 Clear the TF flag for the next round with the instruction ―CLR TF0‖
or ―CLR TF1‖, for timer 0 and timer 1, respectively.
 Go back to step 2 to load TH and TL again.
Mode 0:
The programming techniques mentioned here are also applicable to
counter/timer mode 0. The only difference is in the number of bits
16 | P a g e
Microcontrollers GOGA SUBRAMANYAM

of the initialization value.


Mode 2:
 Load the TMOD value register indicating which timer (0 or 1) is
to be used; select timer mode 2.
 Load TH register with the initial count value. As it is an 8-bit timer,
the valid range is from 00 to FFH.
 Start the timer.
 Keep monitoring the timer flag (TFx) with the ―JNB TFx,target‖
instruction to see if it is raised. Get out of the loop when TFx goes
high.
 Clear the TFx flag.
 Go back to step 4, since mode 2 is auto-reload.
==========================================================================
5.13SERIAL COMMUNICATION.
DATA COMMUNICATION
The 8051 microcontroller is parallel device that transfers eight bits of data
simultaneously over eight data lines to parallel I/O devices. Parallel data transfer
over a long is very expensive. Hence, a serial communication is widely used in long
distance communication. In serial data communication, 8-bit data is converted to
serial bits using a parallel in serial out shift register and then it is transmitted over a
single data line. The data byte is always transmitted with least significant bit first.
BASICS OF SERIAL DATA COMMUNICATION,
Communication Links
1. Simplex communication link: In simplex transmission, the line is dedicated for
transmission. The transmitter sends and the receiver receives the data.

Transmitter Receiver

2. Half duplex communication link: In half duplex, the communication link can be
used for either transmission or
reception. Data is transmitted in only one direction at a time.

Transmitter Receiver

Receiver Transmitter

3. Full duplex communication link: If the data is transmitted in both ways at the
same time, it is a full duplex i.e. transmission and reception can proceed
simultaneously. This communication link requires two wires for data, one for

Transmitter Receiver

Receiver Transmitter
transmission and one for reception.

17 | P a g e
Microcontrollers GOGA SUBRAMANYAM

Types of Serial communication:


Serial data communication uses two types of communication.
1. Synchronous serial data communication: In this transmitter and receiver are synchronized. It
uses a common clock to synchronize the receiver and the transmitter. First the synch character is
sent and then the data is transmitted. This format is generally used for high speed transmission. In
Synchronous serial data communication a block of data is transmitted at a time.
Data
Transmitter Receiver
Sync

Clock
2. Asynchronous Serial data transmission: In this, different clock sources are used for transmitter
and receiver. In this mode, data is transmitted with start and stop bits. A transmission begins with
start bit, followed by data and then stop bit. For error checking purpose parity bit is included just
prior to stop bit. In Asynchronous serial data communication a single byte is transmitted at a time.

Transmitter Start D0 D1 D2 D3 D4 D5 D6 D7 D8 Stop Receiver


Data
Clock 1 Clock2
Baud rate:
The rate at which the data is transmitted is called baud or transfer rate. The baud rate is the
reciprocal of the time to send one bit. In asynchronous transmission, baud rate is not equal to
number of bits per second. This is because; each byte is preceded by a start bit and followed by
parity and stop bit. For example, in synchronous transmission, if data is transmitted with 9600 baud,
it means that 9600 bits are transmitted in one second. For bit transmission time = 1 second/ 9600 =
0.104 ms.
============================================================
=======
5.148051 SERIAL COMMUNICATION

The 8051 supports a full duplex serial port.


Three special function registers support serial communication.
1. SBUF Register: Serial Buffer (SBUF) register is an 8-bit register. It has
separate SBUF registers for data transmission and for data reception. For a
byte of data to be transferred via the TXD line, it must be placed in SBUF
register. Similarly, SBUF holds the 8-bit data received by the RXD pin and
read to accept the received data.
2. SCON register: The contents of the Serial Control (SCON) register are
shown below. This register contains mode selection bits, serial port interrupt
bit (TI and RI) and also the ninth data bit for transmission and reception
(TB8 and RB8).

18 | P a g e
Microcontrollers GOGA SUBRAMANYAM

3. PCON register: The SMOD bit (bit 7) of PCON register controls the baud
rate in asynchronous mode transmission.

SERIAL COMMUNICATION MODES


1. Mode 0
In this mode serial port runs in synchronous mode. The data is transmitted
and received through RXD pin and TXD is used for clock output. In this
mode the baud rate is 1/12 of clock frequency.
2. Mode 1
In this mode SBUF becomes a 10 bit full duplex transceiver. The ten bits are
1 start bit, 8 data bit and 1 stop bit. The interrupt flag TI/RI will be set once
transmission or reception is over. In this mode the baud rate is variable and is
determined by the timer 1 overflow rate. Baud rate = [2smod/32] x
Timer 1 overflow Rate
= [2smod/32] x [Oscillator Clock Frequency] / [12 x [256 – [TH1]]]
3. Mode 2
This is similar to mode 1 except 11 bits are transmitted or received. The 11
bits are, 1 start bit, 8 data bit, a programmable 9th data bit, 1 stop bit.
Baud rate = [2smod/64] x Oscillator Clock Frequency

4. Mode 3
This is similar to mode 2 except baud rate is calculated as in mode 1
--
==========================================================================
19 | P a g e
Microcontrollers GOGA SUBRAMANYAM

5.15ASSEMBLY LANGUAGE PROGRAMMING INSTRUCTION FORMATE:


LABEL: OPCODE OPERAND ;COMMENT
LABEL : (THIS IS NOT NECESSARY UNLESS THAT SPECIFIC LINE HAS TO
BE ADDRESSED). The label is a symbolic
address for the instruction. When the program is assembled, the label will be given
specific address in which that instruction is stored. Unless that specific line of
instruction is needed by a branching instruction in the program, it is not necessary to
label that line.
OPCODE: Opcode is the symbolic representation of the operation. The assembler
converts the opcode to a unique binary code (machine language).
OPERAND: While opcode specifies what operation to perform, operand specifies
where to perform that action. The operand field generally contains the source and
destination of the data. In some cases only source or destination will be available
instead of both. The operand will be either address of the data, or data itself.
COMMENT: Always comment will begin with ; or
// symbol. To improve the program quality, programmer may always use comments in the program
The instructions of 8051 Microcontroller can be classified into five different groups. These groups are
like below
 Data Transfer Group
 Arithmetic Group
 Logical Group
 Program Branch Group
 Bit Processing Group
Data Transfer Instructions
The Data Transfer Instructions are associated with transfer with data between registers or external
program memory or external data memory. The Mnemonics associated with Data Transfer are given
below.
 MOV
 MOVC
 MOVX
 PUSH
 POP
 XCH
 XCHD

Arithmetic Instructions
Using Arithmetic Instructions, you can perform addition, subtraction, multiplication and division. The
arithmetic instructions also include increment by one, decrement by one and a special instruction called
Decimal Adjust Accumulator.
The Mnemonics associated with the Arithmetic Instructions of the 8051 Microcontroller Instruction Set
are:
 ADD
 ADDC
 SUBB
 INC
 DEC
20 | P a g e
Microcontrollers GOGA SUBRAMANYAM

 MUL
 DIV
 DA A
Logical Instructions
The next group of instructions are the Logical Instructions, which perform logical operations like AND,
OR, XOR, NOT, Rotate, Clear and Swap. Logical Instruction are performed on Bytes of data on a bit-by-
bit basis.
Mnemonics associated with Logical Instructions are as follows:
 ANL
 ORL
 XRL
 CLR
 CPL
 RL
 RLC
 RR
 RRC
 SWAP
Boolean or Bit Manipulation Instructions
As the name suggests, Boolean or Bit Manipulation Instructions will deal with bit variables. We know
that there is a special bit-addressable area in the RAM and some of the Special Function Registers (SFRs)
are also bit addressable.
The Mnemonics corresponding to the Boolean or Bit Manipulation instructions are:
 CLR
 SETB
 MOV
 JC
 JNC
 JB
 JNB
 JBC
 ANL
 ORL
 CPL

Program Branching Instructions


The last group of instructions in the 8051 Microcontroller Instruction Set are the Program Branching
Instructions. These instructions control the flow of program logic. The mnemonics of the Program
Branching Instructions are as follows.
 LJMP
 AJMP
 SJMP
 JZ
 JNZ
 CJNE
 DJNZ
21 | P a g e
Microcontrollers GOGA SUBRAMANYAM

 NOP
 LCALL
 ACALL
 RET
 RETI
 JMP
======================================================================
5.16MATRIX KEYPAD
Matrix Keypads are commonly used in calculators, telephones etc where a number of input switches are
required. We know that matrix keypad is made by arranging push button switches in row and columns. In
the straight forward way to connect a 4×4 keypad (16 switches) to a microcontroller we need 16 inputs
pins. But by connecting switches in the following way we can read the status of each switch using 8 pins
of the microcontroller.

4×4-Matrix-Keypad
The status of each keys can be determined by a process called Scanning. For the sake of explanation lets
assume that all the column pins (Col1 – Col4) are connected to the inputs pins and all the row pins are
connected to the output pins of the microcontroller. In the normal case all the column pins are pulled up
(HIGH state) by internal or external pull up resistors. Now we can read the status of each switch through
scanning.
1. A logic LOW is given to Row1 and others (Row2 – Row-4) HIGH
2. Now each Column is scanned. If any switch belongs to 1st row is pressed corresponding column
will pulled down (logic LOW) and we can detect the pressed key.
3. This process is repeated for all rows.
If you need to save more pins of your microcontroller then you can interface keypad using the ADC
module of your microcontroller.
Interfacing with 8051 Microcontroller
Circuit diagram
Interfacing Keypad with 8051 Microcontroller using Keil C
10KΩ resistor and 10μF will provide the required Power On Reset (POR) signal to the 8051
microcontroller. 12MHz crystal is used to provide required clock for the microcontroller and 22pF
capacitors will stabilize the oscillations of the crystal. AT89C51 can works upto 24MHz. We can choose
the required frequency by changing the crystal and clock frequency in the project settings of Keil C.
Keypad is connected to the Port P1 and column inputs pins are pulled up internally. 16×2 LCD is

22 | P a g e
Microcontrollers GOGA SUBRAMANYAM

connected to Port P2 and P0. P0.0 and P0.1 pins are pulled up externally using 10KΩ resistors since Port
P0 has no internal pull up.

=========================================================================
5.17ADC (ANALOG TO DIGITAL CONVERTER INTERFACING TO 8051 )
ADC is the Analog to Digital converter, which converts analog data into digital format; usually it is
used to convert analog voltage into digital format. Analog signal has infinite no of values like a sine
wave or our speech, ADC converts them into particular levels or states, which can be measured in
numbers as a physical quantity. Instead of continuous conversion, ADC converts data periodically, which
is usually known as sampling rate. Telephone modem is one of the examples of ADC, which is used for
internet, it converts analog data into digital data, so that computer can understand, because computer can
only understand Digital data. The major advantage, of using ADC is that, we noise can be efficiently
eliminated from the original signal and digital signal can travel more efficiently than analog one. That‘s
the reason that digital audio is very clear, while listening.
ADC 0808/0809 pins
 IN0-IN7: Analog Input channels
 D0-D7: Data Lines
 A, B, C: Analog Channel select lines; A is LSB and C is MSB
 OE: Output enable signal
 ALE: Address Latch Enable
 EOC: End of Conversion signal
 Vref+/Vref-: Differential Reference voltage input
 Clock: External ADC clock input

23 | P a g e
Microcontrollers GOGA SUBRAMANYAM

ALGORITHM
1. Start.
2. Select the channel.
3. A Low – High transition on ALE to latch in the address.
4. A Low – High transition on Start to reset the ADC‘s SAR.
5. A High – Low transition on ALE.
6. A High – Low transition on start to start the conversion.
7. Wait for End of cycle (EOC) pin to become high.
8. Make Output Enable pin High.
9. Take Data from the ADC‘s output
10. Make Output Enable pin Low.
11. Stop
The total numbers of lines required are:

========================================================================
5.18DAC INTERFACING TO 8051

quantity like temperature, pressure, speed, distance, etc.

requires analog signal as they don't accept digital data thus making it necessary to use DAC which
converts digital data into equivalent analog voltage.
-bit DAC 0808. This IC converts digital data into equivalent analog
Current. Hence we require an I to V converter to convert this current into equivalent voltage.

24 | P a g e
Microcontrollers GOGA SUBRAMANYAM

Ex:
1. IF data =00H [00000000], Vref=

10V Therefore, V0= 0 Volts.

2. If data is 80H [10000000], Vref=

10V Therefore, V0= 5 Volts.

Different Analog output voltages for different Digital signal is given as:

Interfacing Diagram

25 | P a g e

You might also like