Sie sind auf Seite 1von 62

1

CHAPTER-1
COMPANY PROFILE

COMPANY PROFILE
Sofcon India Pvt. Ltd (ISO 9001-2008 & IAO-International Accreditation Organization
accredited Company) imparts practical Training to Fresh Engineers / Working Professionals /
Technicians on:
Embedded Systems : 8051, PIC, AVR Micro Controllers , ARM, RTOS

PLC : Allen Bradley, Siemens, Modicon, Mitsubishi, GE Fanuc, Omron...

SCADA/HMI : Wonderware, RS View, Win CC, Intellution, Panel View

Variable Frequency Drives : Power Flux, Altivar, Danfoss, ABB, Siemens

Motion Control, Stepper/Servo Drives

DCS: ABB AC 700F, Hollysys SM 202

Process Instrumentation, Panel Designing &AutoCad

Industrial Networking/Wireless Technology (Ethernet, ControlNet, DeviceNet,


Modbus, Profibus, Fieldbus)

Integrated Building Management System, Building Automation, Fire Alarms, Access


control, CCTV Surveillance, Gas suppression, Public Address system

Electrical Systems

Summer / Winter / Project Training with project Guidance for II/III/Final year
Engineering/Diploma Students

Customized Training for Working Professionals / Plants / Industries.

Soft skill development & Interview Preparation


SOFCON is professionally run by technocrats having decades of experience in Training /
process / manufacturing industries. Our rich experience of over 02 decades in providing
automation solutions to Indian & overseas industries has made us a leading training
Service Provider.

RESOURCES:
Qualified & Dedicated Training Staff
Specialized Consultants & Expert Advisors from Industry & Reputed Institutes
Team for In-house Research & Development
Placement cell for industry-academic interaction

CHAPTER -2

Introduction To Embedded System

Microcontroller are widely used in Embedded System products . An Embedded


product uses the microprocessor(or microcontroller) to do one task & one task
only. A printer is an example of Embedded system since the processor inside it
perform one task only namely getting the data and printing it. Although
microcontroller are preferred choice for many Embedded systems, There are times
that a microcontroller is inadequate for the task. For this reason in recent years
many manufactures of general purpose microprocessors such as INTEL, Motorolla,
AMD & Cyrix have targeted their microprocessors for the high end of Embedded
market.One of the most critical needs of the embedded system is to decrease power
consumptions and space. This can be achieved by integrating more functions into
the CPU chips. All the embedded processors have low power consumptions in
additions to some forms of I/O,ROM all on a single chip. In higher performance
Embedded system the trend is to integrate more & more function on the CPU chip
& let the designer decide which feature he/she wants to use.

2.1

Embedded System

An Embedded System employs a combination of hardware & software to perform


a specific function. Software is used for providing features and flexibility
hardware(Processors, Memory...) is used for performance & sometimes security.An
embedded system is a special purpose system in which the computer is completely
encapsulated by the device it controls. Unlike a general purpose computer, such as
a PC, an embedded system performs predefined tasks usually with very specific
tasks design engineers can optimize it reducing the size and cost of the product.
Embedded systems are often mass produced, so the cost savings may be multiplied

by millions of items.The core of any embedded system is formed by one or several


microprocessor or micro controller programmed to perform a small number of
tasks. In contrast to a general purpose computer, which can run any software
application, the user chooses, the software on an embedded system is semipermanent, so it is often called firmware.

2.2Examples of Embedded System


1. Automated tiller machines (ATMS).
2. Integrated system in aircraft and missile.
3.Cellular telephones and telephonic switches.
4. Computer network equipment, including routers timeservers and firewalls
5. Computer printers, Copiers.
6. Disk drives (floppy disk drive and hard disk drive)
7. Engine controllers and antilock brake controllers for automobiles.
8. Home automation products like thermostat, air conditioners sprinkles and
security monitoring system.
9. House hold appliances including microwave ovens, washing machines, TV sets
DVD players/recorders.
10. Medical equipment.
11. Measurement equipment such as digital storage oscilloscopes, logic analyzers
and spectrum analyzers.
12. Multimedia appliances: internet radio receivers, TV set top boxes.
13. Small hand held computer with P1M5 and other applications.
14. Programmable logic controllers (PLCs) for industrial automation and
monitoring.
15. Stationary video game controllers.

2.3

Microprocessor (MPU)

A microprocessor is a general-purpose digital computer central processing


unit(CPU). Although popularly known as a computer on a chip is in no sense a
complete digital computer. The block diagram of a microprocessor CPU is shown,
which contains an arithmetic and logical unit (ALU), a program counter (PC), a
stack pointer (SP),some working registers, a clock timing circuit, and interrupt
circuits.
CPU
GeneralMICR
OCONTROL
LERS
(MCU)Purpose

RAM

ROM

I/O Port

Timer

Figure1.1:Block Diagram Of a Microprocessor

2.4

Microcontroller (MCU)

Serial
COM
Port

Figure shows the block diagram of a typical microcontroller. The design


incorporates all of the features found in micro-processor CPU: ALU, PC, SP, and
registers. It also added the other features needed to make a complete computer:
ROM, RAM, parallel I/O, serial I/O, counters, and clock circuit.

Figure1.2:Block Diagram Of a Microcontroller

2.5

Comparision Between Microprocessor And Microcontroller

The microprocessor must have many additional parts to be operational as a


