POGRAMMABLE LOGIC CONTROLLERS AND MICROCONTROLLERS LIST...
Transcript of POGRAMMABLE LOGIC CONTROLLERS AND MICROCONTROLLERS LIST...
POGRAMMABLE LOGIC CONTROLLERS AND MICROCONTROLLERS
LIST OF CONTENTS
Unit1 Introduction to PLC, Concept of PLC - Building blocks of PLC - Functions of various blocks,
- limitations of relays - Advantages of PLCs over electromagnetic relays - Different
programming languages - PLC manufacturer etc.
Unit 2 Working of PLC, Basic operation and principles of PLC, Architectural details
processor Memory structures - I/O structure Programming terminal - Power supply
Unit3 Instruction Set - Basic instructions bit.-Timer instruction like retentive timers, resetting of timers -
Counter instructions like up counter, down counter, resetting of counters.- Arithmetic Instructions
(ADD,SUB,DIV,MUL etc.)- MOV instruction - Comparison instructions like equal, not equal, greater,
greater than equal, less than, less than equal 4. Ladder Diagram Programming 5 Applications of PLCs 6 Micro Controller Series(MCS)-51Over View 7 Instruction Set Addressing Modes 8 Assembly language programming 9 Design and Interface
UNIT I
1.1 Introduction to PLC
The hydramatic Division of the General Motors Corporation specified the design criteria for the first
programmable controller come in 1968. Programmable logic controllers, also called programmable
controllers or PLCs, are solid-state members of the computer family, using integrated circuits instead of
electromechanical devices to implement control functions. They are capable of storing instructions, such
as sequencing, timing, counting, arithmetic, data manipulation, and communication, to control industrial
machines and processes
Purposes - Initially designed to replace relay logic boards, Sequence device actuation, Coordinate
activities accepts input from a series of switches, Sends output to devices or relays
What is PLC?
Programmable Logic Controller (PLC) is a digital computer used for the automation of various
electro-mechanical processes in industries. These controllers are specially designed to survive in harsh
situations and shielded from heat, cold, dust, and moisture etc. PLC consists of a microprocessor which
is programmed using the computer language. The program is written on a computer and is downloaded to the PLC via cable. These loaded programs
are stored in non – volatile memory of the PLC. During the transition of relay control panels to PLC, the
hard wired relay logic was exchanged for the program fed by the user. A visual programming language
known as the Ladder Logic was created to program the PLC.
1.2 Advantages of PLCs over electromagnetic relays
• Ability to interface / communicate with computers but not with reley • Simple programming is possible using ladder logic but not with relay
• Plc have High reliability • High controllability due to the use of timers and counters. • Easy maintenance
• Rugged construction - can operate in extremely harsh conditions
• Small size • Easy expandability • Economical in long term
1.3 Limitation of Relay-
• It suffer from contact wear and reliability problems • Unsuitable for designing complex control circuit • Relay occupies large space • Relay takes large time to actuate
2 | P a g e
1.4 Building blocks of PLC
1.5 Functions of various blocks
PLCs have input/output devices like switches, push buttons, limit switches,sensors,lamp indicators,relays solenoids motors etc. block diagram of a PLC shown in above Fig. It has three
major units/sections.
• I/O (Input/Output) Modules. • CPU (Central Processing Units).
• Programmer/Monitor.
The input section converts the field signals supplied by input devices/sensors to logic-level signals that the PLC's CPU can read. The Processor Section reads these inputs, Processes the signal, and prepares the output signals. The output section converts the logic level output signals coming from processor section to high level signals and used to actuate various output field devices. The programmer/monitor is used to enter the user's program into memory and to monitor the execution of the program.
I/O Section:-
The I/O section establishes the interfacing between physical devices in the real world outside the PLC and the digital arena inside the PLC.
The input module has bank of terminals for physically connecting input devices, like push buttons,
limit switches etc. to a PLC. The role of an input module is to translate signals from input devices into a form that the PLC's CPU can understand.
The Output module also has bank of terminals that physically connect output devices like solenoids,
motor starters, indicating lamps etc. to a PLC. The role of an output module is to translate signals
from the PLC's CPU into a form that the output device can use. The tasks of the I/O section can be
classified as:
• Conditioning
3 | P a g e
• Isolation • Termination • Indication
An electronic system for connecting I/O modules to remotely located I/O devices can be added if
needed. The actual operating process under PLC Control can be thousands of feet from the CPU and its I/O modules. CPU Section:-
The Central Processing Unit, the brain of the system is the control portion of the PLC. It has
three Subparts.
• Memory System • Processor • Power Supply
Memory System:- The memory is the area of the CPU in which data and information is stored and retrieved. The total
memory area can be subdivided into the following four Sections.
I/O Image Memory
The input image memory consists of memory locations used to hold the ON or OFF states of each input
field devices, in the input status file. The output status file consists of memory locations that stores the ON or OFF states of hardware output
devices in the field. Data is stored in the output status file as a result of solving user program and is
waiting to be transferred to the output module's switching device.
Data Memory - It is used to store numerical data required in math calculation, bar code data etc.
User Memory - It contains user's application program.
Executive Memory - It is used to store an executive program or system software. An operating system of
the PLC is a special program that controls the action of CPU and consequently the execution of the
user's program. A PLC operating system s designed to scan image memory, interprets the instruction of
user's program stored in main memory, and executes the user's application program the operating
system is supplied by the PLC manufacturer and is permanently held in memory. Processor:-The processor, the heart of CPU is the computerized part of the CPU in the form of
Microprocessor / Micro controller chip. It supervises all operation in the system and performs all
tasks necessary to fulfill the PLC function.
• It reads the information i.e. status of externally connected input devices with input module.
It stores this information in memory for later use.
It carries out mathematical and logic operations as specified in application program.
After solving the user's program, it writes the result values in the memory.
It sends data out to external devices like output module, so as to actuate field hardware.
It performs peripheral and external device communication.
4 | P a g e
Power Supply -
The power supply provides power to memory system, processor and I/O Modules.
It converts the higher level AC line Voltage to various operational DC values.
For electronic circuitry. It filters and regulates the DC voltages to ensure proper computer operations.
Programmer/Monitor -
The Programmer/Monitor (PM) is a device used to communicate with the circuits of
the PLC. The programming unit allows the engineer/technicians to enter the edit the program to be
executed. In its simplest form it can be hand-held device with membrane keypad for program entry and a
display device (LED or LCD) for viewing program steps of functions. More advanced systems employ a
separate industrial terminal or personal computers with type-writer type keyboard and CRT monitors.
With the help of proprietary software, it allows programmer to write, view and edit the program and
download it into the PLC. It also allows user to monitor the PLC as it is running the program. With this
monitoring systems, such things as internal coils, registers, timers and other items not visible externally
can be monitored to determine proper operation. Also, internal register data can be altered, if required. to
fine tune program operation while debugging. Communication between PM and PLC is done via a cable
connected to a special programming port on PLC. Connection to the personal computer can be through a
serial port or from a dedicated card installed in the computer.
1.6 PLC Programming language - Using flowcharts, Using ladder logic and Using statement logics or
mnemonics 1.7 PLC manufacturer - Allen Bradley, Rockwell Automation, Mitsubishi, Omron, Siemens etc.
Programmable Logic Controllers Multiple Choice Questions
Q1. The acronym PLC stands for: (A) Pressure Load Control
(B) Programmable Logic Controller (C) Pneumatic Logic Capstan (D) PID Loop Controller (E) Pressure Loss Chamber
Q2. The PLC was invented by
A) Bill Gates B) Dick Morley C) Bill Landis D) Tod Cunningham
Q3. Ladder logic programming consists primarily of: (A) Virtual relay contacts and coils
(B) Logic gate symbols with connecting lines (C) Function blocks with connecting lines
(D) Text-based code (E) Hieroglyphics
5 | P a g e
Q4. In a PLC, the scan time refers to the amount of time in which …..
(A) the technician enters the program (B) timers and counters are indexed by (C) one “rung” of ladder logic takes to complete (D) the entire program takes to execute
(E) transmitted data communications must finish
Q5. Which one of the following is not a PLC manufacturer
a. Siemens b. Mitsubishi c. Microsoft d. ABB
Short/long answer types questions
Q1 Define PLC Q2 What are the limitations of relay over PLC
Q3 Explain building blocks of PLC in detail Q4 List the names of PLC manufacturer.
6 | P a g e
UNIT 2
2. Working of PLC (Programmable Logic Controller) The Programmable logic controller functions in four steps.
Input scan: The state of the input is scanned which is connected externally. The inputs include
switches, pushbuttons, and proximity sensors, limit switches, pressure switches. Ideally, they are
transformers and not relays. Program scan: The loaded program is executed to carry out the function appropriately.
Output scan: The input sources have a control over the output ports to energize or de-energize
them. The outputs include solenoids, valves, motors, actuator, and pumps. Depending on the
model of PLC, these relays can be transistors.
2.1 PLC ARCHITECTURE • The input sources convert the real time analog electric signals to suitable digital electric
signals and these signals are applied to the PLC through the connector rails. • These input signals are stored in the PLC external image memory in locations known as
bits. This is done by the CPU • The control logic or the program instructions are written onto the programming device
through symbols or through mnemonics and stored in the user memory. • The CPU fetches these instructions from the user memory and executes the input signals by
manipulating, computing, processing them to control the output devices. • The execution results are then stored in the external image memory which controls the
output drives. • The CPU also keeps a check on the output signals and keeps updating the contents of the input
image memory according to the changes in the output memory. • The CPU also performs internal programming functioning like setting and resetting of the
timer, checking the user memory.
7 | P a g e
PC
Program
Loader
Switches
Printer
Processor I/O
Modules Machines
Cassette Loader
Power
EPROM Memory
Supply
Loader
Peripherals External Devices
2.2 PLC Hardware
• The hardware components of a PLC system are CPU, Memory, Input/Output, Power supply unit,
and programming device. Below is a diagram of the system overview of PLC.
•
CPU – Keeps checking the PLC controller to avoid errors. They perform functions including
logic operations, arithmetic operations, computer interface and many more.
• Memory – Fixed data is used by the CPU. System (ROM) stores the data permanently for the
operating system. RAM stores the information of the status of input and output devices, and the
values of timers, counters and other internal devices.
• I/O section – Input keeps a track on field devices which includes sensors, switches.
• O/P Section - Output has a control over the other devices which includes motors, pumps, lights
and solenoids. The I/O ports are based on Reduced Instruction Set Computer (RISC).
• Power supply – Certain PLCs have an isolated power supply. But, most of the PLCs work at
220VAC or 24VDC.
• Programming device – This device is used to feed the program into the memory of the
processor. The program is first fed to the programming device and later it is transmitted to the
PLC’s memory.
System Buses – Buses are the paths through which the digital signal flows internally of the PLC. The four system buses are:
• Data bus is used by the CPU to transfer data among different elements.
• Control bus transfers signals related to the action that are controlled internally.
• Address bus sends the location’s addresses to access the data.
• System bus helps the I/O port and I/O unit to communicate with each other
8 | P a g e
2.3 The memory space can be divided into two broad categories:
Program and Data Memory:
Advanced ladder logic functions allow controllers to perform calculations, make decisions and do other
complex tasks. Timers and counters are examples of ladder logic functions. They are more complex than
basic inputs contacts and output coils and relay heavily upon data stored in the memory of the PLC.
The user program will account for most of the memory of a PLC system. Program files contain the logic controlling machine operation. This logic consists of instructions that are programmed in a ladder logic format.
The data file portion of memory stores input and output status, processor status, the status of various bits and numerical data.
9 | P a g e
Multiple Choice Questions
Q.1 one of the following is an input device
a. Motor b. Light
c. Valve d. Sensor
Q.2 Solenoids, lamps, motors are connected to:
a. Analog output b. Digital output c. Analog input d. Digital input
Q.3 The type of memory which is fast and temporarily stores the data which are
immediately required for use is called as______.
a. HDD b. ROM c. RAM d. SSD
Q.4 how is the speed of operation of conventional relay system as compared to digital controllers?
a. very slow b. very fast c. same d. almost similar
Q.5 The PLC is used in _______.
a. machine tools b. automated assembly equipment c. moulding and extrusion machines
d. all of the above
10 | P a g e
UNIT 3 INSTRUCTION SETS
3. PLC Instructions
3.1 Bit instructions
3.2 Timer and Counter instructions
3.3 Program Control Instructions
3.4 Compare Instructions
3.5 Math Instructions
3.1 Bit Instructions
Mnemonic Name Symbol Description
XIC Examine If Examines a bit for an On (set, high)
Closed condition.
XIO Examine If Examines a bit for an Off (cleared, low)
Open condition.
OTE Output When rung conditions are true, the OTE
Energize will either set or clear the data bit.
OTL Output Latch When enabled, the instruction signals to
the controller to turn on the addressed
bit. The bit remains on, regardless of the
rung condition.
OTU Output When enabled, it clears (unlatches) the
Unlatch data bit. The bit remains Off, regardless
of rung condition.
3.2 Timer and Counter Instructions
Mnemonic Name Symbol Description
TON Timer On A non-retentive timer that accumulates
Delay time when the instruction is enabled. The accumulated value is reset when
rung conditions go false.
11 | P a g e
TOF Timer Off A non-retentive timer that accumulates
Delay time when the rung makes a true-to-
false transition.
RTO Retentive A retentive timer that accumulates time
Timer On when the instruction is enabled. Retains
its accumulated value when rung
conditions become false.
TON Count Up An instruction that counts false-to-true
rung transitions. It counts upward and
the accumulated value is incremented
by one count on each of these
transitions.
TOF Count Down This instruction counts downward on
each false-to-true rung transition. The
accumulated value is decremented by
one count on each of these transitions.
RTO Retentive A retentive timer that accumulates time
Timer On when the instruction is enabled. Retains
its accumulated value when rung
conditions become false.
CTU Count Up An instruction that counts false-to-true
rung transitions. It counts upward and
the accumulated value is incremented
by one count on each of these
transitions.
CTD Count Down This instruction counts downward on
each false-to-true rung transition. The
accumulated value is decremented by
one count on each of these transitions.
RES Reset This instruction is used to reset a timer,
counter or control structure. The
accumulated value of these instructions
are cleared when the RES instruction is
enabled.
12 | P a g e
3.3 Move/Logical Instructions
Mnemonic
Name
Symbol
Description
MOV Move Copies the Source (which remains
unchanged) to the Destination.
MVM Masked Move Copies the Source to a Destination and
allows segments of the data to be masked.
CLR Clear Clears all the bits of the Destination.
DTR Data Passes the Source value through a Mask
Transitional and compares the result with the Reference
value.
SWPB Swap Byte Rearranges the bytes of a tag and stores the
Instruction bytes in the new order.
SWP Swap Byte Swaps the lower and higher bytes of a
Instruction specified number of words.
BTD Bit Field Copies the specified bits from the Source,
Distribute shifts the bits to the appropriate position,
and writes the bits into the Destination.
13 | P a g e
AND Bitwise AND Performs a logical AND operation by using
the bits in Source A and Source B and
placing the result in the Destination.
OR Bitwise OR Performs a logical AND operation by using
the bits in Source A and Source B and
placing the result in the Destination.
XOR Bitwise Performs a bitwise XOR operation using
Exclusive OR the bits in Source A and Source B and
stores the result in the Destination.
NOT Bitwise NOT Executes a bitwise NOT operation by using
the bits in the Source and placing the result
in the Destination
3.4 Program Control Instructions
Mnemonic
Name
Symbol
Description
JSR Jump to This instruction jumps execution to a
Subroutine specific routine and initiates the execution
of this routine, called a subroutine.
SBR Subroutine Stores recurring sections of program logic.
RET Return Used to return to the instruction following
the a JSR operation.
JMP Jump to Label Skips sections of ladder logic.
LBL Label Target of the JMP instruction with the same
label name.
14 | P a g e
MCR Master Cont. Used in pairs to create a program zone that
Res. can disable all rungs between the MCR
instructions.
AFI Always False Disables all instructions on a rung.
NOP No Operation This instruction functions as a placeholder.
TND Temporary End When enabled, it lets the controller execute
logic only up to this instruction.
IOT Immediate This instruction immediately updates the
Output specified output data.
3.5 Compare Instructions
Mnemonic Name Symbol Description
EQU Equal This instruction is used to test whether two
values are equal. If Source A is equal to
Source B, the instruction is logically true.
GEQ Greater Than Determines whether Source A is greater than
or Equal To or equal to Source B. If the value at Source A
is greater than or equal to the value at Source
B, then the instruction is true.
GRT Greater Than This instruction is used to test whether one
value (Source A) is greater than another value
(Source B).
LEQ Less Than or Determines whether one value (Source A) is
Equal To less than or equal to another (Source B).
15 | P a g e
LES Less Than This instruction determines whether Source A
is less than Source B.
LIM Limit This instruction is used to test for values
within the range of the Low Limit to the High
Limit.
MEQ Mask Equal Passes the Source and Compare values
To through a Mask and compares the results.
NEQ Not Equal This instruction tests whether Source A is not
To equal to Source B.
3.6 Math Instructions
Mnemonic
Name
Symbol
Description
ADD Add Adds Source A to Source B and stores the
result in the Destination.
SUB Subtract Subtracts Source B from Source A and
places the result in the Destination.
MUL Multiply Multiplies Source A by Source B and stores
the result in the destination.
16 | P a g e
DIV Divide Divides Source A by Source B and places
the result in the Destination.
MOD Modulo Divides Source A by Source B and stores
the remainder in the Destination.
SQR Square Root Calculates the square root of the source and
places the integer result in the Destination.
NEG Negate Changes the sign (+, -) of the Source and
stores the result in the Destination.
ABS Absolute Takes the absolute value of the Source and
places the result in the Destination.
Multiple Choice Questions
Question 1: Examine-on instruction in PLC language is symbolically represented by what shape? A. -] [- B. -( )- C. -]/[-
D. None of these Question 2: The symbol -(L)- represent what instruction in the PLC
language?
A. OUT output unlatch instruction.
B. OTL output latch instruction.
C. Examine off instruction. D. Output energizes instruction. Question 3: The address T4:6.ACC is used to address what?
A. Accumulator for timer 4 in file 6.
17 | P a g e
B. Preset value of timer 6 in file 4. C. Accumulator for timer 6 in file 4.
D. Accumulator for counter 6 in file 4.
Q4: To reset the time for a PLC what condition must be true?
A. Reset rung of TON must be true. B. Reset rung of TON must be false.
C. RST instruction with timer address must be true.
D. RST instruction with associated timer address must be false. Question 5: To increase the number of inputs and outputs of the PLC, one can use expansion modules. A. True. B. False. C. None of the above.
Question 6: Solenoids, lamps, motors are connected to: A. Analog output.
B. Digital output.
C. Analog input.
D. Digital input Question 7: In a counter instruction if the accumulator value becomes greater than or equal to the preset value then which of the following is true?
A. CU bit goes on.
B. DN bit goes on.
C. Both CU and DN bits go on.
D. None of the above.
Short / long Answer type Questions Q1 Explain time instructions in detail Q2 Explain Counter instructions in detail
4 Ladder Logic
Let’s take a look at an example of ladder logic programming:
Figure 1. A simple ladder logic program
This ladder logic program is three rungs long. The program is “scanned” or run by the CPU from left
to right and top to bottom. The symbols placed throughout the rungs are actually graphical
instructions. The names for these instructions are:
XIC (Examine If Closed)
XIO (Examine If Open)
OTE (Output Energize).
First Rung
Looking at the first rung, notice the first two inputs I:1/1 and I:1/2. The symbol is an XIC, and the I
denotes that this is an input. This instruction represents a physical input found on one of the discrete
input cards.
Figure 2. The first rung represents a physical input found on one of the discrete input cards.
I:1 means that this input card has been placed in slot 1, directly adjacent to the processor. The /1
indicates the bit of interest. Input cards have more than one channel, and if the instruction specifies
/1, the instruction accesses channel 1.
The second input represents channel 2 on the same card. An XIC instruction really means true if
closed. That is, this instruction will be true if the input device it represents is closed. If an instruction
is true it is highlighted in green. The only way for an output to be energized is if a path of true
instructions can be traced from the left rail to the right rail. Therefore, the output on rung one will be
true because a path of true instructions, I:1/1 and I:1/2, exists. This is effectively an AND operation.
The output in this case, B: 0/1, is actually an internal bit stored in the PLC's memory. That’s why it’s
labeled B instead of O for “output.” These internal bits work great when a certain state or set of
inputs needs to be recorded without actually turning on a physical output.
Unit 5
Automation of product packaging
Product packaging is one of the most frequent cases for automation in industry. It can be encountered
with small machines (ex. packaging grain like food products) and large systems such as machines for
packaging medications. Example we are showing here solves the classic packaging problem with few
elements of automation. Small number of needed inputs and outputs provides for the use of CPM1A
PLC controller which represents simple and economical solution.
By
pushing START key you activate Flag1 which represents an assisting flag (Segment 1) that comes up
as a condition in further program (resetting depends only on a STOP key). When started, motor of an
conveyor for boxes is activated. The conveyor takes a box up to the limit switch, and a motor stops
then (Segment 4). Condition for starting a conveyor with apples is actually a limit switch for a box.
When a box is detected, a conveyor with apples starts moving (Segment 2). Presence of the box
allows counter to count 10 apples through a sensor used for apples and to generate counter CNT010
flag which is a condition for new activation of a conveyor with boxes (Segment 3). When the
conveyor with boxes has been activated, limit switch resets counter which is again ready to count 10
apples. Operations repeat until STOP key is pressed when condition for setting Flag1 is lost. Picture
below gives a time diagram for a packaging line signal.
Ladder diagram:
Traffic light control using PLC
Pump control
6. 8051 Microcontroller
A microcontroller is a small and low-cost microcomputer, which is designed to perform the specific
tasks of embedded systems like displaying microwave’s information, receiving remote signals, etc.
The general microcontroller consists of the processor, the memory (RAM, ROM, EPROM), Serial
ports, peripherals (timers, counters), etc.
Difference between Microprocessor and Microcontroller
The following table highlights the differences between a microprocessor and a microcontroller −
Microcontroller Microprocessor
Microcontrollers are used to execute a single
task within an application.
Microprocessors are used for big
applications.
Its designing and hardware cost is low. Its designing and hardware cost is high.
Easy to replace. Not so easy to replace.
It is built with CMOS technology, which
requires less power to operate.
Its power consumption is high because it
has to control the entire system.
It consists of CPU, RAM, ROM, I/O ports. It doesn’t consist of RAM, ROM, I/O ports.
It uses its pins to interface to peripheral
devices.
Types of Microcontrollers
Microcontrollers are divided into various categories based on memory, architecture, bits and
instruction sets. Following is the list of their types −
Bit
Based on bit configuration, the microcontroller is further divided into three categories.
8-bit microcontroller − This type of microcontroller is used to execute arithmetic and logical
operations like addition, subtraction, multiplication division, etc. For example, Intel 8031 and
8051 are 8 bits microcontroller.
16-bit microcontroller − This type of microcontroller is used to perform arithmetic and
logical operations where higher accuracy and performance is required. For example, Intel
8096 is a 16-bit microcontroller.
32-bit microcontroller − This type of microcontroller is generally used in automatically
controlled appliances like automatic operational machines, medical appliances, etc.
Memory
Based on the memory configuration, the microcontroller is further divided into two categories.
External memory microcontroller − This type of microcontroller is designed in such a way
that they do not have a program memory on the chip. Hence, it is named as external memory
microcontroller. For example: Intel 8031 microcontroller.
Embedded memory microcontroller − This type of microcontroller is designed in such a way
that the microcontroller has all programs and data memory, counters and timers, interrupts, I/O
ports are embedded on the chip. For example: Intel 8051 microcontroller.
Instruction Set
Based on the instruction set configuration, the microcontroller is further divided into two categories.
CISC − CISC stands for complex instruction set computer. It allows the user to insert a single
instruction as an alternative to many simple instructions.
RISC − RISC stands for Reduced Instruction Set Computers. It reduces the operational time
by shortening the clock cycle per instruction.
Applications of Microcontrollers
Microcontrollers are widely used in various different devices such as −
Light sensing and controlling devices like LED.
Temperature sensing and controlling devices like microwave oven, chimneys.
Fire detection and safety devices like Fire alarm.
Measuring devices like Volt Meter.
8051 microcontroller is designed by Intel in 1981. It is an 8-bit microcontroller. It is built with 40 pins
DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit timers. It
consists of are four parallel 8-bit ports, which are programmable as well as addressable as per the
requirement. An on-chip crystal oscillator is integrated in the microcontroller having crystal frequency
of 12 MHz.
In the following diagram, the system bus connects all the support devices to the CPU. The system bus
consists of an 8-bit data bus, a 16-bit address bus and bus control signals. All other devices like
program memory, ports, data memory, serial interface, interrupt control, timers, and the CPU are all
interfaced together through the system bus.
The pin diagram of 8051 microcontroller looks as follows −
Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other functions. It is
internally pulled up, bi-directional I/O port.
Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values.
Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like
interrupts, timer input, control signals, serial communication signals RxD and TxD, etc.
Pins 18 & 19 − These pins are used for interfacing an external crystal to get the system clock.
Pin 20 − This pin provides the power supply to the circuit.
Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order address bus
signals are also multiplexed using this port.
Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a signal
from the external program memory.
Pin 30 − This is EA pin which stands for External Access input. It is used to enable/disable the
external memory interfacing.
Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to demultiplex the
address-data signal of port.
Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order address and
data bus signals are multiplexed using this port.
Pin 40 − This pin is used to provide power supply to the circuit.
8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or output.
Hence, total 32 input/output pins allow the microcontroller to be connected with the peripheral
devices.
Pin configuration, i.e. the pin can be configured as 1 for input and 0 for output as per the logic
state.
o Input/output (I/O) pin − All the circuits within the microcontroller must be connected
to one of its pins except P0 port because it does not have pull-up resistors built-in.
o Input pin − Logic 1 is applied to a bit of the P register. The output FE transistor is
turned off and the other pin remains connected to the power supply voltage over a pull-
up resistor of high resistance.
Port 0 − The P0 (zero) port is characterized by two functions −
o When the external memory is used then the lower address byte (addresses A0A7) is
applied on it, else all bits of this port are configured as input/output.
o When P0 port is configured as an output then other ports consisting of pins with built-in
pull-up resistor connected by its end to 5V power supply, the pins of this port have this
resistor left out.
Input Configuration
If any pin of this port is configured as an input, then it acts as if it “floats”, i.e. the input has unlimited
input resistance and in-determined potential.
Output Configuration
When the pin is configured as an output, then it acts as an “open drain”. By applying logic 0 to a port
bit, the appropriate pin will be connected to ground (0V), and applying logic 1, the external output
will keep on “floating”.
In order to apply logic 1 (5V) on this output pin, it is necessary to build an external pullup resistor.
Port 1
P1 is a true I/O port as it doesn’t have any alternative functions as in P0, but this port can be
configured as general I/O only. It has a built-in pull-up resistor and is completely compatible with
TTL circuits.
Port 2
P2 is similar to P0 when the external memory is used. Pins of this port occupy addresses intended for
the external memory chip. This port can be used for higher address byte with addresses A8-A15.
When no memory is added then this port can be used as a general input/output port similar to Port 1.
Port 3
In this port, functions are similar to other ports except that the logic 1 must be applied to appropriate
bit of the P3 register.
Pins Current Limitations
When pins are configured as an output (i.e. logic 0), then the single port pins can receive a
current of 10mA.
When these pins are configured as inputs (i.e. logic 1), then built-in pull-up resistors provide
very weak current, but can activate up to 4 TTL inputs of LS series.
If all 8 bits of a port are active, then the total current must be limited to 15mA (port P0:
26mA).
If all ports (32 bits) are active
7 Timers / Counters
8051 has two 16-bit programmable UP timers/counters. They can be configured to operate either as timers or
as event counters. The names of the two counters are T0 and T1 respectively. The timer content is available
in four 8-bit special function registers, viz, TL0,TH0,TL1 and TH1 respectively.
In the "timer" function mode, the counter is incremented in every machine cycle. Thus, one can think of it as
counting machine cycles. Hence the clock rate is 1/12 th
of the oscillator frequency.
In the "counter" function mode, the register is incremented in response to a 1 to 0 transition at its
corresponding external input pin (T0 or T1). It requires 2 machine cycles to detect a high to low transition.
Hence maximum count rate is 1/24 th
of oscillator frequency.
The operation of the timers/counters is controlled by two special function registers, TMOD and TCON
respectively.
Timer Mode control (TMOD) Special Function Register:
Various bits of TMOD are described as follows -
Gate: This is an OR Gate enabled bit which controls the effect of on START/STOP of Timer. It is set
to one ('1') by the program to enable the interrupt to start/stop the timer. If TR1/0 in TCON is set and signal
on pin is high then the timer starts counting using either internal clock (timer mode) or external pulses
(counter mode).
It is used for the selection of Counter/Timer mode.
Mode Select Bits:
M1 and M0 are mode select bits.
Timer/ Counter control logic:
Fig .Timer/Counter Control Logic
Timer control (TCON) Special function register:
TCON is bit addressable. The address of TCON is 88H. It is partly related to Timer and partly to interrupt.
Fig TCON Register
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 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).
Interrupts are the events that temporarily suspend the main program, pass the control to the external
sources and execute their task. It then passes the control to the main program where it had left off.
8051 has 5 interrupt signals, i.e. INT0, TFO, INT1, TF1, RI/TI. Each interrupt can be enabled or
disabled by setting bits of the IE register and the whole interrupt system can be disabled by clearing
the EA bit of the same register.
IE (Interrupt Enable) Register
This register is responsible for enabling and disabling the interrupt. EA register is set to one for
enabling interrupts and set to 0 for disabling the interrupts. Its bit sequence and their meanings are
shown in the following figure.
EA IE.7 It disables all interrupts. When EA = 0 no interrupt will be
acknowledged and EA = 1 enables the interrupt individually.
- IE.6 Reserved for future use.
- IE.5 Reserved for future use.
ES IE.4 Enables/disables serial port interrupt.
ET1 IE.3 Enables/disables timer1 overflow interrupt.
EX1 IE.2 Enables/disables external interrupt1.
ET0 IE.1 Enables/disables timer0 overflow interrupt.
EX0 IE.0 Enables/disables external interrupt0.
IP (Interrupt Priority) Register
We can change the priority levels of the interrupts by changing the corresponding bit in the Interrupt
Priority (IP) register as shown in the following figure.
A low priority interrupt can only be interrupted by the high priority interrupt, but not
interrupted by another low priority interrupt.
If two interrupts of different priority levels are received simultaneously, the request of higher
priority level is served.
If the requests of the same priority levels are received simultaneously, then the internal polling
sequence determines which request is to be serviced.
- IP.6 Reserved for future use.
- IP.5 Reserved for future use.
PS IP.4 It defines the serial port interrupt priority level.
PT1 IP.3 It defines the timer interrupt of 1 priority.
PX1 IP.2 It defines the external interrupt priority level.
PT0 IP.1 It defines the timer0 interrupt priority level.
PX0 IP.0 It defines the external interrupt of 0 priority level.
SERIAL DATA COMMUNICATION IN 8051 MICROCONTROLLER
The fastest way of transmitting data, within a microcomputer is parallel data transfer.
• For transferring data over long distances, however, parallel data transmission requires too many
wires.
• For long distance transmission, data is usually converted from parallel form to serial form so that it
can be sent on a single wire or pair of wires.
• Serial data received from a distant source is converted to parallel form and it can be easily
transferred on the microcomputer buses.
• The types of communication systems are, 1. Simplex 2. Half-duplex 3. Full-duplex In simplex
communication, data can be transmitted only in one direction, ie. data from sensors to processor.
Eg : commercial radio stations. In half-duplex transmission, data can be transmitted in either direction
between two systems, but can occur only in one direction at a time.
Eg : two-way radio system, where one user always listens while the other talks because the receiver
circuitry is turned off during transmit. In full duplex, the data can be send and received at the same
time
. Eg : A normal phone conversation. Serial data can be sent by two ways.
They are, 1. Synchronous communication. 2. Asynchronous communication In synchronous
transmission, data are transmitted in block at a constant rate
SCON (serial control) register The SCON register is an 8-bit register used to program the start bit, stop bit, and data bits of data
framing, among other things.
The following describes various bits of the SCON register.
8 Unit
Assembler –
The Assembler is used to translate the program written in Assembly language into machine code. The
source program is a input of assembler that contains assembly language instructions. The output
generated by assembler is the object code or machine code understandable by the computer.
Compiler –
The language processor that reads the complete source program written in high level language as a whole in one
go and translates it into an equivalent program in machine language is called as a Compiler.
Example: C, C++, C#, Java
ASSEMBLER DIRECTIVES To assemble a program automatically the assembler needs information
in the form of assembler directives that controls the assembly. For example, the assembler must be told
at what address to start assembling the program. These assembler directives are command placed in the
program by the designer that provides information to the assembler. They do not become part of the
final program as they are not the part of the instruction set of the microprocessor nor did they translate
into executable code. Therefore, they are also known as pseudo-instruction on false instructions.
ORG: The origin (ORG) instruction tells the assembler the address of the memory location for the next
instruction or data byte should be assembled. ORG is entered at the beginning of a program. When
different parts of a programme (e.g. subroutines) are to be placed in different areas of memory, an
ORG pseudo instruction is used before each part of the program to specify the starting location for
assembly of that part of the program. The origin instruction has the following form
END: When an assembler scans the program to be assembled it must know, where the program ends. It
cannot depend on a HLT instruction for this because some programmes don’t contain a halt instruction
as the last instruction and other don’t contain a halt at all. An application program used, e.g., in process
monitoring on control might run continuously and, therefore, not contain a halt instruction. Thus, an
end assembly, END directive must be the last instruction. The directive has a form. END
The END statement explicitly indicates the end of the program to the assembler. If no END statement
is given, then the assembler just keeps on running through all the memory.
The ORG and END assembler directives, in effect, frame the program to be assembled. ORG 0000H
[Assembly language instructions] END
EQU: Symbolic names, which appear in assembly language programs as labels, instructions
mnemonics and operands are translated to binary values by the assembler. As discussed in
handassembly the labels are assigned the current value of the assembler’s location counter when
encountered in the first pass of the assembly. Instruction mnemonics have predefined values that the
assembler obtains from a table that is part of the assembler.
DB: When a table of fixed data values is required, memory must also be allocated. However, unlike
the DS, each memory locations must have a defined value that is assembled into it.
DW: Define word DW instruction is similar to define byte pseudo instruction. opt. name: DW list The
only difference between the DB & DW is that expression in this define word list is evaluated to 16-bit
quantity and stored as 2-bytes. It is stored with the lower order byte in the lower of the two memory
locations and the higher order byte in the next higher location
Light Emitting Diodes or LEDs are the mostly commonly used components in many applications.
They are made of semiconducting material. In this project, I will describe about basics of Interfacing
LED with 8051 Microcontroller.
Principle behind Interfacing LED with 8051
The main principle of this circuit is to interface LEDs to the 8051 family micro controller. Commonly,
used LEDs will have voltage drop of 1.7v and current of 10mA to glow at full intensity. This is applied
through the output pin of the micro controller.
Circuit Diagram
NOTE: I suggest you to connect 1KΩ Pull-up resistors to all the pins of PORT0 of 8051. I haven’t
shown that connection in this circuit diagram
Components Required
AT89C51 (8051 Microcontroller)
8 LEDs
8 Resistors – 1KΩ
Crystal oscillator – 11.0592MHz
2 Capacitors – 33pF
2 Resistors – 10KΩ
1 Capacitor – 10μF
1 Push Button
8051 Programmer
5V Power Supply
Circuit Design
The circuit mainly consists of AT89C51 microcontroller. AT89C51 belongs to the family of 8051
microcontroller. It is an 8-bit microcontroller. This microcontroller has 4KB of Flash Programmable
and Erasable Read Only Memory and 128 bytes of RAM. This can be programmed and erased a
maximum of 1000 times.
It has two 16 bit timers/counters. It supports USART communication protocol. It has 40 pins. There are
four ports are designated as P0, P1, P2, and P3. Port P0 will not have internal pull- ups, while the other
ports have internal pull-ups.
Microcontroller Questions
Question1. Introduction of 8051 Microcontroller Architecture? Answer : In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051. The 8051 became
widely popular after Intel allowed other manufacturers to make and market any flavors of the 8051.
They please with the condition that they remain code-compatible with the 8051. This has led to many,
versions of the 8051 with different speeds and amounts of on-chip ROM marketed by more than half a
dozen manufacturers. It is important to note that although there are different flavors of the 8051 in
terms of speed and amount of on-chip ROM, they are all compatible with the original 8051 as far as
the instructions are concerned. This means that if you write your program for one, it will run on any of
them regardless of the manufacturer.
Question 2. Intel 8051 Follows Which Architecture?
Answer :
Intel 8051 is Harvard Architecture.
Question 3. What Is The Difference Between Harvard Architecture And Von Neumann
Architecture?
Answer : The name Harvard Architecture comes from the Harvard Mark. The most obvious characteristic of
the Harvard Architecture is that it has physically separate signals and storage for code and data
memory. It is possible to access program memory and data memory simultaneously. Typically, code
(or program) memory is read-only and data memory is read-write. Therefore, it is impossible for
program contents to be modified by the program itself.
The von Neumann Architecture is named after the mathematician and early computer scientist John
von Neumann. Von Neumann machines have shared signals and memory for code and data. Thus,
the program can be easily modified by itself since it is stored in read-write memory.
Question 4. 8051 Was Developed Using Which Technology?
Answer : Intel’s original MCS-51 family was developed using NMOS technology, but later versions,
identified by a letter C in their name (e.g., 80C51) used CMOS technology and consume less power
than their NMOS predecessors. This made them more suitable for battery-powered devices.
Question 5. Why 8051 Is Called 8 Bit Microcontroller?
Answer : The Intel 8051 is an 8-bit microcontroller which means that most available operations are limited to
8 bits.
Question 6. What Is The Width Of Data Bus?
Answer :
8-bit data bus
Question 7. What Is The Width Of Address Bus?
Answer :
16-bit address bus
Question 8. List Out The Features Of 8051 Microcontroller?
Answer : o 40 Pin IC.
o 128 bytes of RAM.
o 4K ROM.
o 2 Timers (Timer 0 and Timer 1).
o 32 Input/ Output pins.
o 1 serial port.
o 6 Interrupts (Including Reset).
Question 9. What Location Code Memory Space And Data Memory Space Begins?
Answer :
At location 0x00 for internal or external memory
Question 10. How Much On Chip Ram Is Available?
Answer :
128 bytes of RAM (from 0x00 to 0x7F) and can be used to store data.
Question 11. List out Addressing Modes In Mcs-51?
Answer : o Direct Addressing
o Register Addressing
o Register Indirect Addressing
o Implicit Addressing
o Immediate Addressing
o Index Addressing