Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Millman Halkias - Integrated Electronics

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

8051 Microcontroller

Overview

The Intel 8051 is a very popular general purpose


microcontroller widely used for small scale embedded
systems.
Many vendors such as Atmel, Philips, and Texas Instruments
produce MCS-51 family microcontroller chips.
The 8051 is an 8-bit microcontroller with 8 bit data bus and
16-bit address bus.
The 16 bit address bus can address a 64K( 2 16) byte code
memory space and a separate 64K byte of data memory
space.
The 8051 has 4K on-chip read only code memory(ROM) and
128 bytes of internal Random Access Memory (RAM)
Besides internal RAM, the 8051 has various Special
Function Registers (SFR) such as the Accumulator, the
B register, and many other control registers.
8-bit Program Status Word
16 bit program counter(PC) and data pointer(DPTR)
16 bit timers
3 internal interrupts (one serial), 2 external
interrupts.
4 8-bit I/O ports (3 of them are dual purposed). One
of them used for serial port,
Some 8051 chips come with UART for serial
communication and ADC for analog to digital
conversion
40 pins on the 8051 chip.
Most of these pins are used to connect to I/O
devices or external data and code memory.
4 I/O port take 32 pins(4 x 8 bits) plus a pair
of XTALS pins for crystal clock
A pair of Vcc and GND pins for power supply
(the 8051 chip needs +5V 500mA to function
properly)
A pair of timer pins for timing controls, a group
of pins (EA, ALE, PSEN, WR, RD) for internal and
external data and code memory access controls
One Reset pin for reboot purpose
Pin-40 : Named as Vcc is the main power source. Usually its +5V DC.
Pins 32-39: Known as Port 0 (P0.0 to P0.7) In addition to serving as I/O port,
lower order address and data bus signals are multiplexed with this port (to serve
the purpose of external memory interfacing). This is a bi directional I/O port (the
only one in 8051) and external pull up resistors are required to function this port as
I/O.
Pin-31:- ALE aka Address Latch Enable is used to demultiplex the address-data
signal of port 0 (for external memory interfacing.) 2 ALE pulses are available for
each machine cycle.
Pin-30:- EA/ External Access input is used to enable or disallow external memory
interfacing. If there is no external memory requirement, this pin is pulled high by
connecting it to Vcc.
Pin- 29:- PSEN or Program Store Enable is used to read signal from external
program memory.
Pins- 21-28:- Known as Port 2 (P 2.0 to P 2.7) in addition to serving as I/O port,
higher order address bus signals are multiplexed with this quasi bi directional port.
Pin 20:- Named as Vss it represents ground (0 V) connection.
Pins 18 and 19:- Used for interfacing an external crystal to provide system clock.
Pins 10 17:- Known as Port 3. This port also serves
some other functions like interrupts, timer input,
control signals for external memory interfacing RD and
WR , serial communication signals RxD and TxD etc. This
is a quasi bi directional port with internal pull up.
Pin 9:- RESET pin is used to set the 8051
microcontroller to its initial values, while the
microcontroller is working or at the initial start of
application. The RESET pin must be set high for 2
machine cycles.
Pins 1 8:- Known as Port 1. Unlike other ports, this
port does not serve any other functions. Port 1 is an
internally pulled up, quasi bi directional I/O port.
Pin Connection for External Code and Data Memory
The EA' (External Access) pin is used to control
the internal or external memory access.
The signal 0 is for external memory access and
signal 1 for internal memory access.
The PSEN' (Program Store Enable) is for
reading external code memory when it is low
(0) and EA is also 0.
The ALE (Address Latch Enable) activates the
port 0 joined with port 2 to provide 16 bit
external address bus to access the external
memory. The ALE multiplexes the P0:
1 for latching address on P0 as A0-A7 in the
16 bit address buss, 0 for latching P0 as data
I/O.
P0.x is named ADx because P0 is multiplexed for
Address bus and Data bus at different clock time.
WR' only provides the signal to write external
data memory
RD' provides the signal to read external data and
code memory
The 8051 requires an external oscillator circuit.
The oscillator circuit usually runs around 12MHz.
the crystal generates 12M pulses in one second.
The pulse is used to synchronize the system
operation in a controlled pace..
Architecture of 8051
. Oscillator and clock generator: All operations in a
microcontroller are synchronized by the help of an
oscillator clock. The oscillator clock generates the clock
pulses by which all internal operations are synchronized.
A resonant network connected through pins XTAL1 and
XTAL2 forms up an oscillator. For this purpose a quartz
crystal and capacitors are employed. The crystal run at
specified maximum and minimum frequencies typically at 1
MHz to 16 MHz.
ALU: It is 8 bit unit. It performs arithmetic operation as
addition, subtraction, multiplication, division, increment and
decrement. It performs logical operations like AND, OR and
EX-OR.
It performs compare, rotate and compliment operations. It
consists of Boolean processor which performs bit, set, test,
clear and compliment. 8051 micro controller contains 34
general purpose registers or working registers.2 of them are
called math registers A & B and 32 are bank of registers.
Accumulator(A-reg): It is 8 bit register. Its address is E0H
and it is bit and byte accessible. Result of arithmetic &
logic operations performed by ALU is accumulated by
this register. Therefore it is called accumulator register. It
is used to store 8 bit data and to hold one of operand of
ALU units during arithmetical and logical operations.
Most of the instructions are carried out on accumulator
data. It is most versatile of 2 CPU registers.
B-register: It is special 8 bit math register. It is bit and
byte accessible. It is used in conjunction with A register
as I/P operand for ALU. It is used as general purpose
register to store 8 bit data.
PSW: It is 8 bit register. Its address is D0H and It is bit and byte accessible. It has
4 conditional flags or math flags which sets or resets according to condition of
result. It has 3 control flags, by setting or resetting bit required operation or
function can be achieved. The format of flag register is as shown below:
I) MATH FLAG: 1. Carry Flag(CY): During addition and subtraction any carry or
borrow is generated then carry flag is set otherwise carry flag resets. It is used in
arithmetic, logical, jump, rotate and Boolean operations.
2. Auxiliary carry flag(AC): If during addition and subtraction any carry or
borrow is generated from lower 4 bit to higher 4 bit then AC sets else it resets. It
is used in BCD arithmetic operations.
3. Overflow flag(OV): If in signed arithmetic operations result exceeds more than
7 bit than OV flag sets else resets.It is used in signed arithmetic operations only.
4. Parity flag(P): If in result, even no. Of ones "1" are present than it is called
even parity and parity flag sets. In result odd no. Of ones "1"are present than it
is called odd parity and parity flag resets.
ii)CONTROL FLAGS: 1. FO: It is user defined flag. The user defines the function of this
flag. The user can set ,test n clear this flag through software.
2. RS1 and RS0: These flags are used to select bank of register by resetting those
flags
3.Program counter(PC): The Program Counter (PC) is a 2-byte address which tells
the 8051 where the next instruction to execute is found in memory. It is used to
hold 16 bit address of internal RAM, external RAM or external ROM locations.
When the 8051 is initialized PC always starts at 0000h and is incremented each
time an instruction is executed. It is important to note that PC isnt always
incremented by one and never decremented.
4. Data pointer register(DTPR): It is a 16 bit register used to hold address of
external or internal RAM where data is stored or result is to be stored. It is used to
store 16 bit data. It is divided into2- 8bit registers, DPH-data pointer higher order
(83H) and DPL-data pointer lower order (82H). Each register can be used as general
purpose register to store 8 bit data and can also be used as memory location. DPTR
does not have single internal address.
5. Stack pointer(SP): It is 8-bit register. It is byte addressable. Its address is 81H. It is
used to hold the internal RAM memory location addresses which are used as stack
memory. When the data is to be placed on stack by push instruction, the content of
stack pointer is incremented by 1, and when data is retrieved from stack, content of
stack of stack pointer is decremented by 1
iii. Special function Registers(SFR): The 8051 microcontroller has SFR divided in 4
groups:
A. Timer/Counter register: 8051 microcontroller has 2-16 bit Timer/counter registers
called Timer-reg-T0 And Timer/counter Reg-T1.Each register is 16 bit register divide into
lower and higher byte register as shown below: These register are used to hold initial
no. of count. All of the 4 register are byte addressable.
1. Timer control register: 8051 microcontroller has two 8-bit timer control register i.e.
TMOD and TCON register. TMOD Register: it is 8-bit register. Its address is 89H. It is byte
addressable. It used to select mode and control operation of time by writing control
word.
2. TCON register: It is 8-bit register. Its address is 88H. It is byte addressable. Its MSB 4-
bit are used to control operation of timer/ counter and LSB 4-bit are used for external
interrupt control.
B. Serial data register: 8051 micro controller has 2 serial data register viz. SBUF and
SCON.
1. Serial buffer register (SBUF): it is 8-bit register. It is byte addressable .Its address is
99H. It is used to hold data which is to be transferred serially.
2. Serial control register (SCON): it is 8-bit register. It is bit/byte addressable. Its
address is 98H. The 8-bit loaded into this register controls the operation of serial
communication.
C. Interrupt register: 8051 C has 2 8-bit interrupt register. 1.
Interrupt enable register (IE): it is 8-bit register. It is bit/byte
addressable. Its address is A8H.it is used to enable and disable
function of interrupt.
2. Interrupt priority register (IP): It is 8-bit register. It is bit/byte
addressable. Its address is B8H. it is used to select low or high level
priority of each individual interrupts.
D. Power control register (PCON): it is 8-bit register. It is byte
addressable .Its address is 87H. its bits are used to control mode of
power saving circuit, either idle or power down mode and also one
bit is used to modify baud rate of serial communication.
Internal ROM Data memory and program
code memory both are in different physical
memory but both have the same addresses.
An internal ROM occupied addresses from
0000h to 0FFFh. PC addresses program codes
from 0000h to 0FFFh. Program addresses
higher than 0FFFh that exceed the internal
ROM capacity will cause 8051 architecture to
fetch codes bytes from external program
memory.
The 8051 has 256 bytes of internal addressable
RAM, although only first 128 bytes are available
for general use by the programmer.
The first 128 bytes of RAM (from 0x00 to 0x7F)
are called the direct memory, and can be used to
store data.
The lowest 32 bytes of RAM are reserved for 4
general register banks. The 8051 has 4 selectable
banks of 8 addressable 8-bit registers, R0 to R7.
This means that there are essentially 32 available
general purpose registers, although only 8 (one
bank) can be directly accessed at a time.
The default bank is bank 0.
The second 128 bytes are used to store
Special Function Registers (SFR) that C51
program can configure and control the ports,
timer, interrupts, serial communication, and
other tasks.
I/O Ports
4 I/O ports each comprising of 8 bits which is
configured as inputs or outputs
In total of 32 input /output pins enabling the
microcontroller to be connected to peripheral
devices are available for use.
Working of 8051
The speed of operation of 8051 is decided by
the frequency of clock generated by the
oscillator.
The frequency of the oscillator is dependant on
the crystal frequency connected externally to
the oscillator
CPU fetches the program from the program
memory (ROM) and excecutes the next
instruction
Data required for ALU is obtained from RAM.
For some applications the data can be present
in external devices ,in that case the data is
accessed through IO ports present on the chip
Since the program memory and data memory
are present within the microcontroller the
accessing time required is less and hence the
speed of operation increases.
The timers can be programmed for creating
the delay
Serial port present in the microcontroller can be
used for serial to parallel conversion or parallel to
serial conversion of the data.
Parallel to serial conversion the microcontroller
transfers all bits of data to the serial port and then
the serial port will transfer all bits of data to an
external data bit by bit.
For serial to parallel conversion the serial port
recieves the data bit by bit from an external device
and after receiving the required number of bits all
the bits at a time is transferd to CPUof the
microcontroller.
A signal from an interrupting source can be
connected to an interrupt controller unit of
the microcontroller
It will transfer the signal to the CPU under the
program control
When the interrupt signal is received by the
CPU, the present program which is under the
excecution will temporarily stopped and
microcontroller will start excecuting another
program called ISR (interrupt service routine)
After the completion of excecution of ISR, the
microcontroller will return to the program
which was temporarily stopped.
The execution of ISR will result in certain
action required by the interuppting source.

You might also like