computer whereas microcontroller requires no additional external digital parts.
1. The prime use of microprocessor is to read data, perform extensive calculations
on that data and store them in the mass storage device or display it. The prime
functions of microcontroller is to read data, perform limited calculations on it,
control its environment based on these data. Thus the microprocessor is said to be
general-purpose digital computers whereas the microcontroller are intend to be
special purpose digital controller.
2. Microprocessor need many opcodes for moving data from the external memory
to the CPU, microcontroller may require just one or two, also microprocessor may
have one or two types of bit handling instructions whereas microcontrollers have
many.
3. Thus microprocessor is concerned with the rapid movement of the code and data
from the external addresses to the chip, microcontroller is concerned with the rapid
movement of the bits within the chip.
4. Lastly, the microprocessor design accomplishes the goal of flexibility in the
hardware configuration by enabling large amounts of memory and I/O that could
be connected to the address and data pins on the IC package. The microcontroller
design uses much more limited.

10

2.6 Need Of Embedded System


An embedded system is a special-purpose computer system designed to perform
one or a few
dedicated functions, often with real-time computing constraints. It
is usually embedded as part of a
complete device including hardware and
mechanical parts. In contrast, a general-purpose computer,
such as a personal
computer, can do many different tasks depending on programming. Embedded
systems control many of the common devices in use today.
Since the embedded system is dedicated to specific tasks, design engineers can
optimize it, reducing the size and cost of the product, or increasing the reliability
and performance. Some embedded systems are mass-produced, benefiting from
economies of scale.
Physically embedded systems range from portable devices such as digital watches
and MP4 players, to large stationary installations like traffic lights, factory
controllers, or the systems controlling nuclear power plants. Complexity varies
from low, with a single micro controller chip, to very high with multiple units,
peripherals and networks mounted inside a large chassis or enclosure.
In general, "embedded system" is not an exactly defined term, as many systems
have some element of programmability. For example, Handheld computers share
some elements with embedded systems - such as the operating systems and
microprocessors which power them - but are not truly embedded systems, because
they allow different applications to be loaded and peripherals to be connected.
From several examples listed earlier these Systems are extremely common in the
home, vehicle and the workplace.
At Home: Washing Machines, dishwashers, ovens, central heating system,
burglars alarms, etc.
In Motor Vehicle: Engine management, security (locking or antitheft
devices), air conditioning, brakes, radio etc.
In Industry & Commerce: Machine control, factory automation, robotics,

11

2.7 Components of an Embedded System


An embedded system has three main components:
Hardware
Software
Time operating system

1 Hardware

Power Supply
Processor
Memory (RAM, ROM)
Timers
Serial communication ports
Input/output circuits
System application specific circuits

2 Software:

12

The application software is required to perform the series of tasks.An embedded s


ystem has software designed to keep in view of three constraints:
Availability of System Memory
Availability of processor speed
The need to limit power dissipation when running the system continuously in

Cycles of wait for events, run, stop and wake up

3 Real Time Operating System: (RTOS)


It supervises the application software and it provides a mechanism to let a
computer run a process as per scheduling and do the switching from one process
(task) to another.

Block Diagram of Embedded Systems:

13

Embedded systems are executed by a microcontroller, which communicates with


the sensors and actuators. It means that a user of an embedded system is not able to
change the functionality of the system through modifying or replacing the software
because it is kept in ROM.
basic components used in Embedded System are as follows:
Microcontroller: It monitors and controls the environment.
Sensors: It collects data from environment through input devices.
Actuators: It displays the system's status through output devices.
Timer: It provides response within a certain time frame.

2.8 Characteristics of Embedded System


Some of important Characteristics of embedded system are:
1) Embedded Systems are designed to do some specific task i.e., it is not a general
Purpose kind of a system.
2) Software for Embedded Systems is stored in ROM or flash memory.
3) Knowledge about behaviour at design time can be used to minimize resources
and to maximize robustness.

14

2.9 Programming Language of Embedded System


In embedded systems there are mainly two types of programming languages
are used
Assembly Language
Embedded C

Assembly Language:
An assembly language is a list of processor instructions written in a symbolic,
human-readable form. Each instruction consists of an operation such as addition
along with some operands. E.g., add r5, r2, r4 might add the contents of registers r2
and r4 and write the result to r5. Such arithmetic instructions are executed in order,
but branch instructions can perform conditionals and loops by changing the
processors program counter the address of the instruction being executed.
A processors assembly language is denes by its Opcodes, addressing modes,
registers, and memories. The Opcode distinguishes, say, addition from conditional
branch, and an addressing mode denes how and where data is gathered and stored
(e.g., from a register or from a particular Memory location). Registers can be
thought of as small, fast, easy-to-access pieces of memory.
Embedded C:
A C program contains functions built from arithmetic expressions structured with
loops and conditionals.
Instructions in a C program run sequentially, but control ow constructs such as
loops of conditionals can affect the order in which instructions execute. When
control reaches a function call in an expression, control is passed to the called
function, which runs until it produces a result, and control returns to continue
evaluating the expression that called the function. C derives its types from those a

15

processor manipulates directly: signed and unsigned integers ranging from bytes to
words, oating point numbers, and pointers. These can be further aggregated into
arrays and structuresgroups of named elds.

16

CHAPTER - 3

17

BASIC ELECTRONICS COMPONENTS

18

