You are on page 1of 39

MICROCONTROLLER

AND
ITS APPLICATION
WORKSHOP

January 26, 2007


Usman Institute of Technology, Karachi.

Noman Ahmed
Lecturer
SSUET
E-mail: noman_sid@hotmail.com
Introduction
 It is hard to imagine the present world of electronic devices without the
microprocessor.
 Cash register, scales, ovens, washing machine, alarm clock, thermostats,

and ignition system, etc.


 1971 (Microprocessors)
 Intel 8080, Motorola 6800, RCA 1801, MOS Technology and Zilog Z80.

 1976 (Microcontrollers)
 Intel 8748 (MCS-48 family)  17,000 transistors

• CPU, 1KB EPROM, 64B RAM, 27 I/O pins, and an 8-bit timer.
• Used in washing machines and traffic light controllers.
 1980 (Microcontrollers)
 Intel 8051 (MCS-51 family)  60,000 transistors

• CPU, 4KB ROM, 128B RAM, 32 I/O Pins, a serial port, two 16-bit
timers.
A Computer System
 Computer is defined by two key traits:
 The ability to be programmed to operate on data without human

intervention.
 The ability to store and retrieve data.

 More generally, a computer system includes


 Peripheral devices for communicating with the human. (hardware)

 Program that process data. (software)

 A Computer system contains


 Central process unit (CPU) connected to random access memory

(RAM) and read-only memory (ROM) via the address bus, data bus,
and control bus. Interface circuits connect the system buses to
peripheral devices. (see next slide)
Block Diagram of Computer System
What’s a Microcontroller?
 A Microcontroller is a computer-on-a-chip, or, if you prefer, a
single-chip computer. Micro suggests that the device is small, and
controller tells you that the device might be used to control objects,
processes, or events.

 Another term to describe a microcontroller is embedded


controller, because the microcontroller and its support circuits are
often built into, or embedded in, the devices they control.
Where it Required
 Any device that measures, stores, controls, calculates, or displays
information is a candidate for putting a microcontroller inside.

 Application
 Automobiles

 Security System

 Answering Machine

 Cellular Phone

 Microwave

 Keyless entry

 Fax machine

 Toys

 Camera
Microprocessors vs. Microcontroller
 Hardware Achitecture
 Whereas a microprocessor is a single-chip CPU, a

microcontroller contains a CPU and much of the remaining


circuitry of a complete microcomputer system in a single IC.
 Microcontrollers (as control oriented devices) are called upon

to response to external stimuli in real time.



They must perform fast context switching, suspending, one
process while executing another in response to an ‘event’
(opening the oven’s door).
 Applications

Microcontrollers are suitable to ‘control’ of I/O devices in
designs requiring a minimum component count, whereas
microprocessors are suitable to ‘processing’ information in
computer systems.
Microprocessors vs. Microcontroller


(cont.)
Instruction set features
 Microprocessor instruction sets are ‘processing intensive’
implying they have powerful addressing modes with
instructions catering to operations on large volumes of data.
Microcontrollers, on the other hand, have instruction sets
catering to the control of inputs and outputs.


Microcontrollers have built-in circuitry and instructions for
input/output operations, event timing, and enabling and
setting priority levels for interrupts caused by external stimuli.
Microprocessors often require additional circuitry (serial
interface Ics, interrupt controllers, timers, etc. ) to perform
similar operations.
Hardware Architecture
 The MCS-51 is a family of microcontroller ICs developed, manufactured, and
marketed by Intel. Other IC manufacturers are
 Siemens, Advanced Micro Devices (AMD), Fujitsu, Philips are licensed ‘second

source’ suppliers of devices in the MCS-51 family.


 The generic MCS-51 IC is the 8051, the first device in the family offered
commercially. Its features are summarized
 4KB ROM (64KB external code memory space)

 128B RAM (64KB external data memory space)

 8-bit I/O ports (4EA)

 16-bit timers (2EA)

 Serial interface

 Boolean processor

 210 bit-addressable locations


