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

Module 4

Uploaded by

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

Module 4

Uploaded by

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

MODULE 4

Introduction to 8051
CONTENTS
Introduction to microcontroller
Difference between microcontroller and microprocessor
8051 :
• architecture
• pin diagram of 8051
• memory organization
• special function registers
• I/O pins ,timers, interrupts, serial interface
• power consumption, external interface of the standard 8051
What is a Microcontroller?
• A microcontroller (MCU) is a
small, self-contained
microcomputer that is usually
designed to run a single basic
program repeatedly.
• It's a compact integrated circuit
(IC) device that's used to control
other parts of an electronic
system.
Difference between Microprocessor and
Microcontroller
• The 8051 microcontroller architecture is an 8-bit architecture designed by Intel
in 1981.
• It has a Harvard architecture design, with separate memory buses for
instruction and data.
• The 8051's central processing unit (CPU) is the brain of the microcontroller,
responsible for executing instructions and performing arithmetic and logical
operations. The CPU consists of an ALU, accumulator, registers, and a
program counter.
• The 8051 is called an 8-bit microcontroller because it processes 8 bits of data
every machine cycle. All assembly instructions happen 8-bits at a time, and all
internal registers are 8-bit in size.
• The 8051 is widely used in embedded systems due to its simplicity and
versatility.
• The 8051 microcontroller has a Complex Instruction Set Computer (CISC)
architecture.
• The 8051 microcontroller has the following features:
• 4 KB on-chip ROM (Program memory)

• 128 bytes on-chip RAM (Data memory)

• 8-bit data bus (bidirectional)

• 16-bit address bus (unidirectional)

• Two 16-bit timers

• Instruction cycle of 1 microsecond with 12 MHz crystal

• Four 8-bit input/output ports

• 128 user-defined flags


CENTRAL PROCESSING UNIT (CPU)

 Central Processor Unit (CPU) is the brain of any processing device of the
microcontroller.

 It monitors and controls all operations that are performed on the Microcontroller
units.

 The User has no control over the work of the CPU directly.

 It reads program written in ROM memory and executes them and do the
expected task of that application.
INTERRUPT CONTROL
 There are five interrupt sources in 8051 Microcontroller and interrupt
control section control all these interrupts.

 Two external interrupts (INT0 & INT1), two timer (TF0 & TF1) interrupts
and one serial port (RI / TI) interrupt.

 The Microcontroller 8051 can be configured in such a way that it


temporarily terminates or pause the main program at the occurrence of
interrupt. When subroutine is completed then the execution of main
program starts as usual.
RAM & ROM

 Microcontroller 8051 has 4K of Code Memory or Program memory that is it


has 4KB ROM and RAM of 128 bytes.

 The memory which is used to store the program of Microcontroller, is known


as code memory or Program memory . It is known as 'ROM'(Read Only
Memory).

 Microcontroller also requires a memory to store data or operands temporarily.


This memory is known as Data Memory and we use 'RAM'(Random Access
Memory) for this purpose.
BUS CONTROL
 Bus control section of 8051 is responsible for controlling the operation of
address and data bus.
 Bus: Basically Bus is a collection of wires which work as a communication
channel or medium for transfer of Data.
 Buses are of two types:
 Address Bus: Microcontroller 8051 has a 16 bit address bus. It used
to address memory locations.
 Data Bus: Microcontroller 8051 has 8 bits data bus. It is used to carry
data.
CRYSTAL OSCILLATOR
 Crystal Oscillator: Since Microcontroller is a digital circuit device,
therefore it requires clock for its operation.

 For this purpose, Microcontroller 8051 has oscillator circuitry section


which works as a clock source for Central Processing Unit.

 As the output pulses of oscillator are stable therefore it enables


synchronized work of all parts of 8051 Microcontroller.
I/O PORTS
 I/O Ports: To connect any external devices or peripherals we require
I/O interfacing ports in the microcontroller.

 All 8051 microcontrollers have 4 I/O ports each comprising 8 bits