The basic electronics components are as follows:

Resistor
Capacitor
Diodes
Transistor
Basic ICs
Bread boarding of circuits

3.1 Resistor
Two-terminal non-polarized electronic component Limits or regulates the flow of
electrical current in an electronic circuit Resistors can also be used to provide a
specific voltage for an active device such as a transistor
Resistors restrict the flow of electric current, for example a resistor is placed in
series with a light-emitting diode (LED) to limit the current passing through the
LED. Connecting and soldering Resistors may be connected either way round.
They are not damaged by heat when soldering.
Resistor values - the resistor colour code
Resistance is measured in ohms; the symbol for ohm is an omega. 1 is quite small
so resistor values are often given in k and M. 1 k = 1000 1 M = 1000000.
Resistor values are normally shown using colored bands. Each colour represents a
number as shown in the table.
Most resistors have 4 bands:
The first band gives the first digit.

19

The
second band
gives
the
second
digit.
The third band indicates the number zeros.
The fourth
the tolerance
resistor, this
almost all
details are

band is used to shows


(precision)
of
the
may be ignored for
circuits but further
given below.

20

3.2 Capacitor
Capacitive filters are used stabilized or perfect regulation of the voltage. The
capacitive filters are opted because, they are more efficient. But they are also more
costly.
Different types of capacitors are:
1. Ceramic capacitors.
2. Electrolyte capacitors.
3. Paper/Mica capacitors.
4. Silver capacitors.

Fig. Capacitor Symbol

5. Tantalum capacitors.
Ceramic, Paper/Mica, Silver are non polarized capacitors. Electrolyte and
Tantalum are polarized capacitors. For high frequency, Ceramic capacitors are
used. For low frequencies, Electrolyte capacitors are used.

21

Polarized Capacitor

Non-polarized Capacitor

Polarized Capacitor (Electrolytic capacitor)


Electrolytic capacitor are Polarized and they must be connected the
correct way round, at least one of their leads will be marked + or -. They
are not damaged by heat when soldering. There are two designs of
electrolytic capacitors; axial where the leads are attached to each end
(220F in picture) and radial where both leads are at the same end (10F in
picture). Radial capacitors tend to be a little smaller and they stand upright
on the circuit board. It is easy to find the value of electrolytic capacitors
because they are clearly printed with their capacitance and voltage rating.
The voltage rating can be quite low (6V for example) and it should always
be checked when selecting an electrolytic capacitor. If the project parts list
does not specify a voltage, choose a capacitor with a rating which is greater
than the project's power supply voltage. 25V is a sensible minimum for most
battery circuits.
Tantalum Bead Capacitors
Tantalum bead capacitors are polarised and have low voltage ratings like
electrolytic capacitors. They are expensive but very small, so they are used
where a large capacitance is needed in a small size. 55
Modern tantalum bead capacitors are printed with their capacitance, voltage
and polarity in full. However older ones use a colour-code system which has
two stripes (for the two digits) and a spot of colour for the number of zeros
to give the value in F. The standard colour code is used, but for the spot,
grey is used to mean 0.01 and white means 0.1 so that values of less
than 10F can be shown. A third colour stripe near the leads shows the
voltage (yellow 6.3V, black 10V, green 16V, blue 20V, grey 25V, white 30V,

22

pink 35V). The positive (+) lead is to the


spot is facing you: 'when the spot is in
positive is to the

right when the


sight,
the

Unpolarised capacitors (small values, up to 1F)

Fig. un polarized
Capacitor
Small value capacitors are un polarised and may be connected either way round.
They are not damaged by heat when soldering, except for one unusual type
(polystyrene). They have high voltage ratings of at least 50V, usually 250V or so. It
can be difficult to find the values of these small capacitors because there are many
types of them and several different labeling systems
Many small value capacitors have their value printed but without a multiplier, so
you need to use experience to work out what the multiplier should be!
For example 0.1 means 0.1F = 100nF. Sometimes the multiplier is used in place
of the decimal point: For example: 4n7 means 4.7nF.
Capacitor Number Code:
A number code is often
used on small capacitors
where printing is
difficult:

23

the 1st number is the 1st digit,


the 2nd number is the 2nd digit,
the 3rd number is the number of zeros to give the
capacitance in pF.
Ignore any letters - they just indicate tolerance and voltage rating.