Comparison of MCS-51 ICs
Part No. ROM/EPROM RAM Timers

8051 4K ROM 128B 2

8031 128B 2

8751 4K EPROM 128B 2

8052 8K ROM 256B 3

8032 256B 3

8752 8K EPROM 256B 3


8051 Block Diagram
INT1 Note: bold-faced pin assignments for P1 and P3.
INT2

Timer 1
Timer 0
Serial port
Timer 1 T1
Interrupt Other 128B RAM 4KB
Control registers ROM Timer 0 T0

CPU

Bus Control I/O ports Serial port


Oscillator

RST ALE P0 P1 P2 P3 TXD RXD


EA PSEN Address/data
8051 Pinouts
30pF P0.7 AD7(32)
VCC (40)
XTL1 (19) P0.6 AD6(33)
P0.5 AD5(34) Port 0
XTL2 (18) P0.4 AD4(35)
P0.3 AD3(36)
30pF
P0.2 AD2(37)
P0.1 AD1(38)
P0.0 AD0(39)
(29)
(30)
PSEN
ALE 8051 P1.7
P1.6
(8)
(7) Port 1
(31) EA P1.5 (6)
(9) RST P1.4 (5)
P1.3 (4)
P1.2 (3)
P1.1 (2)
RD(17) P3.7 P1.0 (1)
WR(16) P3.6 P2.7 A15(28)
Port 3 T1(15) P3.5 P2.6 A14(27)
Port 2
T0(14) P3.4 P2.5 A13(26)
P2.4 A12(25)
INT1(13) P3.3 A11(24)
P2.3
INT0(12) P3.2 P2.2 A10(23)
TXD(11) P3.1 P2.1 A9(22)
RXD(10) P3.0 VSS(20) P2.0 A8(21)
I/O Ports
 32 of the 8051’s 40 pins function as I/O port lines. However, 24 of
these 32 lines are dual-purpose.

 Dual purpose: can operate as I/O, control line, or part of


address/data bus.

 The 8-line in a port can be treated as a unit in interfacing to parallel


devices such as printers, A/D converters, and so on.

 Or, each line can operate independently in interfacing to single-bit


devices such as switches, LEDs, transistors, motors, and
loudspeakers.
I/O Ports
 Port 0
 Is a dual-purpose port on pins 32-39 of the 8051 IC.

 In minimum-component designs,

• It is used as a general purpose I/O port.


 For larger designs with external memory,

• It becomes a multiplexed address and data bus.


 Port 1
 Is a dedicated I/O port on pins 1-8.

 The pins are available for interfacing to external devices as required.

 Port 2
 Is a dual-purpose port on pins 21-28 of the 8051 IC.

 As a general purpose I/O port

 Or as the high-byte of the address bus for designs with external ROM or more than 256B

of RAM.
I/O Ports (cont.)
 Port 3
 Is a dual-purpose port on pins 10-17 of the 8051 IC.

 As a general purpose I/O port

 These pins are multifunctional, with each having an alternate purpose related to special features of

the 8051.

BIT NAME BIT functions


P3.0 RXD B0H Receive data for serial port
P3.1 TXD B1H Transmit data for serial port
P3.2 INT0 B2H External interrupt 0
P3.3 INT1 B3H External interrupt 1
P3.4 T0 B4H Timer/counter 0 external input
P3.5 T1 B5H Timer/counter 1 external input
P3.6 WR B6H External data memory write strobe
P3.7 RD B7H External data memory read strobe
Control Signals
 PSEN (Program Store Enable)

 Is an output signal on pin 29.

 It is a control signal that enables external program (code) memory (ROM).

 It usually connects to an EPROM’s output enable (OE) pin to permit reading of


program bytes.

 The PSEN signal pulses low (active stage) during the fetch stage of an instruction,