which can be configured as input (1) or an output (0), depends on its
logic state.

 Accordingly, in total of 32 input/output pins enabling the


microcontroller to be connected to peripheral devices are available for
use.
TIMERS/COUNTERS
 Timers/Counters: 8051 Microcontroller 8051 two 16-bit timers and
counters: Timer 0 and Timer 1.

 They can be used either as timers to generate a time delay or as counters to


count events happening outside the microcontroller.

 Since the 8051 has an 8-bit architecture, each 16-bit is accessed as two
separate registers of low byte and high byte.
SERIAL PORT

 Serial port: The 8051 contains one


Serial port or UART (Universal
Asynchronous Receiver Transmitter)

 The serial port is full-duplex so, it can


transmit and receive simultaneously

 Two port pins are used to provide the


serial interface P3.0 is the receive pin
(RXD) P3.1 is the transmit pin (TXD)

 This serial port that can be


programmed to operate in one of four
different modes and at a range of
frequencies.
1. A total of 32 pins are reserved in a 40-pin
package for the four ports (PO, P1, P2, and
P3), each of which requires eight pins.
2. The remaining pins are identified as RST,
EA, PSEN, ALE, XTAL1, XTAL2, GND,
and Vcc.
3. Six of these pins—Vcc, GND, XTAL1,
XTAL2, RST, and EA—are shared by all
8051 and 8031 family members.
4. The majority of 8031-based systems
employ the other two pins, PSEN and ALE.
 Pin-40 : Vcc is the main power source. Usually its +5V DC.

 Pins 32-39: 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 - Address Latch Enable. It is especially used for 8031 IC to connect it to the external memory.
It can be used while deciding whether P0 pins will be used as Address bus or Data bus. When ALE = 1, then
the P0 pins work as Data bus and when ALE = 0, then the P0 pins act as Address bus.

 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. This is an active low pin, i.e., it gets activated after applying a low
pulse. It is an output pin and used along with the EA pin in 8031 based (i.e. ROMLESS) Systems to allow
storage of program code in external ROM.

 Pins- 21-28: 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:- Vss – it represents ground (0 V) connection.

 Pins 18 and 19:- XTAL1 & XTAL2 Used for interfacing an external crystal to provide system clock.

 Pins 10 – 17:- Port 3 (P 3.0 to P 3.7) It is also of 8 bits and can be used as Input/Output. This port provides some
extremely important signals.

 P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter) respectively and are collectively used for Serial
Communication.

 P3.2 and P3.3 pins are used for external interrupts. P3.4 and P3.5 are used for timers T0 and T1 respectively.

 P3.6 and P3.7 are Write (WR) and Read (RD) pins.
 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:- Port 1 (P 1.0 to P 1.7). It is an 8-bit port (pin 1 through 8) and can be used either as input or
output. Unlike other ports, this port does not serve any other functions. Port 1 is an internally pulled up,
quasi bi directional I/O port.
The 8051 microcontroller's memory is divided into four types:

•Program memory
Also known as ROM, this memory is used to permanently save the program that is being
executed.

•Data memory
Also known as RAM, this memory is used to temporarily store intermediate results and
variables.

•Special function registers (SFRs)


These are bit, byte, or word-sized registers that are used to control timers, counters, serial I/O,
port I/O, and peripherals. The 8051 provides 128 bytes of memory for SFRs.

•External data memory


This memory can be addressed by the 8051, and up to 64 k-bytes of additional data memory
can be addressed. The external data memory is accessed using the “MOVX” instruction.
DATA MEMORY (RAM)

REGISTER BANKS

 Registers are used to store data or operands during


executions. Register banks form the lowest 32 bytes on
internal RAM memory.

 There are 4 register banks designated bank #0,#1, #2 and #3.


Each bank has 8 registers which are designated as R0,R1…
R7.

 At a time only one register bank is selected (using RS1 & RS0
bits in PSW register) for operations and the registers inside
the selected bank are accessed using mnemonics R0..R1.. etc.

 By default register bank #0 is selected (after a system reset).