For example: 102 means 1000pF = 1nF (not 102pF!) For example: 472J
means 4700pF = 4.7nF (J means 5%

3.3 Diodes
Diode is an electronic component which permits the flow of current in one
direction only. Diodes are made up of semiconductor material; therefore they are
often called semiconductor diodes or crystal diodes
Types of diodes
1

PN junction diode: - Made by P-type & N-type material. Works in

forward bias.

24

2 Zener Diode :- Works in reverse bias. Black band which is negative

Light Emitting Diodes (LED): Operates in forward bias.

Photo Diode :- Reverse biased.

3.4 Transistor

25

A transistor is
a semiconductor device used
to amplify and switch electronic signals and electrical power. It is composed
of semiconductor material with at least three terminals for connection to an
external circuit. A voltage or current applied to one pair of the transistor's terminals
changes the current through another pair of terminals. Because the controlled
(output) power can be higher than the controlling (input) power, a transistor
can amplify a signal. Today, some transistors are packaged individually, but many
more are found embedded in integrated circuits.

It
is
a
Semiconductor device used
to
amplify
and
switch electronic signals.Transistor is three terminals for connection to an external
circuit. One terminal can be use to control the flow of current through the other
two terminals.The three terminals are Emitter, Base and Collector
Types of Transistor
n-p-n transistors :-A straight switch

p-n-p transistors:- A inverted switch

26

3.5 Basic ICs


There following ICs are the basic ICs, performs several application.
L293D
555
LM358
IC 7805(voltage controlled)

L293D:
L293D is a dual H-Bridge motor driver.
With one IC we can interface two DC motors which can be controlled in
both clockwise and counter clockwise direction

If you have motor with fix direction of motion then you can make use of all
the four I/Os to connect up to four DC motors.

L293D has output current of 600mA.

Moreover for protection of circuit from back EMF output diodes are included
within the IC.

27

Interface Motor with L239D

VCC

555 IC

The 555 Timer IC is an integrated circuit (chip) used in a timer application,


pulse generation and oscillator applications.
It works only on falling edge of the incoming signal
Operating modes of 555 IC

28

It has three operating modes:


1) Monostable
2) Bistable
3) Astable
Monostable Mode
In this mode, the IC has only one stable state. In the monostable mode, the 555
timer acts as a "one-shot" pulse generator. The pulse begins when the 555 timer
receives a signal at the trigger input that falls below a third of the voltage supply.

Bistable Mode
In this mode, the IC has two stable states. In Bistable mode, the 555 timer acts as a
basic flip-flop. The trigger and reset inputs (pins 2 and 4 respectively on a 555) are
held high via Pull-up resistors while the threshold input (pin 6) is simply grounded.
Thus configured, pulling the trigger momentarily to ground acts as a 'set' and
transitions the output pin (pin 3) to Vcc (high state). Pulling the reset input to
ground acts as a 'reset' and transitions the output pin to ground (low state).

29

Astable Mode
In this mode, the IC not having a single stable state. Astable mode, the 555 timer
puts out a continuous stream of rectangular pulses having a specified frequency.
Resistor R1 is connected between VCC and the discharge pin (pin 7) and another
resistor (R2) is connected between the discharge pin (pin 7), and the trigger (pin 2)
and threshold (pin 6) pins that share a common node. Hence the capacitor is
charged through R1 and R2, and discharged only through R2, since pin 7 has low
impedance to ground during output low intervals of the cycle, therefore
discharging the capacitor

LM358 IC

30

The LM358 is a great, easy-to-use dual-channel operational amplifier. Opamps


have so many applications we figured we should probably carry at least one in
a DIP package. LM358 applications include transducer amplifiers, DC gain blocks
and all the conventional opamp circuits. If you're looking for a good, standard
opamp the LM358 should fill most of your needs. It can handle a supply of 332VDC and source up to 20mA per channel. This opamp is great if you need to
operate two individual opamps from a single power supply Comes in an 8-pin DIP
package.
Features:
Two internally compensated op-amps
Internally frequency compensated for unity gain
Large DC voltage gain: 100 dB
Wide bandwidth (unity gain): 1 MHz (temperature compensated)
Wide power supply range:
Single supply: 3V to 32V
or dual supplies: 1.5V to 16V
It have two op-amp
Eliminate need of dual supply

IC 7805
The 78xx (sometimes LM78xx) is a family of self-contained fixed linear voltage
regulator integrated circuits. The 78xx family is commonly used in electronic
circuits requiring a regulated power supply due to their ease-of-use and low cost.
For ICs within the family, the xx is replaced with two digits, indicating the
output voltage (for example, the 7805 has a 5 volt output, while the 7812 produces

31

12 volts). The 78xx line is positive voltage regulators: they produce a voltage that
is positive relative to a common ground. There is a related line of 79xx devices
which are complementary negative voltage regulators. 78xx and 79xx ICs can be
used in combination to provide positive and negative supply voltages in the same
circuit.

3.6 Bread boarding of circuits


A breadboard is used to make up temporary circuits for testing or to try out
an idea

No soldering is required so it is easy to change connections and replace


components. Parts will not be damaged so they will be available to re-use
afterwards

Almost all the Electronics Club projects started life on a breadboard to check
that the circuit worked as intended
Internals connection of breadboard
The top and bottom rows are linked horizontally(up to consecutive 25
holes) all the way across as shown by the
red and black lines on the
diagram

The other holes are linked vertically in blocks of 5 with no link across the
centre as shown by the blue lines on the diagram
Connections on Breadboard

Breadboards have many tiny sockets (called 'holes') arranged on a 0.1" grid.
The leads of most components can be pushed straight into the holes

ICs are inserted


across the central gap with their

32

notch or dot to the left. Wire links can be made with single-core plasticcoated wire of 0.6mm diameter (the standard size)

Stranded wire is not suitable because it will crumple when pushed into a
hole and it may damage the board if strands break off
Breadboard implementation of some circuits:-

Fig.: NOT GATE

Fig.: Monostable Mode

Fig.: AND Gate

Fig.: Astable Mode

Fig.: OR Gate

Fig. Bistable Mode

33
Fig.: Light Sensor

34

CHAPTER - 4
8051 ARCHITECTURE

35

4.1 About the 8051


The Intel 8051 is an 8-bit microcontroller which means that most available
operations are limited to 8 bits. There are 3 basic "sizes" of the 8051: Short,
Standard, and Extended. The Short and Standard chips are often available in DIP
(dual in-line package) form, but the Extended 8051 models often have a different
form factor, and are not "drop-in compatible".
4.2 Block Diagram