which is stored in external program memory.

 The binary codes of a program (opcode) are read from EPROM, travel across the
data bus, and are latched into the 8051’s instruction register (IR) for decoding.
Control Signals
 ALE (Address Latch Enable)

 Is an output signal on pin 30.

 It is used for de-multiplexing the address and data bus.

 When port 0 is used in its alternate mode – as the data bus and low-byte of the
address bus – ALE is the signal that latches the address into an external register
during the first-half of a memory cycle. This done, the port 0 lines are then
available for data input or output during the second-half of the memory cycle.

 The ALE signal pulses at 1/6th the on-chip oscillator frequency


Control Signals
 EA (External Access)
 Is an input signal on pin 31.

 Is generally tied high (5V) or low (ground).

 If high

• The 8051 executes programs from internal ROM when executing in the lower
4K/8K of memory.
 If low

• Programs execute from external memory only (and PSEN pulses low)
 RST (Reset)
 Is an input signal on pin 9.

 When this signal is brought high for at least 2 machine cycles, the 8051 internal

registers are loaded with appropriate values for an orderly system start-up.
 For normal operation, RST is low.
Memory Organization
 Most microprocessors implement a shared memory apace for data
and programs. Both the data and programs reside in the system
RAM. Microcontroller, on the other hand, the control program must
reside in ROM.

 The internal memories consist of ROM and RAM. The RAM


contains a rich arrangement of general-purpose storage, bit
addressable storage, register banks, and special function registers.
RAM
7F FF
General-purpose
RAM (80 bytes)

30
2F Special Function
Bit-addressable Registers (SFR)
locations (16 bytes)

20
1F Bank registers
(32 bytes)

00 80
General-Purpose RAM
7F
General-purpose Ex: To read the contents of
RAM (80 bytes)
internal RAM address 5FH into
the accumulator.
30
2F Solution1:(direct address mode)

MOV A, 5FH
Solution2:(immediate addressing &
indirect address mode)
20 MOV R0, #5FH
1F Bank registers
(32 bytes) MOV A, @R0

00
210 (128+82) Bit-Addressable RAM
7F FF
The idea of
individually
accessing bits
30
Special Function through software
2F
Bit-addressable Registers (SFR) is a powerful
locations (16 bytes) (82 bits) feature of most
(128 bits) microcontroller.

20
1F

00 80
128 General-Purpose
Bit-Addressable Locations
2F 7F 7E 7D 7C 7B 7A 79 78
2E 77 76 75 74 73 72 71 70
2D 6F 6E 6D 6C 6B 6A 69 68
2C 67 66 65 64 63 62 61 60
2B 5F 5E 5D 5C 5B 5A 59 58
2A 57 56 55 54 53 52 51 50
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
20 07 06 05 04 03 02 01 00
Register Banks
1F R7
18 ~R0 Bank 3 (8 bytes)

17 R7
Bank 2 (8 bytes)
10 ~R0
0F R7
Bank 1 (8 bytes)
08 ~R0
07 R7 Bank 0 (8 bytes)
00 ~R0

Ex: Read the contents of address 05H into the accumulator.


Solution: (Register address mode)
MOV A, R5 (only 1-byte)
Solution: (direct address mode)
MOV A, 05H (2-byte instruction)
21 Special Function Registers (SFR)
F0 F7 F6 F5 F4 F3 F2 F1 F0 B
E0 E7 E6 E5 E4 E3 E2 E1 E0 ACC
D0 D7 D6 D5 D4 D3 D2 - D0 PSW
B8 - - - BC BB BA B9 B8 IP
B0 B7 B6 B5 B4 B3 B2 B1 B0 P3
A8 AF - - AC AB AA A9 A8 IE
A0 A7 A6 A5 A4 A3 A2 A1 A0 P2
99 Not bit addressable SBUF
98 9F 9E 9D 9C 9B 9A 99 98 SCON
90 97 96 95 94 93 92 91 90 P1
8D Not bit addressable TH1
8C Not bit addressable TH0
8B Not bit addressable TL1
8A Not bit addressable TL0
89 Not bit addressable TMOD
88 8F 8E 8D 8C 8B 8A 89 88 TCON
87 Not bit addressable PCON