DATA MEMORY – BIT ADDRESSABLE AREA
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.

The Bit Addressable area of the RAM is 16 bytes (128 bits) next to register
banks of Internal RAM located between 20h and 2Fh. 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)

Bit addressable area is mainly used to store bit variables from application
program, like status of an output device like LED or Motor (ON/OFF) etc.

We need only a bit to store this status and using a complete byte addressable
area for storing this is really bad programming practice, since it results in
wastage of memory.
DATA MEMORY – SFRs (Special Function Registers)

 SFRs are accessed just like normal Internal RAM locations.

 The SFR registers are located within the Internal Memory in the address range 80h to FFh.

 Each SFR has a very specific function. Note some of the SFR registers are bit addressable.

 Although 128 byes of the SFR address space is defined only 21 SFR registers are defined in the
standard 8051.

 Rest of locations are intentionally left unoccupied in order to enable the manufacturers to
further develop microcontrollers keeping them compatible with the previous versions.

 Main function of SFR is to control timers, counters, serial I/O, port I/O, and peripherals that
are present in 8051 microcontroller.

The 21 Special Function Registers of 8051 Microcontroller are
categorized in to seven groups.

• Math or CPU Registers: A and B


• Status Register: PSW (Program Status Word)
• I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3)
• Pointer Registers: DPTR (Data Pointer – DPL,DPH), SP (Stack
Pointer)
• Peripheral Control Registers: PCON, SCON, TCON, TMOD, IE and
IP
• Peripheral Data Registers: TL0, TH0, TL1, TH1 and SBUF
8051 Microcontroller Power Consumption Control
• Generally speaking, the microcontroller is inactive for the most part and just waits for
some external signal in order to takes its role in a show.
• This can cause some problems in case batteries are used for power supply.
• In extreme cases, the only solution is to set the whole electronics in sleep mode in order to
minimize consumption.
• A typical example is a TV remote controller: it can be out of use for months but when used
again it takes less than a second to send a command to TV receiver.
• The AT89S53 uses approximately 25mA for regular operation, which doesn't make it a
power-saving microcontroller.
• Anyway, it doesn’t have to be always like that, it can easily switch the operating mode in
order to reduce its total consumption to approximately 40uA.
• Actually, there are two power-saving modes of operation:
• Idle and Power Down.
PCON (Power Control Register)

SMOD – – – GF1 GF0 PD IDL

• PD: Power Down bit.


• Setting this bit activates the power-down operation in the 8051.
• IDL: Idle Mode bit.
• Setting this bit activates the Idle Mode operation in the 8051.
IDLE mode
• Upon the IDL bit of the PCON register is set,
• the microcontroller turns off the greatest power consumer- CPU unit
• peripheral units such as serial port, timers and interrupt system continue operating
normally consuming 6.5mA.
• In IDLE mode, the state of all registers and I/O ports remains unchanged.
• In order to exit the IDLE mode and make the microcontroller operate normally,
it is necessary to enable and execute any interrupt or reset.
• It will cause the IDL bit to be automatically cleared and the program resumes
operation from instruction having set the IDL bit.
• It is recommended that first three instructions to execute now are NOP
instructions.
• They don't perform any operation but provide some time for the microcontroller
to stabilize and prevents undesired changes on the I/O ports.
Power Down mode
• By setting the PD bit of the PCON register from within the program, the
microcontroller is set to Power down mode, thus turning off its internal
oscillator and reduces power consumption enormously.
• The microcontroller can operate using only 2V power supply in power- down
mode, while a total power consumption is less than 40uA.
• The only way to get the microcontroller back to normal mode is by reset.
• While the microcontroller is in Power Down mode, the state of all SFR
registers and I/O ports remains unchanged.
• By setting it back into the normal mode, the contents of the SFR register is
lost, but the content of internal RAM is saved.
• Reset signal must be long enough, approximately 10mS, to enable stable
operation of the quartz oscillator.

You might also like