Figure 2.1:Block Diagram of 8051


All these things are called 8051 because they can all be programmed using 8051
assembly language, and they all share certain features (although the different
models all have their own special features).Some of the features that have made the
8051 popular are:

36

4 KB on chip program memory.


128 bytes on chip data memory(RAM).
4 register banks.
8-bit data bus
16-bit address bus
32 general purpose registers each of 8 bits
16 bit timers (usually 2, but may have more, or less).
3 internal and 2 external interrupts.
Bit as well as byte addressable RAM area of 16 bytes.
Four 8-bit ports, (short models have two 8-bit ports).
16-bit program counter and data pointer.
1 Microsecond instruction cycle with 12 MHz Crystal.
8051 models may also have a number of special, model-specific features,
such as UARTs, ADC, OpAmps, etc...
4.3 Typical applications
8051 chips are used in a wide variety of control systems, telecom applications, and
robotics as well as in the automotive industry. By some estimation, 8051 family
chips make up over 50% of the embedded chip market.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. The following are the main areas of focus:

37

1. Energy Management :- Efficient metering systems help in controlling energy


usage in homes and industrial applications. These metering systems are made
capable by incorporating microcontrollers.
2. Touch screens :- A high number of microcontroller providers incorporate touchsensing capabilities in their designs. Portable electronics such as cell phones,
media players and gaming devices are examples of microcontroller-based touch
screens.
3. Automobiles :- The 8051 finds wide acceptance in providing automobile
solutions. They are widely used in hybrid vehicles to manage engine variants.
Additionally, functions such as cruise control and anti-brake system have been
made more efficient with the use of microcontrollers. So the microcontroller 8051
has great advantage in the field of the automobiles.
4. 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.
4.4 Pinout Description
Pin 1-8(Port 1) : - Each of these pins can be configured as an input or an output.
Pin 9(RST) :- A logic one on this pin disables the microcontroller and clears the
contents ofmost registers. In other words, the positive voltage on this pin resets the
microcontroller. By

38

Figure 2.2:Pin diagram of the 8051 DIP

applying logic zero to this pin, the program starts execution from the beginning.
Pin 9 is the RESET pin. It is an input and is active high. Upon applying a high
pulse to this pin the microcontroller well reset and terminate all activities. This is
often referred to as a power on reset .Activating a power on reset will cause all
values the registers to be lost. It will set program counter to all 0s.In order for the
RESET input to be effective it must have a minimum duration of two machine
cycles. In other words the high pulse must be high for a minimum of two machine
cycles before it is allowed to go low.
Pin 10-17(Port 3) :- Similar to port 1, each of these pins can serve as general input
or output. Besides, all of them have alternative functions:
Pin 10(RXD) :- Serial asynchronous communication input or Serial synchronous
communication output.
Pin 11(TXD) :- Serial asynchronous communication output or Serial synchronous
communication clock output.

39

Pin 12(INT0):Interrupt 0 input.


Pin 13(INT1):Interrupt 1 input.
Pin 14(T0):Counter 0 clock input.
Pin 15(T1):Counter 1 clock input.
Pin 16(WR):Write to external (additional) RAM.
Pin 17(RD):Read from external RAM.
Pin 18, 19(X2,X1):Internal oscillator input and output. The 8051 has an on chip
oscillator but
requires an external clock to run it. Most often a quartz crystal oscillator is
connected to inputs XTAL1 (pin 19) and XTAL2 (pin 18). The quartz crystal
oscillator connected to XTAL1 and XTAL2 also needs two capacitors of 30 pf
value. One side of each capacitor is connected to the ground. Speed refers to the
maximum oscillator frequency connected to XTAL

Figure2.3:Oscillator Circuit and Timing

Pin 20(GND) :- Ground.


Pin 21-28(Port 2) :- If there is no intention to use external memory then these port
pins are configured as general inputs/outputs. In case external memory is used, the
higher address byte, i.e. addresses A8-A15 will appear on this port. Even though

40