83 Not bit addressable DPH


82 Not bit addressable DPL
81 Not bit addressable SP
80 87 86 85 84 83 82 81 80 P0
Addressing Modes
 The 8051 is capable of performing direct and indirect memory accesses on
its various memory spaces.

 These are the typical methods through which processor systems access
memory.

 Addressing modes are in integral part of each computer’s instruction set.


There are 8 modes available:

 Register, Direct, Indirect, Immediate, Relative, Absolute, Long, and


Indexed.
Instruction Set
 The MCS-51 instruction set is optimized for 8-bit control
applications.

It provides a variety of fast, compact address modes for
accessing the internal RAM to facilitate operations on
small data structures.
 The 8051 instructions have 8-bit opcodes  28 = 256
instructions.
 255 are implemented and 1 is undefined.

 There are 139 one-byte instructions, 92 two-byte

instructions, and 24 three-byte instructions.


(139+92+24=255)
Instruction Set (cont.)
 Types of Instruction


Arithmetic Instructions

 Logical Instructions

 Data Transfer Instructions


Boolean Instructions

 Program Branching Instructions


INTERFACING OF DIFFERENT
COMPONENTS
WITH
MICROCONTROLLER
Input Devices
 On-Off switch
 Push button
 Limit Switch
 IR sensor
 Metal Detector
 DTMP Decoder
 KEY Pad
Output Devices
 Leds
 Relay
 Solenoid
 Seven segment
 LCD display
 Dot Matrix display
 Stepper Motor
Interfacing of LCD
8051 LCD
P1.0 D0 VCC
~ ~ 10K
P1.7 D7 VEE
Rs R/W E
VSS

P2.0
P2.1
P2.2
Temperature Sensor
Physical data
(temperature, light, Output Electrical
flow, speed, and Transducers Signals (current,
etc.) (Sensors) voltage, resistance,
capacitance, and
etc.)

o
C K Ohm
Thermistor
0 29.49

Temperature Resistance 25 10
50 3.893
75 1.7
100 0.817
Interfacing of ADC808/809
 ADC808/809 Chip with 8 analog channel. This means this kind of chip
allows to monitor 8 different transducers.
 ADC804 has only ONE analog input: Vin(+).
ADC808
D0 ~ D7
8 channels
(IN0~IN7)
GND channel CBA
CLK EOC IN0 000
VCC OE IN1 001
Vref(+) IN2 010
Vref(-) IN3 011
SC ALE C BA IN4 100
IN5 101
IN6 110
IN7 111
Interfacing of Stepper Motor
 Stepper motor translates electrical pulses into mechanical movement (for
position control).
 Applications: Disk Driver, Dot matrix printer, robotics.

A 4 Step Sequences
N S
Step A B C D
C S N D
s
S
1 1 0 0 1
N
B 2 1 1 0 0
3 0 1 1 0
4 0 0 1 1
Interfacing of Keyboard
 Keyboard and LCDs are the most widely used input/output devices
of the 8051, and a basic understanding of them is essential.
 See Figure
Project Steps
 Putting together a microcontroller project involves
several steps:
1. Define the task
2. Design and build the circuits
3. Write the control program
4. Test and debug

Sometimes the steps won’t follow exactly in this order.


Projects
 Digital Clock
 Keyless entry
 Mobile Automation
 Robotic Arm
 Elevator Control System
 Industrial Network
 DC/AC Drive
Projects
 PABX
 Autonomous Robot
 Infant incubator
 Attendace System
 Car Tracking
 Score Board
 Prepaid Energy meter
 CNC PCB drill machine

You might also like