EMBEDDED SYSTEM
-
Upload
airtel -
Category
Engineering
-
view
182 -
download
0
Transcript of EMBEDDED SYSTEM
1 | P a g e
A
PROJECT REPORT
On
EMBEDDED SYSTEM
Submitted by
SUYASH TYAGI
In partial fulfilment for the award of the degree
Of
B.TECH
In
ELECTRONICS AND COMMUNICATION ENGINEERING
Under the Guidance
of
MR. SUMIT SINGH DHANDA
AMITY SCHOOL OF ENGINEERING TECHNOLOGY
AMITY UNVERSITY RAJASTHAN
2 | P a g e
PREFACE
There are certain phases of professional development that cannot be
effectively taught in the academic environment. These facets can only be
learned through ground work with the industry.
The internship program can best be described as an attempt to institutionalize
efforts to bridge the gap between the professional world and the academic
institutions. Hence entire effort in internship is in terms of extending the
program of education and evaluation beyond the classroom.
Excellence is an attitude that the whole of the human race is born with. It is
the environment that makes sure that makes sure whether the results of this
attitude are visible or otherwise. A well planned, properly executed &
evaluated industrial helps a lot in inculcating a professional attitude. It
provides a linkage between the student & the industry to develop an awareness
of industrial approach to problem solving, based on a broad understanding of
process & mode of operation of organization.
The internship training helped us to gain direct, on-the-job experience,
working with successful professionals and experts in the field. Internship with
the industry also provided hands on practical experience to us on the work
culture, work ethics and work practices in the industry.
I had the opportunity to have a real experience on many ventures, which
increased my sphere of knowledge to a great extent.
SUYASH TYAGI
3 | P a g e
ACKNOWLEDGEMENT
I have taken efforts in this project. However, it would not have been
possible without the kind support and help of many individuals and
organizations. I would like to extend my sincere thanks to all of them.
I am highly indebted to my guide MR. SUMIT SINGH DHANDA for
his guidance and constant supervision as well as for providing necessary
information regarding the project & also for his support in completing
the project.
I would like to express my gratitude towards my parents and my
program coordinator Mr. Sanyog Rawat for their kind co-operation and
encouragement which help me in completion of this project.
My thanks and appreciations also go to my colleague in developing the
project and people who have willingly helped me out with their abilities.
4 | P a g e
Central Electronics Limited (CEL)
CEL is a Public Sector Enterprise under the Department of Scientific and Industrial
Research (DSIR), Ministry of Science & Technology, Government of India. It was
established in 1974 with an objective to commercially exploit the indigenous
technologies developed by National Laboratories and R&D Institutions in the
country. CEL is one of the rare companies, which utilized the homegrown
technologies during all these years of its existence.
CEL is pioneer in the country in the field of Solar Photovoltaic (SPV) and it has
developed state-of-the-art technology with its own R&D efforts.
CEL, pioneer in the field of Railways Safety & Signaling, has been identified as a
major indigenous agency for design and development of modern electronic Signaling
and Safety equipment by Indian Railways. The equipment manufactured in CEL
finds extreme usage in Railways in the form of Axle Counter, Axle Counter Block
System and Train Approach Warning Devices for more than 25 years.
CEL has developed a number of critical components for strategic applications and is
supplying these items to Defense.
In recognition of all these efforts, CEL has been awarded a number of times with
prestigious awards including “National Award for R&D by DSIR”.
Divisions of CEL:
The Operations of the company are divided into three Business Groups:
1. Solar Photovoltaic Group (SPV): CEL, backed by an integrated production
facility, has opened up new horizons in the field of Solar Photovoltaic. It fulfills
the various demands from rural & urban areas, thus, harnessing the solar energy.
The products of this division are Solar Cells, Modules and systems, which serve
the industrial needs of Railway Signaling, Microwave Repeaters, Defense
equipments, Obstruction warning lights at airports, etc. and rural needs such as
pumping systems for irrigation, street lighting systems, solar lanterns and rural
telecommunications.
5 | P a g e
2. Electronic Systems Group (ESG): The Company is a pioneer in manufacturing
of Railway Signaling and Safety Equipments. It manufactures Axle Counters,
Railway Level Crossing Warning System, and solid State Interlocking System for
Railways. The other products of this division include Electronic Switching System,
Cathodic Protection System for underground pipelines and VSAT.
3. Components Group: A large range of products is manufactured here using state-
of-art technologies to meet the requirements of communications, defense,
consumer and industrial sectors.
It is divided into three sub departments. Their products and applications are as
follows:
(a) Professional Ferrites:
This department manufactures different types of ferrite cores for high frequency
applications. The different types of cores manufactured are Pot cores, E, U, I, RM,
torroids etc. These are called professional because they require highly sophisticated
techniques for their manufacture and give a superior performance. The various
applications of ferrite cores include TV sets, Communication equipments, computers,
electronic ballasts, switch mode power supplies (SMPS) and Microwave equipments.
(b) Electronic Ceramics:
This department manufactures piezo-electric transducer elements, high temperature
crucibles, high speed bearings and other alumina products. These products are used
in Defense ammunitions, Ultrasonic cleaners, Buzzers, Sonar, Gas Lighters,
Automobiles, etc.
(c) Microwave Electronics: This department manufactures microwave
components such as Phase Shifters used in Radars, Direction Finding Systems,
Frequency Correlators, Antennas, etc.
6 | P a g e
(d) Products of CEL:
The organization manufactures different products that can be classified according to
the divisions of CEL as follows:
(i) Solar Photovoltaic Group :
Solar Cells/Modules
Solar Lantern
Street Light System
Home Light System
Water Pumping System
(ii) Electronic Systems Group :
Single / Multiple Entry / Exit Axle counters
Universal Axle counters
Block proving system
Railway Level Crossing Warning system
Solid State Interlocking System for Railways
Cathodic Protection system
Very Small Aperture Terminal (VSAT)
Electronic Switching Equipments
(iii) Components Group :
Different types of ferrite cores like Pot, RM, E, U, I, etc
Piezoelectric transducer elements
Special Bearings used in Heavy Water Plants
Microwave Ferrite Phase shifters
Direction Finding Systems
Frequency / Phase Correlator
7 | P a g e
Index
Chapter 1 Introduction to Embedded System ……………………..1
1.1 Embedded System…………………………………………..1
1.2 Characteristics………………………………………………1
1.3 What is a controller…………………………………………2
1.4 A little history of Microcontroller…………………………..3
1.5 User interface and peripherals………………………………4
1.6 Architecture of Microcontroller……………………………..5
Cha pte r 2 Mic ro controller 8 0 51……………………………...6
2.1 pin Diagram And Pin Function……………………………..6
Chapter 3 LED Interfacing ………………………………………...13
3.1 About LED………………………………………………….13
3.2 Bi-colour LEDs……………………………………………..14
3.3 LED interfacing…………………………………………….16
Chapter 4 7- segment Display Interfacing …………………………19
4.1 7-segment Display ………………………………………….19
4.2 7-segment LEDs…………………………………………….19
4.3 7-segment LCDs…………………………………………….20
4.4 7-segment Display Interfacing……………………………...21
Chapter 5 LCD interfacing………………………………………….28
5.1 About LCD…………………………………………………28
5.2 About the Modules………………………………………….29
5.3 Power Supplies and Backlights……………………………..31
5.4 Reading and Writing………………………………………..33
5.5 LCD Interfacing …………………………………………...34
Reference………………………………………………………………36
8 | P a g e
Chapter 1
Introduction to Embedded System
1.1 Embedded System
An embedded system is a computer system designed to do one or a few dedicated
and/or specific functions often with real-time computing constraints. It is embedded
as part of a complete device often including hardware and mechanical parts. By
contrast, a general-purpose computer, such as a personal computer (PC), is designed
to be flexible and to meet a wide range of end-user needs. Embedded systems control
many devices in common use today.
Physically, embedded systems range from portable devices such as digital watches
and MP3 players, to large stationary installations like traffic lights, factory
controllers, or the systems controlling nuclear power plants. Complexity varies from
low, with a single microcontroller chip, to very high with multiple units, peripherals
and networks mounted inside a large chassis or enclosure.
1.2 Characteristics
1. Embedded systems are designed to do some specific task, rather than be a general-
purpose computer for multiple tasks. Some also have real-time performance
constraints that must be met, for reasons such as safety and usability; others may
have low or no performance requirements, allowing the system hardware to be
simplified to reduce costs.
2. Embedded systems are not always standalone devices. Many embedded systems
consist of small, computerized parts within a larger device that serves a more general
purpose. For example, the Gibson Robot Guitar features an embedded system for
tuning the strings, but the overall purpose of the Robot Guitar is, of course, to play
music. Similarly, an embedded system in an automobile provides a specific function
as a subsystem of the car itself.
9 | P a g e
3. The program instructions written for embedded systems are referred to as
firmware, and are stored in read-only memory or Flash memory chips. They run with
limited computer hardware resources: little memory, small or non-existent keyboard
and/or screen.
1.3 What’s a Microcontroller?
A microcontroller is a computer-on-a-chip or if we prefer a single-chip computer.
Micro suggests that the device is small, and controller tells that the device might be
used to control objects, processes or events. Another term to describe a
microcontroller isembedded controller, because the microcontroller and its support
circuits are often built into, or embedded in, the devices they control.
You can find microcontrollers in all kinds of things these days. Any device that
measures, stores, controls, calculates, or displays information is a candidate for
putting a microcontroller inside. The largest single use for microcontrollers is in
automobiles just about every car manufactured today includes at least one
microcontroller for engine control, and often more to control additional systems in
the car. In desktop computers, we can find microcontrollers inside keyboards,
modems, printers, and other peripherals. In test equipment, microcontrollers make it
easy to add features such as the ability to store measurements, to create and store
user routines, and to display messages and waveforms. Consumer products that use
microcontrollers include cameras, video recorders, compact-disk players, and ovens.
And these are just a few examples.
A microcontroller is similar to the microprocessor inside a personal computer. Both
microprocessors and microcontrollers contain a central processing unit, or CPU. The
CPU executes instructions that perform the basic logic, math, and data-moving
functions of a computer.
To make a complete computer, a microprocessor requires memory for storing data
and programs, and input/output (I/O) interfaces for connecting external devices like
keyboards and displays. In contrast, a microcontroller is a single-chip computer
10 | P a g e
because it contains memory and I/O interfaces in addition to the CPU. Because the
amount of memory and interfaces that can fit on a single chip is limited,
microcontrollers tend to be used in smaller systems that require little more than the
microcontroller and a few support components. Examples of popular
microcontrollers are Intel’s 8051, Intel’s 8052, Motorola’s 68HC11, and Zilog’s Z8.
1.4 A Little History of Microcontroller
To understand how microcontrollers fit into the always-expanding world of
computers, we need to look back to the roots of micro computing.
Microcontrollers have gone through a silent evolution. The evolution can be rightly
termed as silent as the impact or application of a microcontroller is not well known to
a common user, although microcontroller technology has undergone significant
change since early 1970's.
Development of some popular microcontrollers is given as follows.
Intel 4004 4 bit (2300 PMOS trans, 108
kHz)
1971
Intel 8048 8 bit 1976
Intel 8031 8 bit (ROM-less) .
Intel 8051 8 bit (Mask ROM) 1980
Microchip PIC16C64 8 bit 1985
Motorola 68HC11 8 bit (on chip ADC) .
Intel 80C196 16 bit 1982
Atmel AT89C51 8 bit (Flash memory) .
Microchip PIC
16F877
8 bit (Flash memory + ADC) .
11 | P a g e
1.5 User Interface And Peripherals
Embedded systems range from no user interface at all dedicated only to one task to
complex graphical user interfaces that resemble modern computer desktop operating
systems. Simple embedded devices use buttons, LEDs, graphic or character LCDs
(for example popular HD44780 LCD) with a simple menu system.
More sophisticated devices use graphical screen with touch sensing or screen-edge
buttons provide flexibility while minimizing space used: the meaning of the buttons
can change with the screen, and selection involves the natural behaviour of pointing
at what's desired. Handheld systems often have a screen with a "joystick button" for a
pointing device.
Some systems provide user interface remotely with the help of a serial (e.g. RS-232,
USB, etc.) or network (e.g. Ethernet) connection. In spite of the potentially necessary
proprietary client software and/or specialist cables that are needed, this approach
usually gives a lot of advantages: extends the capabilities of embedded system,
avoids the cost of a display, allows to build rich user interface on the PC. A good
example of this is the combination of an embedded web server running on an
embedded device (such as an IP camera) or a network routers.
Peripherals
Embedded Systems talk with the outside world via peripherals, such as:
– LED
– Displays: LCD, 7 segments etc.
– Serial Communication Interfaces (SCI): RS-232, RS-422, RS-485 etc.
– Synchronous Serial Communication Interface: I2C, SPI, SSC and ESSI (Enhanced
Synchronous Serial Interface)
– Universal Serial Bus (USB)
– Multi Media Cards (SD Cards, Compact Flash etc.)
– Networks: Ethernet, LonWorks, etc.
– Fieldbuses
– Timers: PLL(s), Capture/Compare and Time Processing Units
12 | P a g e
– Discrete IO: aka General Purpose Input/Output (GPIO)
– Analog to Digital/Digital to Analog (ADC/DAC)
– Debugging: JTAG, ISP, ICSP, BDM Port, BITP, and DP9 ports.
1.6 Architecture of Microcontroller
At times, a microcontroller can have external memory also (if there is no internal memory or
extra memory interface is required). Early microcontrollers were manufactured using bipolar
or NMOS technologies. Most modern microcontrollers are manufactured with CMOS
technology, which leads to reduction in size and power loss. Current drawn by the IC is also
reduced considerably from 10mA to a few micro Amperes in sleep mode (for a
microcontroller running typically at a clock speed of 20MHz).
Fig 1.1 Internal Structure of a Microcontroller
13 | P a g e
Chapter 2
Microcontroller 8051
2 .1 P in Diagram And Pin Funct ions
The pin diagram of the 8051 shows all of the input/output pins unique to
microcontrollers:
The following are some of the capabilities of 8051 microcontroller.
- Internal ROM and RAM
14 | P a g e
- I/O ports with programmable pins
- Timers and counters
-Serial data communication
ALE/PROG:
Address Latch Enable output pulse for latching the low byte of the address
during accesses to external memory.
ALE is emitted at a constant rate of 1/6 of the oscillator frequency, for
external timing or clocking purposes, even when there are no accesses to
external memory. (However, one ALE pulse is skipped during each access to
external Data Memory.)
This pin is also the program pulse input (PROG) during EPROM
programming.
PSEN:
Program Store Enable is the read strobe to external Program Memory.
When the device is executing out of external Program Memory, PSEN is
activated twice each machine cycle (except that two PSEN activations are
skipped during accesses to external Data Memory).
PSEN is not activated when the device is executing out of internal Program
Memory
EA/VPP:
When EA is held high the CPU executes out of internal Program.
Holding EA low forces the CPU to execute out of external memory
regardless of the Program Counter value.
In the EPROM devices, this pin also receives the programming supply
voltage (VPP) during EPROM programming.
XTAL1:
Input to the inverting oscillator amplifier.
XTAL2:
Output from the inverting oscillator amplifier.
Port 0:
Port 0 is an 8-bit bidirectional port.
As an open drain output port, it can sink eight LS TTL loads.
15 | P a g e
Port 0 pins that have 1s written to them float, and in that state will function as
high impedance inputs.
Port 0 is also the multiplexed low-order address and data bus during accesses
to external memory.
In this application it uses strong internal pull-ups when emitting 1s.
Port 0 emits code bytes during program verification. In this application,
external pull-ups are required.
Port 1:
Port 1 is an 8-bit bidirectional I/O port with internal pull-ups.
Port 1 pins that have 1s written to them are pulled high by the internal pull-
ups, and in that state can be used as inputs.
As inputs, port 1 pins that are externally being pulled low will source current
because of the internal pull-ups.
Port 2:
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups.
Port 2 emits the high-order address byte during accesses to external memory
that use 16-bit addresses. In this application, it uses the strong internal pull-
ups when emitting 1s.
Port 3:
Port 3 is an 8-bit bidirectional I/O port with internal pull-ups.
It also serves the functions of various special features of the 80C51 Family as
follows:
Port Pin Alternate Function
P3.0 RxD (serial input port)
P3.1 TxD (serial output port)
P3.2 INT0 (external interrupt 0)
P3.3 INT1 (external interrupt1)
P3.4 T0 (timer 0 external input)
P3.5 T1 (timer 1 external input )
P3.6 WR (external data memory write strobe)
P3.7 RD (external data memory read strobe)
16 | P a g e
The alternate functions can only be activated if the corresponding bit latch in the port
SFR contains a 1. Otherwise the port pin remains at 0.
* All four ports in the 80C51 are bidirectional. Each consists of a latch (Special
Function Registers P0 through P3), an output driver, and an input buffer.
* The output drivers of Ports 0 and 2, and the input buffers of Port 0, are used in
accesses to external memory. In this application, Port 0 outputs the low byte of the
external memory address, time-multiplexed with the byte being written or read. Port
2 outputs the high byte of the external memory address when the address is 16 bits
wide. Otherwise, the Port 2 pins continue to emit the P2 SFR content.
Reset requirements
The process of starting any microcontroller is a non-trivial one. The underlying
hardware is complex and a small, manufacturer-defined, ‘reset routine’ must be run
to place this hardware into an appropriate state before it can begin executing the user
program. Running this reset routine takes time, and requires that the
microcontroller’s oscillator is operating.
Where your system is supplied by a robust power supply, which rapidly reaches its
specified output voltage when switched on, rapidly decreases to 0V when switched
off, and – while switched on – cannot ‘brown out’ (drop in voltage), then you can
safely use low-cost reset hardware based on a capacitor and a resistor to ensure that
your system will be reset correctly: this form of reset circuit is shown in Figure 2.3a.
Where your power supply is less than perfect, and / or your application is safety
related, the simple RC solution will not be suitable. Several manufacturers provide
more sophisticated reset chips which may be used in these circumstances
Clock frequency and performance
All digital computer systems are driven by some form of oscillator circuit: the 8051
is certainly no exception. The oscillator circuit is the ‘heartbeat’ of the system and is
crucial to correct operation. For example, if the oscillator fails, the system will not
function at all; if the oscillator runs irregularly, any timing calculations performed by
the system will be inaccurate.
17 | P a g e
We consider some important issues linked to oscillator frequency and performance in
this section:
a) The link between oscillator frequency and machine-cycle period
One of the first questions to be asked when considering a microcontroller for a
project is whether it has the required level of performance. As a general rule, the
speed at which your application runs is directly determined by the oscillator
frequency: in most cases, if you double the oscillator frequency, the application will
run twice as fast. When we want to compare different processors, we need a way of
specifying performance in a quantitative manner. One popular measure is the number
of machine instructions that may be executed in one second, usually expressed in
‘MIPS’ (Million Instructions per Second). For example, in the original Intel 8051
microcontroller, a minimum of 12 oscillator cycles was required to execute a
machine instruction. The original 8051 had a maximum oscillator frequency of 12
MHz and therefore a peak performance of 1 MIP.
A simple way of improving the 8051 performance is to increase the clock frequency.
More modern (Standard) 8051 devices allow the use of clock speeds well beyond the
12 MHz limit of the original devices. For example, the Atmel AT89C55WD, allow
clock speeds up to 33 MHz: this raises the peak performance to around 3 MIPS.
Another way of improving the performance is to make internal changes to the
microcontroller so that fewer oscillator cycles are required to execute each machine
instruction. The Dallas ‘High Speed Microcontroller’ devices (87C520, and similar)
use this approach, so that only four oscillator cycles are required to execute a
machine instruction. These Dallas devices also allow faster clock rates (typically up
to 33 MHz). Combined, these changes give a total performance of around 8 MIPS.
Similar changes are made in members of the Winbond family of Standard 8051
devices (see the Winbond W77E58, for example) resulting in performance figures of
up to 10 MIPS.
Clearly, for maximum performance, we would like to execute instructions at a rate of
one machine instruction per oscillator cycle. For example, the Dallas ‘Ultra High
Speed’ 89C420 operates at this rate: as a result, it runs at 12 times the speed of the
18 | P a g e
original 8051. In addition, the 89c420 can operate at up to 50 MHz, increasing
overall performance to around 40–50 MIPS.
To put all these figures in perspective, a modern desktop PC has a potential
performance of around 1000 MIPS. However, a good percentage of this performance
(perhaps 50% or more) will be ‘consumed’ by the operating system. By contrast, the
embedded operating system we will describe in Chapter 7 consumes less than 1% of
the processor resources of the most basic 8051: this leaves sufficient CPU cycles to
run a complex embedded application.
b) Why you should choose a low oscillator frequency
In our experience, many developers select an oscillator frequency that is at or near
the maximum value supported by a particular device. For example, the Infineon
C505/505C will operate with crystal frequency of 2–20 MHz, and many people
automatically choose values at or near the top of this range, in order to gain
maximum performance.
This can be a mistake, for the following reasons:- Many applications do not
require the levels of performance that a modern 8051 device canprovide.
- In most modern (CMOS-based) 8051s, there is an almost linear relationship
between the oscillator frequency and the power supply current. As a result, by using
the lowest frequency necessary it is possible to reduce the power requirement: this
can be useful, particularly in battery-powered applications.
- When accessing low-speed peripherals (such as slow memory, or liquid-crystal
displays), programming and hardware design can be greatly simplified – and the cost
of peripheral components, such as memory latches, can be reduced – if the chip is
operating more slowly.
- The electromagnetic interference (EMI) generated by a circuit increases with
clock frequency.
In general, you should operate at the lowest possible oscillator frequency compatible
with the performance needs of your application. As we will see in later chapters,
simulating the processor is a good way of determining the required operating
frequency for a particular application.
19 | P a g e
Fig. Microcontroller
20 | P a g e
Chapter 3
LED Interfacing
3.1 About LED
Discrete or individual LEDs (light-emitting diodes) are an easy way to indicate
status, such as On, Ready, Mode selected, and so on. They are colourful, eye-
catching, and easy to interface to 5-volt logic. Available colours now include blue as
well as red, green, and yellow. Some individual LED packages can emit red, green,
or amber light, depending on the voltages applied.
Like other diodes, current passes through an LED in one direction only. When a
positive voltage is applied to the anode, current flows and electrons migrate across an
energy gap in the LED, causing it to emit light. The size of the energy gap
determines the voltage drop across the LED, as well as the colour of light emitted. A
tinted case can also vary the colour.
Table 3. 1.The forward voltage drop across an LED varies with the colour.
LED colour typical forward voltage
(volts)
Red 1.6
Green 2.0
Yellow 2.0
Blue 3.2
Table 3.1 shows typical forward voltages for different colours of LEDs. Typical
LED operating currents are between 10 and 20 mill amperes. For a bright display
with low power consumption, look for types labelled high efficiency.
21 | P a g e
One disadvantage to LEDs is that the light from most is hard to detect in bright light,
especially outdoors. A tinted, transparent sheet of plastic mounted over the display
can make it more visible in bright light. For red LEDs, transparent red or purple
works well.For best visibility over a wide area, look for LEDs with a wide viewing
angle. This means that the LED emits light in a wide cone, so you don’t need to view
it straight-on.
3.2 Bi-colour LEDs
Bi-colour LEDs have two LEDs of different colours inside a single package. By
turning on one, both, or neither, we can use a single indicator to show as many as
four states. Some bicolour LEDs have two leads, while others have three.
22 | P a g e
Figure 3.2.Ways to connect bicolour LEDs.
Figure 3.2illustrates.
In the 3-lead, or common-cathode type, the cathodes of both LEDs connect internally
(A). To turn on an LED, we ground the cathodes through a current-limiting resistor
and apply power to the anode of the desired LED. When both LEDs are powered, we
get different light that is mixture of both led’s colour (amber in case of red and
green). Removing power from both turns the LED off, giving a total of four states
that the device can display. Instead of the one current-limiting resistor shown, we can
connect a resistor to each anode, to set the current through each LED individually.
In a 2-lead, or parallel-connected, bicolour LED, the anode of each LED connects
internally to the other’s cathode (B). To turn on the one LED, we apply +5V to
terminal A and ground terminal B. To turn on the other LED, we do the reverse
terminal A is ground and terminal B is +5V. With this type, we can’t turn on both
LEDs at once.With either type, by adding an inverter, we can use a single output to
control both LEDs (C, D).
23 | P a g e
3.3 LED Interfacing
We can interface LED to any output port of 8051 microcontroller. When a LED is
connected to any circuit it usually takes 2 Volts (Red, Green) and a Blue or White
LED takes 4 Volts.
To turn on an LED at a port, write a 1 or 0, as appropriate, to the bit that controls it.
LED has two leads: Cathode and Anode. They are identified by the length of the lead.
Cathode is of broader filament.
Circuit diagram 3.1 LED interfacing
24 | P a g e
Example
write a programme to show moving off in LEDs interfaced at port 2
Programme
01 #include<reg51.h> // Including header file
02 #define led P2 // Defining Port 2.0 as Led port
03 void delay(unsigned int);
04 void main() // Main function
05 {
06 while(1)
07 {
08 led=0xFF; //to on all the LEDs
09 delay(100); //delay function call
10 led=0x7F; // one led is off
11 delay(100);
12 led=0xBF;
13 delay(100);
14 led=0xDF;
15 delay(100);
16 led=0xEF;
17 delay(100);
18 led=0xF7;
19 delay(100);
20 led=0xFB;
21 delay(100);
22 led=0xFD;
23 delay(100);
24 led=0xFE;
25 delay(100);
26 }
27 }
28 void delay(unsigned int e)
25 | P a g e
29 { unsigned inti,j;
30 for(i=0;i<e;i++)
31 for(j=0;j<1275;j++);
32 }
Circuit diagram 3.2
26 | P a g e
Chapter 4
7 segment display interfacing
4.1 7-segment Displays
If we want to display numbers, 7-segment displays will do the job. Each digit on the
display contains seven segments. Numerals are displayed by turning on different
combinations of segments, as Figure 4.1 shows.
Figure 4.1A 7-segment display can show numbers from 0 to 9 and hex digits A-F.
Decoder chips make it easy to operate one or more displays with a minimum of
programming and added components. Seven-segment displays are available as LEDs,
where each segment is a light-emitting diode, and as LCDs, where each segment is a
liquid-crystal display. We’ll look at the LED type first.
4.2 7-segment LEDs
A 7-segment LED contains seven individual LEDs arranged in the pattern shown in
Figure 4.2 Sometimes there is also a decimal point (or two, one on each side). There
are also special leading-digit modules that display only a 1 and a plus-or-minus
symbol.
27 | P a g e
The displays come in two types: common-anode or common-cathode. In a common-
anode display, the anodes of each segment connect internally. To use the display,
you connect the anodes to a voltage source and turn on individual segments by
grounding them through a current-limiting resistor. A common-cathode display is the
opposite: the cathodes connect internally, so you ground the cathodes and apply
voltages through current-limiting resistors at the segments you want to light.
Figure 4.2 7-segment LEDs
4.3 7-segment LCDs
An alternative to LEDs is liquid-crystal displays (LCDs). Unlike LEDs, which
consume several milliamperes per segment, LCDs are voltage-controlled and require
very little operating current.
Compared to LEDs, LCDs are easy to read in bright light. However, because LCDs
don’t emit light as LEDs do, but merely absorb or transmit it, we need additional
lighting to see them in the dark. LCDs also tend to have narrower viewing angles
than LEDs. So, whether to use LEDs or LCDs may depend on where and how we
will use the display.
28 | P a g e
Most 7-segment LCD modules contain two or more digits. Like the LEDs, a 7-
segment LCD creates a numeral by turning on selected segments.
Each LCD segment contains a thin layer of liquid crystal between two layers of
glass. Liquid crystals are organic compounds that act as electrically controlled light
polarizers. In a positive-image display (the most common type), applying a voltage
across a segment causes the segment to appear dark, or opaque, while removing the
voltage causes the segment to appear light-colored, or transparent. Negative-image
displays are opaque when not powered, and transparent when powered. By applying
and removing voltages across individual segments, you can display numeric,
alphabetic, and other characters.
Applying a constant voltage to an LCD segment will eventually destroy it. Instead,
you must drive the segment with an alternating voltage, typically a square wave that
alternately applies +5 and -5V across the segment.
4.4 7 segment display interfacing
There isn’t much standardization for pinouts of 7-segment displays. If we don’t know
the pinout for a display, we can find it by experimenting. We’ll need a 330-ohm
resistor and a 5-volt supply.
Sometimes we’ll find CC or CA stamped on the package to indicate common cathode
or common anode. If even this information is lacking, begin by connecting one lead
of the resistor to ground on your power supply. Clip the resistor’s other end to one of
the LED’s pins. Use a test lead to touch the power supply +5V output to each of the
other pins in turn.
If only one or two connections cause a segment to light, you have a common-anode
display, and the common anode is the pin or pins that connect to +5V when the
segment lights. (There may be two common-anode pins.) To find the pin that
controls each segment, leave the +5V lead on a common-anode pin, and connect the
resistor to each pin in turn, noting the results.
For a common-cathode display, to find the common-cathode pin or pins, connect a
pin to +5V, and touch the others to ground through the 330-ohm resistor. The pin or
29 | P a g e
pins that cause the segment to light are the common-cathode connections. To find the
pin that controls each segment, move the +5V lead to each pin in turn, and note the
results.
Figure 4.3
30 | P a g e
Circuit diagram 4.1 for 7 segment display interfacing with 8051uc
Examples
1. Write a programme to design a up down counter using 8051 with 7
segment interfacing.
01 #include <REGX51.H>
02 void delay(unsigned int);
03 unsigned char z[]={0xC0,0xF9,0xA4,0xB0,0x99, 0x92, 0x82,
0xF8,0x80,0x90};
04 sbit up = P2^0;
05 sbit down=P2^1;
06 void main()
07 { while(1)
08 {unsigned inti;
09 if( up==0 && down==1)
10 {if(i>=9)
11 { i==0;
31 | P a g e
12 }else
13 { i++;
14 P3=z[i];
15 delay(100);
16 }}
17 else if( up== 1 && down==0)
18 {if(i<=0)
19 {i==0;
20 }else
21 {i--;
22 P3=z[i];
23 delay(100);
24 }}} }
25 void delay(unsigned int x)
26 {unsigned inta,b;
27 for(a=0;a<x;a++)
28 for(b=0;b<1275;b++);
29 }
Circuit diagram
32 | P a g e
2. Design an interfacing to make a free running counter up to 9999.
01 #include <REGX51.H>
02 void delay(unsigned int);
03 void display(unsigned int);
04 sbit s4=P3^0;
05 sbit s3=P3^1;
06 sbit s2=P3^2;
07 sbit s1=P3^3;
08 void main()
09 { unsigned inta,b,c,d,e,f;
10 unsigned int count;
11 while(1)
12 {s4=s3=s2=s1=0;
13 for(count =00;count<=9999;count++)
14 {a=count%100;
15 b=count/100;
16 c=a%10;
17 d=a/10;
18 e=b%10;
19 f=b/10;
20 s1=1;
21 s3=s2=s4=0;
22 display(c) ;
23 delay(1);
24 s1=0;
25 s2=1;
26 s3=s4=0;
27 display(d);
28 delay(3);
29 s2=0;
30 s3=1;
31 s4=s1=0;
33 | P a g e
32 display(e);
33 delay(3);
34 s3=0;
35 s4=1;
36 s2=s1=0;
37 display(f);
38 delay(5);
39 }}}
40 void display(unsigned int x)
41 {unsigned int y;
42 y=x;
43 switch(y)
44 {case 0:
45 P2 =0xC0;
46 break;
47 case 1:
48 P2 =0xF9;
49 break;
50 case 2:
51 P2 =0xA4;
52 break;
53 case 3:
54 P2 =0xB0;
55 break;
56 case 4:
57 P2 =0x99;
58 break;
59 case 5:
60 P2 =0x92;
61 break;
62 case 6:
63 P2 =0x82;
34 | P a g e
64 break;
65 case 7:
66 P2 =0xF8;
67 break;
68 case 8:
69 P2 =0x80;
70 break;
71 case 9:
72 P2 =0x90;
73 break;
74 }}
75 void delay(unsigned int a)
76 { unsigned intb,c;
77 for (b =0;b<a;b++)
78 for (c=0;c<1275;c++);
79 }
Circuit diagram
35 | P a g e
Chapter 5
LCD interfacing
5.1 About LCD
Sometimes a device has to display more complex messages than simple LEDs and 7-
segment displays can handle. For example, you might want to display messages like
these:
Please enter your access code.
Select function:
Read
Program
Verify
Exit
Wind is from the west at 12 mph
Total cost = $5.82
Room temperature is 26c
We can use the host computer’s display, but this is no help if you want to create a
stand-alone project that doesn’t require a personal computer. In these situations, a
character-based dot-matrix LCD module is a solution.
These modules can display messages made up of numbers, characters of the
alphabet, and other symbols (for math functions, for example, or even symbols you
design yourself). Figure 5.1 illustrates. Devices that use this type of display include
laser printers and test equipment.
36 | P a g e
Figure 5.1With a character-based dot-matrix LCD module, you can display
messages as well as numbers.
5.2 About the Modules
The character-based LCD modules are available from many companies, including
Philips, Optrex, and Densitron. Complete technical information on the controller and
displays is available from Hitachi and the display manufacturers, and from some
distributors and catalogs.
The display of one of these modules contains one or more rows of character
positions. Each character position consists of a matrix that is typically five segments,
or dots, wide and eight segments tall. (The HD44780 can also control matrices that
are 11 segments tall, for better display of characters with descenders, like g, p, and
q.)
The module forms characters by turning on the appropriate segments in a character
position. For example, to display an L, the module turns on one vertical column
37 | P a g e
andone horizontal row of segments. For most characters, the bottom row is reserved
for displaying a cursor, which leaves 35 segments to form the character.
Displays are available in several sizes. Popular sizes are 1 x 16 (1 line of 16
characters), 2 x 16, and 2 x 20. Displays larger than 80 characters require
supplemental driver chips along with the HD44780, but the displays can use the
same interface.
Table 5.1 summarizes the signals in the 14-line interface.
Pin
Symbol Input/
Output
Function
1 VSS Input Signal Ground
2 VDD Input Supply Voltage (+5V)
3 V0 Input Contrast adjust
4 RS Input Register select (1=data; 0=instruction
register, busy flag/address counter)
5 R/W Input Read (1)/write (0) select
6 E Input Enable
7 D0 I/O Data bit 0
8 D1 I/O Data bit 1
9 D2 I/O Data bit 2
10 D3 I/O Data bit 3
11 D4 I/O Data bit 4
12 D5 I/O Data bit 5
13 D6 I/O Data bit 6
14 D7 I/O Data bit 7
38 | P a g e
Figure 5.2 2*16 LCD
5.3 Power Supplies and Backlights
The power supply (pin 2) is a simple +5V DC. The modules contain their own
oscillators to drive the LCD segments. Typical power consumption for an entire
module is just a couple of milliamperes. A contrast input (pin 3) allows you to adjust
for best viewing under varying light conditions, viewing angles, and temperatures.
Some LCD modules use backlighting to allow viewing in dim light. A module may
be reflective (which does not use backlighting), transmissive (which must use
backlighting), or transflective (which may use backlighting or not). With a
transflective display, you can add a switch to enable users to turn the backlighting on
or off as desired.
One popular type of backlight is an electroluminescence (EL) panel behind the LCD
segments. An EL panel emits a diffuse light that provides a bright background for the
LCDs. Electroluminescent backlighting requires first of all, a module that contains an
EL panel, and second, an inverter module to provide the high-voltage alternating
signal required to power the panel. The inverters typically convert +5 volts to around
100 volts RMS at 400 Hertz. Inverters are usually offered along with the modules
that use them, so you shouldn’t have to construct your own. The backlighting
requires several milliamperes. Incandescent and LED backlights are other options for
illuminating LCDs.
39 | P a g e
5.4 Reading and Writing
Writing to the LCD module involves the following steps:
Bring RS high to write data, or low to write an instruction.
Bring R/W low.
Bring D0-D7 to their desired states.
Wait at least 140 nanoseconds.
Bring E high for at least 450 nanoseconds.
Bring E low.
Read operations are similar to writes, with R/W high instead of low. The data appears
on D0-D7 in 320 nanoseconds or less after E goes high.
5.5 LCD Interfacing
On the LCD module, pins 1-3 connect to ground, +5V, and a contrast potentiometer.
For maximum contrast, connect pin 3 directly to ground. Pins 4-6 are the control
signals for the LCD module. These connect to three outputs on Port C. The eight data
bits, pins 7-14 on the LCD module, connect to any Port .
Initializing the module. On power up, the LCD module must initialize properly.
If power-up is clean, with the supply voltage rising from 0.2V to 4.5V in 10
milliseconds or less, the module initializes automatically. But, if power-up doesn’t
meet this requirement, your program has to provide the initialization routine. It’s a
good idea to always include an initialization routine in your program, since it does no
harm, and if the module doesn’t initialize properly, it won’t respond correctly or at
all. Table 8-3 summarizes the initialization procedure. In short, the module must first
receive three identical commands selecting an 8-bit interface. To begin the
initializing, you must send the instruction to select an 8-bit interface, even if your
interface is four bits.
Initialization procedure for LCD modules using HD44780 Controller
Power on
Wait 15 milliseconds after V+ = 4.5V
40 | P a g e
Function set = 30h
Wait 4.1 milliseconds
Function set = 30h
Wait 100 microseconds
Function set = 30h
Function set to match display module
Display on
Display clear
Entry mode set
Example
Write a program to print the text WELCOME on LCD interfaced to uc 8051.
01 #include <REGX51.H>
02 #define lcd P3
03 sbitrs = P2^5;
04 sbitrw = P2^6;
05 sbit en = P2^7;
06 void lcd_cmd(unsigned char);
07 void lcd_data(unsigned char);
08 void delay(unsigned int);
09 void main()
10 {
11 while(1)
12 {
13 lcd_cmd(0x38);
14 delay(1);
15 lcd_cmd(0x80);
16 delay(1);
17 lcd_cmd(0x0e);
18 delay(1);
19 lcd_data('m');
41 | P a g e
20 delay(1);
21 lcd_data('a');
22 delay(1);
23 lcd_data('a');
24 delay(1);
25 }
26 }
27 void lcd_cmd(unsigned char c)
28 {
29 lcd=c;
30 rs=0;
31 rw=0;
32 en=1;
33 delay(1);
34 en=0;
35 }
36 void lcd_data(unsigned char d)
37 {
38 lcd=d;
39 rs=1;
40 rw=0;
41 en=1;
42 delay(1);
43 en=0;
44 }
45 void delay(unsigned int x)
46 {
47 unsigned inti,j;
48 for(i=0;i<x;i++)
49 for(j=0;j<1275;j++);
50 }
42 | P a g e
Circuit diagram
43 | P a g e
Reference
http://www.wikipedia.org/wiki/Liquid_crystal_display
http://www.wikipedia.org/wiki/7_segment_display
8051 microcontroller By Mazidi and Mazidi