memory with capacity of 64Kb is not used, which means that not all eight port bits
are used for its addressing, the rest of them are not available as inputs/outputs.
Pin 29(PSEN) :- This is an output pin. PSEN stands for program store enable. If
external ROM is used for storing program then a logic zero (0) appears on it every
time the microcontroller reads a byte from memory.
Pin 30(ALE) :- ALE stands for address latch enable. It is an output pin and is
active high. When connecting an 8031 to external memory, port 0 provides both
address and data. In other words the 8031 multiplexes address and data through
port 0 to save pins. The ALE pin is used for de-multiplexing the address and data.
Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0. In other words, this port is used for both data and address
transmission.
Pin 31(EA) :- EA which stands for external access is pin number 31 in the DIP
packages. It is an input pin and must be connected to either Vcc or GND. In other
words it cannot be unconnected. By applying logic zero to this pin, P2 and P3 are
used for data and address transmission with no regard to whether there is internal
memory or not. It means that even there is a program written to the
microcontroller, it will not be executed. Instead, the program
writtento external ROM will be executed. By applying logic one to the EA pin, the
microcontroller will use both memories, first internal then external (if exists).
Pin 32-39(Port 0) :- Similar to P2, if external memory is not used, these pins can
be used as general inputs/outputs. Otherwise, P0 is configured as address output
(A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when
the ALE pin is driven low (0).
Pin 40(Vcc) :- +5V power supply.
2.5PORTS 0,1,2,3:

41

All the ports upon RESET are configured as input, since P0-P3 have value FFH on
them. The following is a summary of features of P0-P3.
PORT 0:
Port 0 is also designated as AD0-AD7 allowing it to be used for both address and
data. When connecting an 8051/31 to an external memory, port 0 provides both
address and data. The 8051 multiplexes address and data through port 0 to save
pins. ALE indicates if p0 has address A0-A7.in the 8051 based systems where there
is no external memory connection the pins of P0 must be connected externally to
10k-ohm pull-up resistor. This is due to the fact that P0 is an open drain, unlike P1,
P2 and P3. Open drain is a term used for MOS chips in the same way that open
collector is used for TTL chips. In many systems using the 8751, 89c51 or
DS89c4*0 chips we normally connect P0 to pull up resistors.
PORT 1, PORT 2:
In 8051 based systems with no external memory connection both P1 and P2 are
used as simple I/O. however in 8031/51 based systems with external memory
connections P2 must be used along with P0 to provide the 16-bit address for the
external memory. P2 is also designated as A8-A15 indicating its dual function.
Since an 8031/51 is capable of accessing 64k bytes of external memory it needs a
path for the 16 bits of address. While P0 provides the lower 8 bits via A0-a7 it is
the job P2 to provide bits A8-A15 of the address. In other words when the 8031/51
is connected to external memory P2 is used for the upper 8 bits of the 16 bit
address and it cannot be used for I/O.
PORT 3:
Port 3 occupies a total of 8 pins 10 through 17. It can be used as input or output. P3
does not need any pull-up resistors the same as P1 and P2 did not. Although port 3
is configured as input port upon reset this is not the way it is most commonly used.

42

Port 3 has the additional function of providing some extremely important signals
such as interrupts.
P3 BitFunction

Pin
P3.0

RXD

10

P3.1

TXD

11

P3.2

INT0

12

P3.3

INT1

13

P3.4

T0

14

P3.5

T1

15

P3.6

WR

16

P3.7

RD

17

43

CHAPTER - 5
EMBEDDED C PROGRAMING

44

What is Embedded C? The use of C language to program microcontrollers is


becoming too common. And most of the time its not easy to build an application
in assembly which instead you can make easily in C.So its important that you
know C language for microcontroller which is commonly known as Embedded C.
As we are going to use AVR studio 4Compiler.

5.1 Data Types


A good understanding of C data types for 8051 can help programmers to create
smaller hex files

unsigned char

signed char

unsigned int

signed int

sbit (single bit)

bit and sfr

The character data type is the most natural choice AVR is an 8-bit
microcontroller

Unsigned char is an 8-bit data type in the range of 0 255 (00 FFH) One
of the most widely used data types for the AVR- Counter value - ASCII
characters

C compilers use the signed char as the default if we do not put the keyword
unsigned

5.2 Input / Output Operation


Points to Remember

45

The 8-bit I/O ports PORTB, PORTC, PORTD each uses 8 pins except
PORTC uses 7 pins.

All the ports upon RESET are configured as input, ready to be used as input
ports

When the first 1is written to a port, it becomes an output.

To reconfigure it as an input, a 0 must be sent to the port.

To use any of these ports as an input port, it must be programmed.

DATA TYPES
Type

Typical Size in Bits

Minimal Range

char

-127 to 127

unsigned char

0 to 255

signed char

-127 to 127

int

16 or 32

-32767 to 32767

unsigned int

16 or 32

0 to 65535

signed int

16 or 32

Same as int

short int

16

-32767 to 32767

unsigned short int

16

0 to 65535

signed short int

16

Same as short int

long int

32

2,147,483,647
2,147,483,647

signed long int

32

same as long int

unsigned long int

32

0 to 4,294,967,295

float

32

Six digits of precision

double

64

Ten digits of precision

to

46

long double

80

Ten digits of precision

5.3 Operators used in C


Operator type: The assignment operator =
Arithmetic operators , +, *, /, %
Increment and decrement ++ ,
Relational operators >, >= , < , <= , = =, !=
Logical operators && , || , !
Bitwise operators &, |, ^ , ~, >>, <<

5.4 CONDITIONAL STATEMENT


A conditional expression determines what course of action is to be taken. A
conditional expression evaluates to either a true or false value.
C supports two types of selection statements: if and switch. The general
form of the if statement is
if (expression)
statement;
else

47

statement;
Where a statement may consist of a single statement, a block of statements. The
else clause is optional.
Switch-case
C has a built-in multiple-branch selection statement, called switch, which
successively tests the value of an expression against a list of integer or character
constants.
switch (expression)
{
case constant1:
statement sequence
break;
.
default:
statement sequence }
The default statement is executed if no matches are found.

5.5 LOOPS
For loop
The general form of the for statement is
for(initialization; condition; updation)
Statement;
The for loop continues to execute as long as the condition is true. Once the
condition becomes false, program execution resumes on the Statement following
the for.

48

The while loop


The second loop available in C/C++ is the while loop.
while (condition)
Statement;
The condition may be any expression, and true is any nonzero value. When the
condition becomes false, program control passes to the line of code immediately
following the loop.
do- while statement
Syntax:
Initial counter
do
{
statement.
update statement
}while(condition);

5.6 FUNCTIONS
Functions are the blocks in which we define the steps that how the program will
work. The general form of a function is:
Return -type function-name (parameter list)
{
body of the function
}
The return-type specifies the type of data that the function returns. The parameter
list is a comma-separated list of variable names.Need of Functions-Functions is
used so that we dont have to write the code repeatedly over and over again. If a
task is required to be done frequently then we can write this task code in a function
and call this function whenever needed.

49

How to create Functions


STEP 1 is to decide a name for function.
Step 2 is to declare the function at the top of the C file.
The declaration only consists the functions return type, its name and the type of
parameters it accepts.
Return-type function-name (parameter type)
STEP 3 is to define what a function will do i.e. its definition.
The function is generally defined in the end of the main function.

50

CHAPTER - 5

Interfacing

51

6.1 LED interfacing


Like a normal diode, an LED consists of a chip of semiconducting material
impregnated, or doped, with impurities to create a p-n junction. As in other diodes,
current flows easily from the p-side, or anode, to the n-side, or cathode, but not in
the reverse direction. Charge-carrierselectrons and holesflow into the junction
from electrodes with different voltages. When an electron meets a hole, it falls into
a lower energy level, and releases energy in the form of a photon. The wavelength
of the light emitted, and therefore its color, depends on the band gap energy of the
materials forming the p-n junction. In silicon or germanium diodes, the electrons
and holes recombine by a non-radiativetransition which produces no optical
emission, because these are indirect band gap materials. The materials used for an
LED have a direct band gap with energies corresponding to near-infrared, visible or
near-ultraviolet light. LED development began with infrared and red devices made
with gallium arsenide. Advances in materials science have made possible the
production of devices with ever-shorter wavelengths, producing light in a variety
ofcolors.Conventional LEDs are made from a variety of inorganic semiconductor
materials, producing the following colors:
Aluminium gallium arsenide (AlGaAs) red and infrared
Aluminium gallium phosphide (AlGaP) green
Aluminium gallium indium phosphide (AlGaInP) high-brightness
orange-red, orange, yellow, and green
Gallium arsenide phosphide (GaAsP) red, orange-red, orange, and yellow
Gallium phosphide (GaP) red, yellow and green
Gallium nitride (GaN) green, pure green (or emerald green), and blue
also white (if it has an AlGaN Quantum Barrier)

52

/* PROGRAM TO GLOW LED*/


#include<reg51.h>
void delay()
{
int a;
for(a=0;a<=30000;a++);
}
void main()
{
while(1)
{
P2=0x00;
delay();
P2=0xFF;
delay();
}

6.2 Seven segment display interfacing


Seven Segment
The seven-segment LED display has four individual digits, each with a decimal
point. Each of the seven segments (and the decimal point) in a given digit contains
an individual LED. When a suitable voltage is applied to a given segment LED,
current flows through and illuminates that segment LED. By choosing which
segments to illuminate, any of the nine digits can be shown. For example, as shown
in the figure below, a 2 can be displayed by illuminating segments a, b, d, e, and
g.seven segment displays come in two varieties - common anode (CA) and

53

common cathode (CC). In a CA display, the anodes for the seven segments and the
decimal point are joined into a single circuit node. To illuminate a segment in a CA
display, the voltage on a cathode must be at a suitably lower voltage (about .7V)
than the anode. In a CC display, the cathodes are joined together, and the segments
are illuminated by bringing the anode voltage higher than the cathode node (again,
by about .7V). The Dig labboard uses CA displays.
The seven LEDs in each digit are labeled a-g. Since
the Digilab board usesCA displays, the anodes for
each of the four digits are connected in a common
node, so that four separate anode circuit nodes exist
(one per digit).Similar cathode leads from each digit
have also been tied together to form seven common
circuit nodes, so that one node exists for each segment type. These four anode and
seven cathode circuit nodes are available at the J2connector pins labeled A1-A4
and CA-CG. With this scheme, any segment of any digit can be driven
individually. For example, to illuminate segments and c in the second digit, the b
and c cathode nodes would be brought to a suitable low voltage (by connecting the
corresponding circuit node available at the J2 connector to ground), and anode 2
would be brought to a suitablehigh voltage (by connecting the corresponding
circuit node available at theJ2 connector to Vdd).
/* PROGRAM TO SWITCH ON SEVEN SEGMENT DISPLAY MOVING FROM LSB TO
MSB */

#include<reg51.h>
void delay()
{

54

int a;
for(a=0;a<=30000;a++);
}
void main()
{
P2=0x3F;
delay();
P2=0x30;
delay();
P2=0x5B;
delay();
P2=0x1F;
delay();
P2=0x66;
delay();
P2=0x6D;
delay();
P2=0x7C;
delay();
P2=0x07;
delay();
P2=0x7F;
delay();
P2=0x3F;
delay();
}

55

6.3 Stepper motor interfacing


STEPPER MOTOR
EMotion Control, in electronic terms, means to accurately control the movement of
an object based on either speed, distance, load, inertia or a combination of all these
factors. There are numerous types of motion control systems, including; Stepper
Motor, Linear Step Motor, DC Brush, Brushless, Servo, Brushless Servo and
more.stepper motor is an electromechanical device which converts electrical pulses
into discrete mechanical movements. Stepper motor is a form of ac. motor .The
shaft or spindle of a stepper motor rotates in discrete step increments when
electrical command pulses are applied to it in the proper sequence. The motors
rotation has several direct relationships to these applied input pulses. The sequence
of the applied pulses is directly related to the direction of motor shafts rotation.
The speed of the motor shafts rotation is directly related to the frequency of the
input pulses and the length of rotation is directly related to the number of input
pulses applied. For every input pulse, the motor shaft turns through a specified
number of degrees, called a step. Its working principle is one step rotation for one
input pulse. The range of step size mayvary from 0.72 degree to 90 degree. In
position control application, if the number of input pulsessent to the motor is
known, the actual position of the driven job can be obtained.A stepper motor
differs from a conventional motor (CM) as under:

56

Figure 5.1-stepper
motor
a. Input to SM is in the form of electric pulses whereas input to a CM is invariably
from a constant voltage source.
b. A CM has a free running shaft whereas shaft of SM moves through angular
steps.
6.3.1 Step Angle & Steps per Revolution
Movement associated with a single step, depends on the internal construction of
the motor, inParticular the number of teeth on the stator and the rotor. The step
angle is the minimum degree of rotation associated with a single step. Step per
revolution is the total number of steps needed to rotate one complete rotation or
360degrees (e.g., 180 steps * 2 degree = 360) Since the stepper motor is not
ordinary motor and has four separate coils, which have tobe energized one by one
in a stepwise fashion. We term them as coil A, B, C and D. At a particular instant
the coil A should get supply and then after some delay the coil B should get supply
and then coil C and then coil D and so on the cycle continues. The more the delay
is introduced between the energizing of the coils the lesser is the speed of the
stepper motor advice versa.

57
/* PROGRAM USING STEPPER MOTOR*/

#include<reg51.h>
void delay()
{
int a;
for(a=0;a<=6000;a++);
}
void main()
{
P2=0x00;
delay( );
P2=0xff;
delay();
P2=0x00;
delay( );
P2=0xff;
delay();
P2=0x00;
delay( );
P2=0xff;
delay( );
}

58

6.4 Relay interfacing


The electromagnetic relay consists of a multi-turn coil, wound on an iron core, to
form an electromagnet. When the coil is energized, by passing current through it,
the core becomes temporarilymagnetized. The magnetized core attracts the iron
armature. The armature is pivoted which causes it to operate one or more sets of
contacts. When the coil is de-energized the armature and contacts are released. The
coil can reenergized from a low power source such as a transistor while the
contacts can switch high powers such as the mains supply. The relay can also be
situated remotely from the control source. Relays can generate a very high voltage
across the coil when switched off.This can damage other components in the circuit.
To prevent this a diode is connected across the coil.As there are always some
chances of high voltage spikes back from the switching circuit i.e. heater so an opt
coupler/isolator MCT2e is used. It provides and electrical isolation between the
microcontroller and the heater. MCT2e is a 6-pin IC with a combination of optical
transmitter LED and an optical receiver as phototransistor. Microcontroller is
connected to pin no 2 ofMCT2e through a 470-ohm resistor. Pin no.1 is given +5V
supply and pin no.4 is grounded. To handle the current drawn by the heater a
power transistor BC-369 is used as a current driver. Pin no.5 of opt coupler is
connected to the base of transistor. It takes all its output to Vandactivates the heater
through relay circuit. The electromagnetic relay consists of a multi-turn coil,
wound on an iron core, to form an electromagnet. When the coil is energized, by
passing current through it, the core becomes temporarily magnetized. The
magnetized core attracts the iron armature. The armature is pivoted which causes it
to operate one or more sets of contacts. When the coil is de-energized the armature

59

and contacts are released. Relays can generate a very high voltage across the coil
when switched off. This can damage other components in the circuit. To
preventthis diode is connected across the coil. Relay has five points. Out of the 2
operating points one is permanently connected to the ground and the other point is
connected to thecollector side of the power transistor. When Vreaches the collector
side i.e. signal is given to the operating points the coil gets magnetized and attracts
the iron armature. The iron plate moves from normally connected (NC) position to
normally open (NO) position. Thus the heater gets the phase signal and is ON. To
remove the base leakage voltage when no signal is present a 470-ohmresistance is
used.
/* PROGRAM USING RELAY */

#include<reg51.h>
void delay()
{
int a;
for(a=0;a<=6000;a++);
}
sbit relay=P1^1;
void main()
{
while(1)
{
relay =0;
delay();
delay();

60

delay();
delay();
delay();
relay=1;
delay();
delay();
delay();
delay();
delay();
}
}

61

CHAPTER - 7

CONCLUSION

62

CONCLUSION
The

basic architecture and function of a microcontroller is discussed. With

examples, the need for low power microcontroller is illustrated.


Microcontrollers

are

of

prime

importance

for

electronic

control

and

communication of any modern appliance. Any household appliance e.g. washing


machine, refrigerator, air-conditioner or office appliances e.g. electronic printer,
Photostat copier, fax machine contains one or more microcontrollers. Because of
its bulk usage a marginal saving in power for one 8051 results to enormous saving
as a whole.
In any device design, when one feature is optimized another feature degrades.
When low power is achieved the speed or performance may go down. Though this
microcontroller consumes negligible power its other features are comparable to the
existing microcontrollers available in the market.

Das könnte Ihnen auch gefallen