8051 Microcontroller Features
8051 Microcontroller Features
Contents
Microcontrollers Applications of microcontrollers Microprocessor vs microcontrollers History of 8051 microcontroller Features of microcontroller Block diagram and pin description of 8051 Registers Memory mapping in 8051 Timers and counters
Serial communication
Interrupts Applications of 8051 microcontroller
2
Microcontrollers
Microcontrollers are small computing systems on a single chip. A microcontroller will also be referred to as an MCU. Central Processing Unit (CPU) Program memory Random Access Memory (RAM) EEPROM - Electrically Erasable Programmable Read Only
Memory USARTs, Timer/Counters, ADC, DAC, I/O Ports, CANs, SPIs, etc. Examples : Motorolas 6811,Intels 8051,Zilogs Z8 and PIC 16X.
CPU I/O Port
3
RAM Timer
A single chip
Applications of microcontrollers
Cell phone Pager Watch Calculator video games Alarm clock Air conditioner TV remote Microwave oven Washing machines
Applications contd
Microprocessor vs Microcontroller
Microprocessor
CPU is stand-alone,
Microcontroller
CPU, RAM, ROM, I/O and timer are all on a single chip fix amount of on-chip ROM, RAM, I/O ports Highly bit addressable for applications in which cost, power and space are critical single-purpose
RAM, ROM, I/O, timer are separate designer can decide on the amount of ROM, RAM and I/O ports. Expansive versatility general-purpose
microcontroller called 8051. It has 4K bytes of ROM,128 Bytes of RAM , a serial port, two 16-bit Timers and 32 I/O pins. CPU can work with 8 bit of data at a time. Data larger than 8 bit can be broken into 8 bit pieces to be processed by the CPU
(ROM)
8051 CPU
Programmable I/O
External interrupts
10
purpose, i.e. they can operate as I/O or a control line or as part of address or data bus.
11
A (8-bit Accumulator) B (8-bit register for Mul &Div) PSW (8-bit Program Status Word) SP (8-bit Stack Pointer) PC (16-bit Program Counter) DPTR (16-bit Data Pointer)
12
List of registers
13
14
8k
0000H
32k
0FFFH
DS5000-32
1FFFH
8051
8752
7FFFH
Bit-Addressable RAM
20H
1FH 18H 17H 10H 0FH 08H 07H 00H
Register Bank 3
Register Bank 2
(Stack) Register Bank 1
Register Bank 0
16
Timers /Counters
The 8051 has 2 timers/counters:
Timer/Counter 0 Timer/Counter 1
Timer :
Used as a time delay generator. Many microcontroller application requires the counting of external events such as frequency, time delay.
17
18
Timer
Set the initial value of registers
Start the timer and then the 8051 counts up. Input from internal system clock (machine cycle) When the registers equal to 0 and the 8051 sets a bit to
8051
P2 P1
TH0 TL0
19
Set Timer 0
to LCD
Counter
Count the number of events Show the number of events on registers External input from T0 input pin (P3.4) for Counter 0 External input from T1 input pin (P3.5) for Counter 1 External input from Tx input pin. We use Tx to denote T0 or T1.
8051
TH0
P1
TL0
to LCD
P3.4 a switch
20
T0
TMOD Register
(MSB) GATE (LSB) M0
C/T M1 Timer 1
M0
GATE
C/T M1 Timer 0
TMOD. It is an-8-bit register . The lower 4-bits are meant for Timer 0 &the upper 4bits are meant for Timer 1 It is used similar to any other register of 8051 .
21
TMod contd.
C/T :
Timer or counter selected cleared for timer operation (input from internal system clock). Set for counter operation (input from Tx input pin). M1,M0 : Used for mode selection. Because the Timers of 8051 can be set in 4-different modes. M1
0 0 1
M0
TLx
1 0
Mode
0 1
Operation
13-bit timer mode 16-bit timer mode 8-bit auto reload
is to be
time it overflows.
Split timer mode
Gate
Every timer has a mean of starting and stopping.
GATE=0
Internal control The start and stop of the timer are controlled by way of
software. GATE=1
External control The hardware way of starting and stopping the timer by
software and an external source. Timer/counter is enabled only while the INT pin is high and the TR control pin is set (TR).
23
TCON Register
timer/counter,
24
Tcon contd
TR (Timer run control bit) TR0 for Timer/counter 0; TR1 for Timer/counter 1. TR is set by programmer to turn timer/counter on/off. TR=0 : off (stop) TR=1 : on (start)
26
by serial communication. These two pins are part of the Port3(P3.0 &P3.1) These pins are TTL compatible and hence they require a line driver to make them RS232 compatible Max232 chip is one such line driver in use. Serial communication is controlled by an 8-bit register called SCON register, it is a bit addressable register.
27
28
SM0 , SM1
These two bits of SCON register determine the framing of data by specifying the number of bits per character and start bit and stop bits. There are 4 serial modes.
SM0 0 0 1 1
29
SM1 0 1 0 1
Serial Mode 0 Serial Mode 1, 8 bit data, 1 stop bit, 1 start bit Serial Mode 2 Serial Mode 3
REN, TI, RI
REN (Receive Enable) also referred as SCON.4. When it is high, it allows the 8051 to receive data on the
30
TI,RI
TI (Transmit interrupt)
It is the D1 bit of SCON register.
Contd
When 8051 finishes the transfer of 8-bit character, it raises the TI flag to indicate that it is ready to transfer another byte.
RI (Receive interrupt)
31
It is the D0 bit of the SCON register. When the 8051 receives data serially ,via RxD, it gets rid of the start and stop bits and places the byte in the SBUF register. Then it raises the RI flag bit to indicate that a byte has been received and should be picked up before it is lost. RI is raised halfway through the stop bit.
Interrupt Sources
8051 has 6 sources of interrupts
Reset Timer 0 overflow Timer 1 overflow External Interrupt 0 External Interrupt 1 Serial Port events (buffer full, buffer empty, etc)
32
Upon reset all Interrupts are disabled and do not respond to the Microcontroller These interrupts must be enabled by software in order for the Microcontroller to respond to them. This is done by an 8-bit register called Interrupt Enable Register (IE).
33
: : : : : : : :
Global enable/disable. Undefined. Enable Timer 2 interrupt. Enable Serial port interrupt. Enable Timer 1 interrupt. Enable External 1 interrupt. Enable Timer 0 interrupt. Enable External 0 interrupt.
34
Interrupt Priorities
If two interrupt sources interrupt at the same time ,the interrupt with the highest PRIORITY gets serviced first. All interrupts have a power on default priority order. 1. External interrupt 0 (INT0) 2. Timer interrupt0 (TF0) 3. External interrupt 1 (INT1) 4. Timer interrupt1 (TF1) 5. Serial communication (RI+TI) Priority can also be set to high or low by IP reg.
35
IP.7: reserved IP.6: reserved IP.5: Timer 2 interrupt priority bit (8052 only) IP.4: Serial port interrupt priority bit IP.3: Timer 1 interrupt priority bit IP.2: External interrupt 1 priority bit IP.1: Timer 0 interrupt priority bit IP.0: External interrupt 0 priority bit
36
A high-priority interrupt can interrupt a low-priority interrupt All interrupt are latched internally Low-priority interrupt wait until 8051 has finished servicing the high-priority interrupt
37
38
Applications contd
The 8051 has been in use in a wide number of
devices, mainly because it is easy to integrate into a project or build a device around.
Energy Management: Efficient metering systems help in controlling
energy usage in homes and industrial applications. These metering systems are made capable by incorporating microcontrollers.
39
Applications contd
Touch screens:
A high number of microcontroller providers incorporate
touch-sensing capabilities in their designs. Portable electronics such as cell phones, media players and gaming devices are examples of microcontroller-based touch screens.
Automobiles:
The 8051 finds wide acceptance in providing
40
automobile solutions. They are widely used in hybrid vehicles to manage engine variants. Functions such as cruise control and anti-brake system have been made more efficient with the use of
Applications contd
Medical Devices:
Portable medical devices such as blood pressure
and glucose monitors use microcontrollers will to display data, thus providing higher reliability in providing medical results.
41
Thank you
42