You are on page 1of 87

PLEASE NOTE: THE MATTER

PRODUCED BELOW IS
REFERENCE MATERIAL ONLY
FOR PREPARING THE PROJECT
REPORT. IT IS NOT THE
COMPLETE PROJECT REPORT.

1

A PROJECT REPORT ON

LOW COST PROGRAMMABLE LOGIC CONTROL (PLC) FOR
INDUSTRIAL AUTOMATION IN REPETATIVE NATURE OF
WORK
Submitted in partial fulfillment of the requirements
For the award of the degree
BACHELOR OF ENGINEERING
IN
____________________________________ ENGINEERING
SUBMITTED BY
--------------------

(--------------)

--------------------- (---------------)
--------------------- (---------------)

DEPARTMENT OF _______________________ ENGINEERING
__________COLLEGE OF ENGINEERING
AFFILIATED TO ___________ UNIVERSITY

2

CERTIFICATE
This

is

to certify

that

the dissertation work entitled

LOW COST

PROGRAMMABLE LOGIC CONTROL ( PLC) FOR INDUSTRIAL
AUTOMATION IN REPETATIVE NATURE OF WORK is the work done by
_______________________________________________submitted

in

partial

fulfillment for the award of ‘BACHELOR OF ENGINEERING (B.E)’in
__________________________Engineering from______________ College of
Engineering affiliated to _________ University, Hyderabad .

________________
(Head of the department, ECE)

____________
(Assistant Professor)

EXTERNAL EXAMINER

3

ACKNOWLEDGEMENT
The satisfaction and euphoria that accompany the successful completion of any
task would be incomplete without the mentioning of the people whose constant
guidance and encouragement made it possible. We take pleasure in presenting
before you, our project, which is result of studied blend of both research and
knowledge.
We express our earnest gratitude to our internal guide, Assistant Professor
______________, Department of ECE, our project guide, for his constant
support, encouragement and guidance. We are grateful for his cooperation and
his valuable suggestions.
Finally, we express our gratitude to all other members who are involved either
directly or indirectly for the completion of this project.

DECLARATION
4

being submitted in partial fulfillment for the award of Bachelor of Engineering Degree in Electronics and Communication Engineering.We. the undersigned. affiliated to _________ University. is the work carried out by us. __________ _________ _________ __________ _________ _________ CONTENTS PAGE NO. 5 . declare that the project entitled ‘LOW COST PROGRAMMABLE LOGIC CONTROL ( PLC) FOR INDUSTRIAL AUTOMATION IN REPETATIVE NATURE OF WORK’.

4 FILTER 24 4.8 LCD 53 4.2 CONCEPT OF COMPILER 57 5. HARDWARE REQUIREMENTS 17 4.12 RESISTORS 4.9 ULN2003 56 4. ABSTRACT 9 2.5 MICROCONTROLLER (AT89S52) 24 4. INTRODUCTION TO EMBEDDED SYSTEMS 10 3. SOFTWARE REQUIREMENTS 56 5.10 1N4007 4.1 IDE 57 5.4 KEIL C CROSS COMPILER 59 5.1 TRANSFORMERS 19 4.3 CONCEPT OF CROSS COMPILER 58 5. BLOCK DIAGRAM 16 4.7 PUSH BUTTONS 49 4.2 VOLTAGE REGULATOR (LM7805) 20 4.1.5 BUILDING AN APPLICATION IN UVISION2 59 6 .13 CAPACITORS 5.12 LOAD 4.6 RELAY 45 4.3 RECTIFIER 23 4.11 LED 4.

6 CREATING YOUR OWN APPLICATION IN UVISION2 59 5. LAYOUT DIAGRAM 71 8.10 BUILDING PROJECTS & CREATING HEX FILES 61 5. CODING 75 9. HARDWARE TESTING 88 10.1 DESCRIPTION 67 7. BIBLIOGRAPHY 94 LIST OF FIGURES PAGE NO. BILL OF MATERIALS 72 9.15 EMBEDDED C 64 6.12 DATABASE SELECTION 62 5. RESULTS 69 12.13 START DEBUGGING 63 5.8 STARTING UVISION2 & CREATING A PROJECT 61 5.7 DEBUGGING AN APPLICATION IN UVISION2 60 5.11 CPU SIMULATION 62 5.5.1 COMPILER 76 9. 7 .9 WINDOWS_ FILES 61 5.2 POWER ON TEST 89 11.CONCLUSION 93 13.1 CONTINUITY TEST 88 10.14 DISASSEMBLY WINDOW 63 5.2 SOURCE CODE 84 10. SCHEMATIC DIAGRAM 66 5.

1 A TYPICAL TRANSFORMER 19 4.2(a) BLOCK DIAGRAM OF VOLTAGE REGULATOR 21 4.5(b) PIN DIAGRAM OF AT89S52 28 4.9 ULN2003 42 4.11 (a) TYICAL LED 4. ABSTRACT 8 .5(a) BLOCK DIAGRAM OF AT89S52 27 4.8 LCD 4.11(b) CIRCUIT OF LED SCHEMATIC DIAGRAM 1.7(c) TABLE FOR TYPES OF PUSH BUTTONS 53 4. 33 4.5(d) EXTERNAL CLOCK DRIVE CONFIG.6(a) RELAY 45 4.7(b) PUSH ON BUTTON 51 4.5(c) OSCILLATOR CONNECTIONS 32 4.7(a) PUSH BUTTONS 49 4.6(b) INTERNAL CIRCUIT OF RELAY 46 4.2(c) PERFORMANCE CHARACTERISTICS OF VOLTAGE REGULATOR 22 4.2(a) EMBEDDED DESIGN CALLS 12 2(b) ‘V’ DIAGRAM 12 3 BLOCK DIAGRAM OF THE PROJECT 16 4.2(b) RATING OF VOLTAGE REGULATOR 22 4.

the set mode. The development of this application requires the configuration of microcontroller architecture that is the selection of the machines..The main objective of the project is designing a programmable sequential switching of any load using embedded system based microcontroller concept. and writing debugging of the application program. through the digital clock the machinery will run based on/off and on time where as in auto mode they will run by default settings and finally in the manual mode the real-time systems used extensively in industrial control applications can run depending on the user’s need and flexibility. 9 . the clock plays an important role. where it is used in the following mode i.e. auto mode and manual mode for controlling different machines. In this project. In set mode.

and perhaps additional mechanical or other parts. designed to perform a specific function.2. An 10 .INTRODUCTION TO EMBEDDED SYSTEMS What is embedded system? An Embedded System is a combination of computer hardware and software.

not a software system on PC or UNIX. or human or network interactive. SYSTEM DESIGN CALLS: Build Operating Digital Integrated Download circuit Systems Electronic design design Debug Analog Tools Electronic design Computer Embedded Architecture Sensors and Systems measurements Software Engineering Electric motors and actuatorsControl Data Engineering Communication Embedded system design calls on many disciplines Figure 2(a): Embedded system design calls EMBEDDED SYSTEM DESIGN CYCLE 11 .Lower end embedded systems . Examples Personal Digital Assistant and Mobile phones etc .Generally 8. 64 Bit Controllers used with OS.Generally 32. software driven. operating on diverse physical variables and in diverse environments and sold into a competitive and cost conscious market. High-end embedded system .embedded system is a microcontroller-based. High-end embedded & lower end embedded systems. autonomous. reliable. An embedded system is not a computer system that is used primarily for processing.16 Bit Controllers used with an minimal operating systems and hardware layout designed for the specific purpose. real-time control system. not a traditional business or scientific application.

– Throughput – Our system may need to handle a lot of data in a short period of time. – Reliability – embedded systems must be able to handle any situation without human intervention. finding out what the software is doing wrong (other than not working) is a troublesome problem. and the software in these systems must conserve power. • They will encounter a number of difficulties when writing embedded system software in addition to those we encounter when we write applications. 12 .Har Sy dw ste are m Rapi -inDef d the init Prot ion otypi Lo Targ ng op eting Tes tin g Sy ste m Tes tin g Figure 2(b):“V Diagram” Characteristics of Embedded System • An embedded system is any computer system hidden inside a product other than a computer. – Debugability–Without a screen or a keyboard. – Testability–Setting up equipment to test embedded software can be difficult. – Program installation – you will need special tools to get your software into embedded systems. – Memory space – Memory is limited on embedded systems. – Response–Our system may need to react to events quickly. – Processor hogs – computing that requires large amounts of CPU time can complicate the response problem. and you must make the software and the data fit into whatever memory exists. – Power consumption – Portable systems must run on battery power.

APPLICATIONS 1) 2) 3) 4) 5) 6) 7) Military and aerospace embedded software applications C o mmu n i ca t io n App l ic a t io ns I nd us t r ia l au to ma t io n a nd p ro ce s s c on tr o l s o ft w a re Mastering the complexity of applications.  RTS is one which has to respond to events within a specified deadline. 13 . • Embedded systems have a microprocessor/ microcontroller and a memory. Cardiac pacemaker. They usually do not have keyboards. Reduction of product design time. Some have a serial port or a network connection. screens or disk drives. Intelligent.– Cost – Reducing the cost of the hardware is a concern in many embedded system projects. autonomous sensors. CLASSIFICATION  Real Time Systems.  Example: Nuclear power system. SOFT REAL TIME SYSTEM  "Soft" real-time systems have reduced constrains on "lateness" but still must operate very quickly and repeatable. software often operates on hardware that is barely adequate for the job. RTS CLASSIFICATION  Hard Real Time Systems  Soft Real Time System HARD REAL TIME SYSTEM  "Hard" real-time systems have very narrow response time.  Example: Railway reservation system – takes a few extra seconds the data remains valid. Real time processing of ever increasing amounts of data.  A right answer after the dead line is a wrong answer.

BLOCK DIAGRAM 14 .3.

1: project block diagram 15 .Fig 3.

4. TRANSFORMER (230 – 12 V AC) 16 .HARDWARE REQUIREMENTS HARDWARE COMPONENTS: 1.

RELAY 7. FILTER 5. CAPACITORS 4. RESISTORS 14. LED 12. RECTIFIER 4. MICROCONTROLLER (AT89S52/AT89C51) 6. ULN2003 10. LCD 9. Most 17 . LOAD 13.2. step-down transformers reduce voltage. Step-up transformers increase voltage. 1N4007 11. PUSH BUTTONS 8. VOLTAGE REGULATOR (LM 7805) 3.1 TRANSFORMER Transformers convert AC electricity from one voltage to another with a little loss of power.

power supplies use a step-down transformer to reduce the dangerously high voltage to a safer low voltage. Note that as voltage is stepped down and current is stepped up. Transformers waste very little power so the power out is (almost) equal to the power in. TURNS RATIO = (Vp / Vs) = ( Np / Ns ) Where. The ratio of the number of turns on each coil. and a small number of turns on its secondary (output) coil to give a low output voltage. A step-down transformer has a large number of turns on its primary (input) coil which is connected to the high voltage mains supply. The two lines in the middle of the circuit symbol represent the core. instead they are linked by an alternating magnetic field created in the soft-iron core of the transformer. There is no electrical connection between the two coils. determines the ratio of the voltages. Vs = secondary (output) voltage Np = number of turns on primary coil Ns = number of turns on secondary coil Ip = primary (input) current Is = secondary (output) current. called the turn’s ratio.1: A TYPICAL TRANSFORMER The input coil is called the primary and the output coil is called the secondary. FIG 4. Ideal power equation 18 . Vp = primary (input) voltage.

This relationship is reciprocal. all the incoming energy is transformed from the primary circuit to the magnetic field and into the secondary circuit. If this condition is met. the transformer is perfectly efficient. so that the impedance Zp of the primary circuit appears to the secondary to be (Ns/Np)2Zp. electrical power is transmitted from the primary circuit to the secondary circuit.2 VOLTAGE REGULATOR 7805 19 .The ideal transformer as a circuit element If the secondary coil is attached to a load that allows current to flow. Ideally. 4. it appears to the primary circuit to have an impedance of (Np/Ns)2Zs. the incoming electric power must equal the outgoing power: Giving the ideal transformer equation Transformers normally have high efficiency. If the voltage is increased. For example. so this formula is a reasonable approximation. The impedance in one circuit is transformed by the square of the turns ratio. then the current is decreased by the same factor. if an impedance Zs is attached across the terminals of the secondary coil.

6. 8. 18. Each type employs internal current limiting. these devices can be used with external components to obtain adjustable voltages and currents. making it essentially indestructible. 15. 9. • Short Circuit Protection. • Output Voltages of 5. Internal Block Diagram 20 . Description The LM78XX/LM78XXA series of three-terminal positive regulators are available in the TO-220/D-PAK package and with several fixed output voltages. Although designed primarily as fixed voltage regulators. If adequate heat sinking is provided. making them useful in a Wide range of applications. 12.Features • Output Current up to 1A. • Output Transistor Safe Operating Area Protection. they can deliver over 1A output Current. 24V. thermal shutdown and safe operating area protection. • Thermal Overload Protection. 10.

2(b): RATINGS OF THE VOLTAGE REGULATOR 21 .2(a): BLOCK DIAGRAM OF VOLTAGE REGULATOR Absolute Maximum Ratings TABLE 4.FIG 4.

4.C. into pulsating D. current that flows in only one direction. Output received from this filter is constant until the mains 22 . 4. in negative half cycle remaining two diodes will conduct and they will conduct only in forward bias only. Rectifiers may be made of solid state diodes. which periodically reverses direction.C. The output from the transformer is fed to the rectifier. vacuum tube diodes. Rectifiers have many uses including as components of power supplies and as detectors of radio signals. It removes the ripples from the output of rectifier and smoothens the D.4 FILTER Capacitive filter is used in this project. In positive half cycle only two diodes( 1 set of parallel diodes) will conduct. a bridge rectifier is used because of its merits like good stability and full wave rectification. It converts A.3 RECTIFIER A rectifier is an electrical device that converts alternating current (AC). a process known as rectification. The rectifier may be a half wave or a full wave rectifier. mercury arc valves. and other components.C. to direct current (DC). In this project.

two data pointers.voltage and load is maintained constant. on-chip oscillator. high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip. The use of this filter is very limited. The device is manufactured using Atmel’s high-density non volatile memory technology and is compatible with the industry standard 80C51 instruction set and pin out. 4. Therefore a regulator is applied at the output stage. three 16-bit timer/counters. The AT89S52 provides the following standard features: 8K bytes of Flash. low-current power supplies for cathode-ray and similar electron tubes that require very little load current from the supply. 32 I/O lines. the 23 . and clock circuitry. voltage received at this point changes. a six-vector two-level interrupt architecture. a full duplex serial port.C. This filter is also used in circuits where the power-supply ripple frequency is not critical and can be relatively high. 256 bytes of RAM. Watchdog timer. Below figure can show how the capacitor changes and discharges. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional non volatile memory programmer.5 MICROCONTROLLER AT89S52 The AT89S52 is a low-power. However. D. In addition. if either of the two is varied. the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and costeffective solution to many embedded control applications. The simple capacitor filter is the most basic type of power supply filter. It is sometimes used on extremely high-voltage.

Features: • Compatible with MCS®-51 Products • 8K Bytes of In-System Programmable (ISP) Flash Memory – Endurance: 10.AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes.000 Write/Erase Cycles • 4. The Powerdown mode saves the RAM contents but freezes the oscillator. and interrupt system to continue functioning.0V to 5. timer/counters. disabling all other chip functions until the next interrupt or hardware reset.5V Operating Range • Fully Static Operation: 0 Hz to 33 MHz • Three-level Program Memory Lock • 256 x 8-bit Internal RAM • 32 Programmable I/O Lines • Three 16-bit Timer/Counters • Eight Interrupt Sources • Full Duplex UART Serial Channel • Low-power Idle and Power-down Modes • Interrupt Recovery from Power-down Mode • Watchdog Timer • Dual Data Pointer • Power-off Flag • Fast Programming Time • Flexible ISP Programming (Byte and Page Mode) • Green (Pb/Halide-free) Packaging Option Block Diagram of AT89S52: 24 . The Idle Mode stops the CPU while allowing the RAM. serial port.

FIG 4.5(A): BLOCK DIAGRAM OF AT89S52 Pin Configurations of AT89S52 25 .

5(b): PIN DIAGRAM OF AT89S52 Pin Description: VCC: Supply voltage. the pins can be used as highimpedance inputs. As inputs. When 1s are written to Port 1 pins. each pin can sink eight TTL inputs. External pull-ups are required during program verification. The Port 1 output buffers can sink/source four TTL inputs. Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. When 1s are written to port 0 pins. Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. Port 0 can also be configured to be the multiplexed low-order address/data bus during accesses to external program and data memory. In this mode. As an output port. GND: Ground Port 0: Port 0 is an 8-bit open drain bidirectional I/O port.FIG 4. they are pulled high by the internal pull-ups and can be used as inputs. P0 has internal pullups. Port 1 pins that are 26 .

they are pulled high by the internal pull-ups and can be used as inputs. This pin is also the program pulse input (PROG) during Flash programming. Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. Note. PSEN is activated twice each 27 . In the default state of bit DISRTO.1/T2EX). As inputs. Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups. that one ALE pulse is skipped during each access to external data memory. the RESET HIGH out feature is enabled. When 1s are written to Port 3 pins.0 and P1. ALE is emitted at a constant rate of 1/6 the oscillator frequency and may be used for external timing or clocking purposes.externally being pulled low will source current (IIL) because of the internal pull-ups. In normal operation. however. When 1s are written to Port 2 pins. During accesses to external data memory that uses 8-bit addresses (MOVX @ RI).0/T2) and the timer/counter 2 trigger input (P1. In this application. PSEN: Program Store Enable (PSEN) is the read strobe to external program memory.1 can be configured to be the timer/counter 2 external count input (P1. The Port 3 output buffers can sink/source four TTL inputs. ALE/PROG: Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during accesses to external memory. In addition. A high on this pin for two machine cycles while the oscillator is running resets the device. The Port 2 output buffers can sink/source four TTL inputs. Port 2 emits the contents of the P2 Special Function Register. P1. This pin drives high for 98 oscillator periods after the Watchdog times out. As inputs. RST: Reset input. Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. When the AT89S52 is executing code from external program memory. they are pulled high by the internal pull-ups and can be used as inputs. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that uses 16-bit addresses (MOVX @ DPTR). The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. Port 2 uses strong internal pull-ups when emitting 1s.

EA should be strapped to VCC for internal program executions. There are no requirements on the duty cycle of the external clock signal. EA will be internally latched on reset. FIG 4. Oscillator Characteristics: XTAL1 and XTAL2 are the input and output. Note. that if lock bit 1 is programmed. however. XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2: Output from the inverting oscillator amplifier. as shown in Figure 1.5(c): Oscillator Connections 28 . Either a quartz crystal or ceramic resonator may be used. XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure 6. but minimum and maximum voltage high and low time specifications must be observed. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming. To drive the device from an external clock source. of an inverting amplifier which can be configured for use as an on-chip oscillator.machine cycle. EA/VPP: External Access Enable. respectively. since the input to the internal clocking circuitry is through a divide-by-two flip-flop.2. except that two PSEN activations are skipped during each access to external data memory. EA must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH.

the CPU puts itself to sleep while all the on chip peripherals remain active. The reset should not be activated before VCC is restored to its normal operating level and must be held active long enough to allow the oscillator to restart and stabilize. The collector-current rating of a single Darlington pair is 500mA. 4. DESCRIPTION: The ULN2003 is a monolithic high voltage and high current Darlington transistor arrays. Reset redefines the SFRs but does not change the on-chip RAM. and the instruction that invokes power down is the last instruction executed. The mode is invoked by software.5(d): External Clock Drive Configuration Idle Mode In idle mode. The content of the on-chip RAM and all the special functions registers remain unchanged during this mode. The only exit from power down is a hardware reset. It consists of seven NPN Darlington pairs that feature high-voltage outputs with common-cathode Clamp diode for switching inductive loads. Power down Mode In the power down mode the oscillator is stopped. The idle mode can be terminated by any enabled interrupt or by a hardware reset.FIG 4. The on-chip RAM and Special Function Registers retain their values until the power down mode is terminated. The Darlington pairs may be paralleled for higher current 29 .6 ULN2003 RELAY DRIVER: ULN2003 is a high voltage and high current Darlington transistor array.

lamp drivers. display drivers (LED gas discharge).7kW series base resistor for each Darlington pair for operation directly with TTL or 5V CMOS devices.capability. and logic buffers. hammer drivers. The ULN2003 has a 2. Fig: ULN 2003 30 . Applications include relay drivers. line drivers.

Input Max:5V Voltage. No. Output Max:50V 31 . CMOS 5V Logic Function Number:2003 Output Type: Open Collector Transistor Type: Power Darlington Voltage. Output Max:500mA Device Marking:ULN2003A IC Generic Number:2003 Input Type: TTL. No. of:7 Current. Min:-20°C Temp.FEATURES:                   Pin no. Op. of:7 Case Style:DIP-16 Temp. Op.:16 Temperature. Operating Range:-20°C to +85°C Transistor Polarity: NPN Transistors. Max:85°C Base Number:2003 Channels.

PIN Diagram: 32 .

Fig: Schematics of Darlington’s pair 33 .

. The first transistor’s emitter feeds into the second transistor’s base and as a result the input signal is amplified by the time it reaches the output.Fig: Darlington pair Darlington pairs are back to back connection of two transistors with some source resistors and when they are arranged as shown in the circuit they are used to amplify weak signals. Inputs pinned opposite to outputs Simplified layout Figure shows the Darlington pair connection of transistor. The important point to remember is that the Darlington Pair is made up of two transistors FEATURES * 500mA rated collector current (Single output). The circuit above is a ‘Darlington Pair’ driver. 34 . The amount by which the weak signal is amplified is called the ‘GAIN’. FEATURES OF DRIVER:        Seven Darlington’s per package Output currents500mA per driver(600mA peak) Integrated suppression diodes for inductive loads Outputs can be paralleled for high currents TTL/CMOS/PMOS/DTL compatible inputs.

Current flowing through the coil of the relay creates a magnetic field which attracts a lever and changes the switch contacts. A relay is an electrically operated switch. 4. The coil current can be on or off so relays have two switch positions and most have double throw (changeover) switch contacts as shown in the diagram. * Inputs compatible with various types of logic. 35 . Relays are used where it is necessary to control a circuit by a low-power signal (with complete electrical isolation between control and controlled circuits).7 RELAY A relay is an electrically operated switch. but other operating principles are also used.* High-voltage outputs: 50V. or where several circuits must be controlled by one signal. Many relays use an electromagnet to operate a switching mechanism mechanically. * Relay driver application.

for example relays with 4 sets of changeover contacts are readily available. Relays are usually SPDT or DPDT but they can have many more sets of switch contacts.8 Relay showing coil and switch contacts Relays allow one circuit to switch a second circuit which can be completely separate from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. For further information about switch contacts and the terms used to describe them please see the page on switches. Most ICs (chips) cannot provide this current and a transistor is usually used to amplify the small IC current to the larger value required for the relay coil. the link is magnetic and mechanical. typically 30mA for a 12V relay. but it can be as much as 100mA for relays designed to operate from lower voltages. 36 . The coil of a relay passes a relatively large current. The maximum output current for the popular 555 timer IC is 200mA so these devices can supply relay coils directly without amplification.Fig 4. There is no electrical connection inside the relay between the two circuits.

To prevent damage you must connect a protection diode across the relay coil. 37 . The figure shows a relay with its coil and switch contacts. Relay coils produce brief high voltage 'spikes' when they are switched off and this can destroy transistors and ICs in the circuit. You can see a lever on the left being attracted by magnetism when the coil is switched on. The coil will be obvious and it may be connected either way round. This lever moves the switch contacts.Most relays are designed for PCB mounting but you can solder wires directly to the pins providing you take care to avoid melting the plastic case of the relay. The supplier's catalogue should show you the relay's connections.

always connect to this. COM is connected to this when the relay coil is off. NC and NO:  COM = Common.  NC = Normally Closed. it is the moving part of the switch. The relay's switch connections are usually labelled COM.There is one set of contacts (SPDT) in the foreground and another behind them. 38 . COM is connected to this when the relay coil is on.  NO = Normally Open. making the relay DPDT.

though even many un-biased buttons (due to their physical nature) require a spring 39 . usually plastic or metal. Relays can be modified to delay opening or delay closing a set of contacts. A very short (a fraction of a second) delay would use a copper disk between the armature and moving blade assembly. as in some types of modems or audio amplifiers. The surface is usually flat or shaped to accommodate the human finger or hand. lengthening release time.7(a): Push Buttons A push-button (also spelled pushbutton) or simply button is a simple switch mechanism for controlling some aspect of a machine or a process. so as to be easily depressed or pushed.  Detect and isolate faults on transmission and distribution lines by opening and closing circuit breakers. a dashpot is used. For longer time periods. a mechanical clockwork timer is installed. A dashpot is a piston filled with fluid that is allowed to escape slowly.Applications of relays Relays are used to and for:  Control a high-voltage circuit with a low-voltage signal.4.8 PUSH BUTTONS Fig. Buttons are most often biased switches.  Time delay functions. 4. as in the starter solenoid of an automobile. Buttons are typically made out of hard material.  Control a high-current circuit with a low-current signal. For a slightly longer (up to a minute) delay. The time period can be varied by increasing or decreasing the flow rate. Current flowing in the disk maintains magnetic field for a short time.

mash. These pushbuttons are called emergency stop buttons and are mandated by the electrical code in many jurisdictions for increased safety. 40 . depress. Uses: In industrial and commercial applications push buttons can be linked together by a mechanical linkage so that the act of pushing one button causes the other button to be released. In this way a start button when pushed will cause the process or machine operation to be started and a secondary contact designed into the operation or process will close to turn on the pilot light and signify the action of pushing the button caused the resultant process or action to start. Typically this light is included into the center of the pushbutton and a lens replaces the pushbutton hard center disk. Different people use different terms for the "pushing" of the button. This method of linkage is used in simple manual operations in which the machine or process have no electrical circuits for control. In this way. a pilot light is commonly added to draw the attention of the user and to provide feedback if the button is pushed. The source of the energy to illuminate the light is not directly tied to the contacts on the back of the pushbutton but to the action the pushbutton controls. such as press. the phrase "the button" refers to a (usually fictional) button that a military or government leader could press to launch nuclear weapons. Commonly used colors are red for stopping the machine or process and green for starting the machine or process. a stop button can "force" a start button to be released. This large mushroom shape can also be found in buttons for use with operators who need to wear gloves for their work and could not actuate a regular flush-mounted push button. In popular culture. Pushbuttons are often color-coded to associate them with their function so that the operator will not push the wrong button in error. Red pushbuttons can also have large heads (mushroom shaped) for easy operation and to facilitate the stopping of a machine. As an aid for operators and users in industrial or commercial applications. and punch.to return to their un-pushed state.

This makes the switching operation using the push button. as all the logic required running them is on board. When the button is pressed they become connected. and are quite simple to work with. Pros:  Very compact and light  Low power consumption  No geometric distortion  Little or no flicker depending on backlight technology  Not affected by screen burn-in  No high voltage or other hazards present during repair/service  Can be made in almost any size or shape 41 . 4.7(b): push on button Initially the two contacts of the button are open.4. This example doesn't use the Bidirectional feature found on newer ports.Push to ON button: Fig. It however doesn't show the use of the Status Port as an input for a 16 Character x 2 Line LCD Module to the Parallel Port. thus it should work with most.9 LIQUID CRYSTAL DISPLAY (LCD) Description: This is the example for the Parallel Port. These LCD Modules are very common these days. if not all Parallel Ports.

respectively. which refers to the controller chip which receives data from an external source (in this case. a very popular standard exists which allows us to communicate with the vast majority of LCDs regardless of their manufacturer. 42 . If an 8-bit data bus is used the LCD will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus). FIG 4. the 8051) and communicates directly with the LCD. The standard is referred to as HD44780U. Fortunately. No theoretical resolution limit LCD Background: Frequently. One of the most common devices attached to an 8051 is an LCD display. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. This means 16 characters per line by 2 lines and 20 characters per line by 2 lines. an 8051 program must interact with the outside world using input and output devices that communicate directly with a human being. Some of the most common LCDs connected to the 8051 are 16x2 and 20x2 displays.10: LCD 44780 LCD BACKGROUND The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for the data bus).

The RS line is the "Register Select" line. In the case of an 8-bit data bus. DB1. DB4. The EN line is called "Enable. the data is to be treated as a command or special instruction (such as clear screen. and end by bringing it low (0) again. the data bus consists of 4 or 8 lines (depending on the mode of operation selected by the user). To send data to the LCD. and RW. the information on the data bus is being written to the LCD. DB6. the data being sent is text data which should be displayed on the screen. position cursor. DB3. etc. your program should make sure this line is low (0) and then set the other two control lines and/or put data on the data bus. When RW is high (1).Finally. to display the letter "T" on the screen you would set RS high. All others are write commands--so RW will almost always be low . When RS is high (1). bring EN high (1) and wait for the minimum amount of time required by the LCD datasheet (this varies from LCD to LCD)." This control line is used to tell the LCD that you are sending it data. DB2. the program is effectively querying (or reading) the LCD. When RS is low (0). The RW line is the "Read/Write" control line. When RW is low (0). For example. Only one instruction ("Get LCD status") is a read command. 43 . RS. DB5. the lines are referred to as DB0. When the other lines are completely ready.The three control lines are referred to as EN. and DB7.).

Maximum forward voltage capacity Fig: 1N4007 diodes The number and voltage capacity of some of the important diodes available in the market are as follows:  Diodes of number IN4001. 44 .4. IN4005. IN4004. in place of IN4002. 1. IN4003. IN4001 or IN4007 can be used but IN4001 or IN4002 cannot be used in place of IN4007.10 1N4007 Diodes are used to convert AC into DC these are used as half wave rectifier or full wave rectifier. Maximum reverse voltage capacity 3. Besides this diode of more capacity can be used in place of diode of low capacity but diode of low capacity cannot be used in place of diode of high capacity.  Diode of same capacities can be used in place of one another.The diode BY125made by company BEL is equivalent of diode from IN4001 to IN4003. For example. IN4006 and IN4007 have maximum reverse bias voltage capacity of 50V and maximum forward current capacity of 1 Amp. Maximum forward current capacity 2. Three points must he kept in mind while using any type of diode. BY 126 is equivalent to diodes IN4004 to 4006 and BY 127 is equivalent to diode IN4007. IN4002.

Therefore.and N-type materials. with voltage applied across the material. Current Flow in the N-Type Material Conduction in the N-type semiconductor. electrons will move through the crystal just as current would flow in a copper wire. we must first consider current flow in the materials that make up the junction and what happens initially within the junction when these two materials are joined together. and the function of the diode. 45 .Fig:PN Junction diode PN JUNCTION OPERATION Now that you are familiar with P. As an electron leaves the crystal. how these materials are joined together to form a diode. let us continue our discussion with the operation of the PN junction. or crystal. thus completing the current path. These electrons will leave the crystal and flow into the positive terminal of the battery. The positive potential of the battery will attract the free electrons in the crystal. an electron from the negative terminal of the battery will enter the crystal. is similar to conduction in a copper wire. the majority current carriers in the N-type material (electrons) are repelled by the negative side of the battery and move through the crystal toward the positive side of the battery. But before we can understand how the PN junction works. This is shown in figure 1-15. That is.

At the positive terminal. What makes an LED give off light are the small amounts of chemical impurities that are added to the silicon. This process continues as the steady stream of holes (hole current) moves toward the negative terminal 4. A hole moves from the positive terminal of the P material to the negative terminal. There are also LEDs in extremely 46 .11(b): circuit symbol Not long ago LEDs were only bright enough to be used as indicators on dashboards or electronic equipment.11(a): Typical LED Fig 4. they are far more efficient than incandescent bulbs. arsenide. Types of LED’S LEDs are produced in an array of shapes and sizes.11 LED LEDs are semiconductor devices. Modern LEDs can replace incandescent bulbs in almost any application. Electrons from the external circuit enter the negative terminal of the material and fill holes in the vicinity of this terminal. For instance. The color of the plastic lens is often the same as the actual color of light emitted.Current Flow in the P-Type Material Current flow through the P-type material is illustrated. electrons are removed from the covalent bonds. But recent advances have made LEDs bright enough to rival traditional lighting technologies. When current passes through the LED. estimated at 80% of world production. and other diodes. Like transistors. LEDs produce photons directly and not via heat. thus creating new holes. indium. instead of negative electrons. Normal light bulbs produce light by heating a metal filament until it is white hot. but not always. it emits photons as a byproduct. such as gallium. Fig 4. The 5 mm cylindrical package is the most common. LEDs are made out of silicon. and nitride. Conduction in the P material is by positive holes. purple plastic is often used for infrared LEDs. and most blue devices have clear housings.

high power devices and custom designs such as alphanumeric or multi-color. They are extremely commonplace in most electronic equipment.11(c) Different types of LED’S 4.12 RESISTORS A resistor is a two-terminal electronic component designed to oppose an electric current by producing a voltage drop between its terminals in proportion to the current. in accordance with Ohm's law: V = IR Resistors are used as part of electrical networks and electronic circuits. Other characteristics include temperature coefficient. The main types of LEDs are miniature. noise. Fig 4. it's determined by design. such as those found on blinkers and on cell phone keypads. The primary characteristics of resistors are their resistance and the power they can dissipate. as well as resistance wire (wire made of a high-resistivity alloy. and above which the limit is applied voltage.tiny packages. Less well-known is critical resistance. such as nickel/chrome). that is. the value below which power dissipation limits the maximum permitted current flow. and inductance. 47 . Practical resistors can be made of various compounds and films. Critical resistance depends upon the materials constituting the resistor as well as its physical dimensions.

Resistors are also implemented within integrated circuits. A resistor is a two-terminal passive electronic component which implements electrical resistance as a circuit element. according to its specific application. When a voltage V is applied across the terminals of a resistor. Size. particularly analog devices. as well as resistance wire (wire made of a high-resistivity alloy. Practical resistors can be made of various compounds and films. and can also be integrated into hybrid and printed circuits. as well as integrated circuits. with a given voltage V. When specifying that resistance in an electronic design. and position of leads (or terminals) are relevant to equipment designers. The temperature coefficient of the resistance may also be 48 . a larger value of R further "resists" the flow of current I as given by Ohm's law: Resistors are common elements of electrical networks and electronic circuits and are ubiquitous in most electronic equipment. The electrical functionality of a resistor is specified by its resistance: common commercial resistors are manufactured over a range of more than 9 orders of magnitude. a current I will flow through the resistor in direct proportion to that voltage. since. The reciprocal of the constant of proportionality is known as the resistance R. resistors must be physically large enough not to overheat when dissipating their power. such as nickel-chrome).Resistors can be integrated into hybrid and printed circuits. the required precision of the resistance may require attention to the manufacturing tolerance of the chosen resistor.

Practical resistors are also specified as having a maximum power rating which must exceed the anticipated power dissipation of that resistor in a particular circuit: this is mainly of concern in power electronics applications. The unwanted inductance. Units The ohm (symbol: Ω) is the SI unit of electrical resistance. In a low-noise amplifier or pre-amp the noise characteristics of a resistor may be an issue. Thus a Siemens is the reciprocal of an ohm: S = Ω − 1. In a high voltage circuit. named after Georg Simon Ohm. practical resistors are always specified in terms of their resistance (ohms) rather than conductance. Although the concept of conductance is often used in circuit analysis. that is. 4. attention must sometimes be paid to the rated maximum working voltage of the resistor. An ohm is equivalent to a volt per ampere. and temperature coefficient are mainly dependent on the technology used in manufacturing the resistor. the derived units of milliohm (1 mΩ = 10 −3 Ω).[1] A family of discrete resistors is also characterized according to its form factor. The reciprocal of resistance R is called conductance G = 1/R and is measured in Siemens (SI unit). Resistors with higher power ratings are physically larger and may require heat sinking. sometimes referred to as a mho.13 CAPACITORS 49 . this specification can be important in some high-frequency applications for smaller values of resistance. excess noise.of concern in some precision applications. and megohm (1 MΩ = 106 Ω) are also in common usage. kilohm (1 kΩ = 103 Ω). The series inductance of a practical resistor causes its behavior to depart from ohms law. Since resistors are specified and manufactured over a very large range of values. the size of the device and position of its leads (or terminals) which is relevant in the practical manufacturing of circuits using them. They are not normally specified individually for a particular family of resistors manufactured using a particular technology.

in the resonant circuits that tune radios to particular frequencies and for many other purposes. 50 . and many other important aspects. When a voltage potential difference exists between the conductors. This is the ratio of the electric charge on each conductor to the potential difference between them. for example. This field stores energy and produces a mechanical force between the plates. A capacitor (formerly known as condenser) is a device for storing electric charge. The effect is greatest between wide. parallel. The properties of capacitors in a circuit may determine the resonant frequency and quality factor of a resonant circuit. the dielectric between the plates passes a small amount of leakage current. for smoothing the output of power supplies.A capacitor or condenser is a passive electronic component consisting of a pair of conductors separated by a dielectric. energy capacity in a high-power system. An ideal capacitor is characterized by a single constant value. Capacitors are widely used in electronic circuits for blocking direct current while allowing alternating current to pass. Capacitors used as parts of electrical systems. power dissipation and operating frequency in a digital logic circuit. which is measured in farads. narrowly separated conductors. capacitance. an electric field is present in the dielectric. but all contain at least two conductors separated by a non-conductor. in filter networks. The forms of practical capacitors vary widely. The conductors and leads introduce an equivalent series resistance and the dielectric has an electric field strength limit resulting in a breakdown voltage. In practice. flat. consist of metal foils separated by a layer of insulating film.

a static electric field develops in the dielectric that stores energy and produces a mechanical force between the conductors. referring to an early means of construction.A capacitor is a passive electronic component consisting of a pair of conductors separated by a dielectric (insulator). while the conductors and leads introduce an undesired inductance and resistance. 51 . In practice the dielectric between the plates passes a small amount of leakage current and also has an electric field strength limit. The capacitance is greatest when there is a narrow separation between large areas of conductor. An ideal capacitor is characterized by a single constant value. resulting in a breakdown voltage. capacitance. A dielectric (orange) reduces the field and increases the capacitance. This is the ratio of the electric charge on each conductor to the potential difference between them. When there is a potential difference (voltage) across the conductors. measured in farads. Theory of operation Main article: Capacitance Charge separation in a parallel-plate capacitor causes an internal electric field. hence capacitor conductors are often called "plates".

[9] and the dielectric develops an electric field. and hence the amount of energy stored. air. a capacitance of one farad means that one coulomb of charge on each conductor causes a voltage of one volt across the device. vacuum.A simple demonstration of a parallel-plate capacitor A capacitor consists of two conductors separated by a non-conductive region[8]. In simpler terms. An ideal capacitor is wholly characterized by a constant capacitance C. defined as the ratio of charge ±Q on each conductor to the voltage V between them:[8] Sometimes charge build-up affects the capacitor mechanically. Examples of dielectric mediums are glass. with no net electric charge and no influence from any external electric field. When the external influence is removed the charge separation persists in the electric field and energy is stored to be released when the charge is allowed to return to its equilibrium position.[10] The capacitor is a reasonably general model for electric fields within electric circuits. The conductors thus hold equal and opposite charges on their facing surfaces. In this case. capacitance is defined in terms of incremental changes: Energy storage Work must be done by an external influence to "move" charge between the conductors in a capacitor. is given by:[11] 52 . The nonconductive region is called the dielectric or sometimes the dielectric medium. causing its capacitance to vary. The work done in establishing the electric field. the dielectric is just an electrical insulator. paper. and even a semiconductor depletion region chemically identical to the conductors. A capacitor is assumed to be self-contained and isolated. In SI units.

[12] . The dual of the capacitor is the inductor. resulting in an electron depletion and consequent positive charge on one electrode that is equal and opposite to the accumulated negative charge on the other. As with any antiderivative. rather an electron accumulates on the negative plate for each one that leaves the positive plate. This is the integral form of the capacitor equation. electrons. Its current-voltage relation is obtained by exchanging current and voltage in the capacitor equations and replacing C with the inductance L. which stores energy in the magnetic field rather than the electric field. 53 . Thus the charge on the electrodes is equal to the integral of the current as well as proportional to the voltage as discussed above. a constant of integration is added to represent the initial voltage v (t0). yields the derivative form. Taking the derivative of this. but actual charges.Current-voltage relation The current i(t) through any component in an electric circuit is defined as the rate of flow of a charge q(t) passing through it. cannot pass through the dielectric layer of a capacitor.[13] . and multiplying by C.

54 .

SOFTWARE REQUIREMENTS 55 .5.

integrated environments. Keil development tools for the 8051 Microcontroller Architecture support every level of software developer from the professional applications engineer to the student just learning about embedded software development. I. real-time kernels. linker. simulators. and 8051 MCU families. evaluation boards. simply select the microcontroller you use from the Device Database and the µVision IDE sets all compiler.5. Keil is a cross compiler.1 INTRODUCTION TO KEIL MICRO VISION (IDE) Keil an ARM Company makes C compilers. So first we have to understand the concept of compilers and cross compilers. After then we shall learn how to work with keil. Desktop compilers produce an output object code for the underlying microprocessor. assembler. When starting a new project. debuggers.2 CONCEPT OF COMPILER Compilers are programs used to convert a High Level Language to object code. and memory options for you. 251. but not for other microprocessors.E the programs written in one of the HLL like ‘C’ will compile the code to run on the system for a particular processor like x86 (underlying microprocessor 56 . and emulators for ARM7/ARM9/Cortex-M3. XC16x/C16x/ST10. 5. macro assemblers.

Interpreter just interprets whole program at a time while compiler analyses and execute each line of source code in succession. looking at the entire piece of source code and collecting and reorganizing the instruction.in the computer). However compilers require some time before an executable program emerges. 5. So the definition of cross compiler is a compiler that runs on one computer but produces object code for a different type of computer. See there is a bit little difference between compiler and an interpreter. which is unique for each type of computer. without looking at the entire program. For example compilers for Dos platform is different from the Compilers for Unix platform So if one wants to define a compiler then compiler is a program that translates source code into object code.3 CONCEPT OF CROSS COMPILER A cross compiler is similar to the compilers but we write a program for the target processor (like 8051 and its derivatives) on the host processors (like computer of x86). many compilers are available for the same language. 5.4 KEIL C CROSS COMPILER 57 . The advantage of interpreters is that they can execute a program immediately. The compiler derives its name from the way it works. It means being in one environment you are writing a code for another environment is called cross development. Secondly programs produced by compilers run much faster than the same programs executed by an interpreter. Now as compilers translate source code into object code. And the compiler used for cross development is called cross compiler.

assembles.5 Building an Application in µVision2 To build (compile. Locator/Linker The Keil ARM tool kit includes three main tools. A compiler is used to compile the C source code into an object file.New Project. you must: 1 Select Project . you must: 1 Select Project -(forexample. assemble.µVision2 compiles.Keil is a German based Software development company.UV2). Cross Assembler. and link) an application in µVision2. 5. 2 Select Project . A linker is used to create an absolute object module suitable for our in-circuit emulator. An assembler is used to assemble the ARM assembly program. and links the files in your project. It provides several development tools like • IDE (Integrated Development environment) • Project Manager • Simulator • Debugger • C Cross Compiler. 2 Select a directory and enter the name of the project file. or C16x/ST10 device from the Device Database™. 58 .6 Creating Your Own Application in µVision2 To create a new project in µVision2.Rebuild all target files or Build target. compiler and linker. 3 Select Project . assembler. 251. 5.Select Device and select an 8051.166\EXAMPLES\HELLO\HELLO. 4 Create source files to add to the project.

We suggest that you use a separate folder for each project.9 Window – Files. 5. You may enter G. Go.Options and set the tool options. 59 . Files. 6 Select Project . 3 Open the Serial Window using the Serial #1 button on the toolbar. You typically only need to configure the memory map of your target hardware. You can see these names in the Project. µVision2 creates a new project file with the name PROJECT1. main in the Output Window to execute to the main C function. Then select this folder and enter the file name for the new project. The Select Device dialog box shows the µVision2 device data base.UV2 which contains a default target and file group name. Break.8 Starting µVision2 and Creating a Project µVision2 is a standard Windows application and started by clicking on the program icon. 5. Now use from the menu Project – Select Device for Target and select a CPU for your project. 5. 7 Select Project . and so on. To create a new project file select from the µVision2 menu Project – New Project…. Debug your program using standard options like Step. you must: 1 Select Debug . This opens a standard Windows dialog that asks you for the new project file name.e. and add the source files to the project.7 Debugging an Application in µVision2 To debug an application created using µVision2. Default memory model settings are optimal for most applications.Targets.5 Select Project . This selection sets necessary tool Options for the 80C51RD+ device and simplifies in this way the tool Configuration. Project1.Start/Stop Debug Session. We are using for our examples the Philips 80C51RD+ CPU. You can simply use the icon Create New Folder in this dialog to get a new empty folder.Rebuild all target files or Build target. Add/Files. Groups. i. Just select the microcontroller you use. 2 Use the Step toolbar buttons to single-step through your program. Note when you select the target device from the Device Database™ all special options are set automatically. select Source Group1.

the tool settings under Options – Target are all you need to start a new application.13 Start Debugging You start the debug mode of µVision2 with the Debug – Start/Stop Debug Session Command. µVision2 will display errors and warning messages in the Output Window – Build page. µVision2 will load the application program and run the startup code µVision2 saves the editor screen 60 . When you build an application with syntax errors. Depending on the Options for Target – Debug Configuration. 5.5. or code execution access.10 Building Projects and Creating a HEX Files Typical. µVision2 creates HEX files with each build process when Create HEX files under Options for Target – Output is enabled. Once you have successfully generated your application you can start debugging. You may select and display the on-chip peripheral components using the Debug menu. The µVision2 simulator traps and reports illegal memory accesses. A double click on a message line opens the source file on the correct location in a µVision2 editor window. it is required to create an Intel HEX file to download the software into an EPROM programmer or simulator.12 Database selection You have made when you create your project target. the simulator also provides support for the integrated peripherals of the various 8051 derivatives. Refer to page 58 for more Information about selecting a device. write. You can also change the aspects of each peripheral using the controls in the dialog boxes. You may start your PROM programming utility after the make process when you specify the program under the option Run User Program #1. The on-chip peripherals of the CPU you have selected are configured from the Device. You may translate all source files and line the application with a click on the Build Target toolbar icon.11 CPU Simulation µVision2 simulates up to 16 Mbytes of memory from which areas can be mapped for read. 5. After you have tested your application. In addition to memory mapping. 5.

most editor features are still available. Simulation helps you understand hardware configurations and avoids time 61 . If the program execution stops. you can use the find command or correct program errors. The next executable statement is marked with a yellow arrow. UART. 5. and PWM Modules) of your 8051 device. µVision2 opens an editor window with the source text or shows CPU instructions in the disassembly window. The additional debug windows are discussed in the following. set Debug – Enable/Disable Trace Recording.14 Disassembly Window The Disassembly window shows your target program as mixed source and assembly program or just assembly code. Interrupts. The Keil µVision Debugger accurately simulates on-chip peripherals (I²C. During debugging. A trace history of previously executed instructions may be displayed with Debug – View Trace Records. A/D Converter. CAN. For example. I/O Ports. SPI. All build commands are disabled. You may use the dialog Debug – Inline Assembly… to modify the CPU instructions. To enable the trace history. The µVision2 debug mode differs from the edit mode in the following aspects: _ The “Debug Menu and Debug Commands” described on page 28 are available. You can select a text line and set or modify code breakpoints using toolbar buttons or the context menu commands. That allows you to correct mistakes or to make temporary changes to the target program you are debugging. _ The project structure or tool parameters cannot be modified. Numerous example programs are included to help you get started with the most popular embedded 8051 devices. Program source text of your application is shown in the same windows. D/A Converter.layout and restores the screen layout of the last debug session. If you select the Disassembly Window as the active window all program step commands work on CPU instruction level rather than program source lines.

in C. 5. and the available processor power is around 1000 times less than that of a desktop processor. and even everyday domestic appliances such as dish washers.wasted on setup problems. If you have some programming experience . they tend to use lowcost processors like the 8051 family of devices considered in this book. medical equipment. washing machines and video recorders now include at least one such device.SCHEMATIC DIAGRAM {FOR SCHEMATIC DIAGRAM REFER CD} 62 . These popular chips have very limited resources available most such devices have around 256 bytes (not megabytes!) of RAM. even for experienced desktop programmers. with simulation. developing embedded software presents significant new challenges. mobile phones. Because most embedded projects have severe cost constraints. Additionally.15 EMBEDDED C Use of embedded processors in passenger cars. aerospace systems and defense systems is widespread. televisions. you can write and test applications before target hardware is available. C++ or Java .then this book and its accompanying CD will help make your move to the embedded world as quick and painless as possible. 6. As a result.

Thus the dc voltage at the input of the regulator changes from about 8V to 15V because of A.e..Thus if the transformer delivers 12V at 220V input it will give 8. negative voltage to indicate 5V power supply availability. of turns in the primary to the no.1 SCHEMATIC DIAGRAM DESCRIPTION POWER SUPPLY The circuit uses standard power supply comprising of a step-down transformer from 230Vto 12V and 4 diodes forming a bridge rectifier that delivers pulsating dc which is then filtered by an electrolytic capacitor of about 470µF to 1000µF. IC LM7805 is used to get 5V DC constant at its pin no 3 irrespective of input DC varying from 7V to 15V. no. STANDARD CONNECTIONS TO 8051 SERIES MICRO CONTROLLER 63 . The filtered dc being unregulated.Similarly at 270V it will give 14. As N1/N2 i.e.72V. The input dc shall be varying in the event of input ac at 230volts section varies from 160V to 270V in the ratio of the transformer primary voltage V1 to secondary voltage V2 governed by the formula V1/V2=N1/N2.6. One LED is connected of this 5V point in series with a current limiting resistor of 330Ω to the ground i. of turns in the secondary remains unchanged V2 is directly proportional to V1. The regulated 5V DC is further filtered by a small electrolytic capacitor of 10µF for any noise so generated by the circuit.72V at 160V.C voltage variation from 160V to 270V the regulator output will remain constant at 5V. The unregulated 12V point is used for other applications as and when required.

and it behaves as a full short circuit from the positive to the pin number 9.e. If it is connected to ground then 64 . and as regards to 20 pin configuration a number of “89C2051”. After the capacitor gets fully charged the current stops flowing and pin number 9 goes low which is pulled down by a 10k resistor to the ground. For example: A 10µF capacitor and a 10kΩ resistor would render a 100ms time to pin number 9 from logic high to low. while connected to the appropriate pin of the microcontroller it results in oscillator function inside the microcontroller. This operation of high to low of the reset pin takes place in fraction of a second as decided by the time constant R and C. low helps the program execution to start from the beginning. “89C52”. “89S51”. RESET Pin no 9 is provided with an re-set arrangement by a combination of an electrolytic capacitor and a register forming RC time constant. The actual number of the Microcontroller could be “89C51” . Typically 11. to enable the program execution from the beginning.0592 MHz crystal is used in general for most of the circuits using 8051 series microcontroller. It may be noted here the crystal is not to be understood as crystal oscillator It is just a crystal. At the time of switch on. the capacitor gets charged. there after the pin number 9 remains low.ATMEL series of 8051 family of micro controllers need certain standard connections. Two small value ceramic capacitors of 33pF each is used as a standard connection for the crystal as shown in the circuit diagram. A crystal ranging from 2 to 20 MHz is required to be used at its pin number 18 and 19 for the internal oscillator. Every microcontroller requires a timing reference for its internal program execution therefore an oscillator needs to be functional with a desired frequency to obtain the timing reference as t =1/f. External Access(EA): Pin no 31 of 40 pin 8051 microcontroller termed as EA¯ is required to be connected to 5V for accessing the program form the on-chip program memory.. This arrangement of reset at pin 9 going high initially and then to logic 0 i. A pushbutton switch is connected across the capacitor so that at any given time as desired it can be pressed such that it discharges the capacitor and while released the capacitor starts charging again and then pin number 9 goes to high and then back to low. In absence of this the program execution could have taken place arbitrarily anywhere from the program cycle. The 4 set of I/O ports are used based on the project requirement. “89S52”.

Current flowing through the coil of the relay creates a magnetic field which attracts a lever and changes the switch contacts. Relays allow one circuit to switch a second circuit which can be completely separate from the first. If logic high is given to the IC as input then its output will be logic low but not the vice versa. There is no electrical connection inside the relay between the two circuits. BRIEF DESCRIPTION OF WORKING OF RELAY A relay is an electrically operated switch. the link is magnetic and mechanical. ULN2003 is a relay driver IC consisting of a set of Darlington transistors. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. Here in ULN2003 pin 1 to 7 are IC inputs and 10 to 16 are IC outputs.(the relay driver) then the relay contacts change their position from normally open to close the circuit as shown below for the load on (say a lamp to start glowing). ULN 2003 RELAY DRIVER IC ULN2003 is an IC which is used to interface relay with the microcontroller since the output of the micro controller is maximum 5V with too little current delivery and is not practicable to operate a relay with that voltage. However as we are using the internal memory it is always connected to +5V. If a relay coil is connected from +ve to the output pin of the uln2003. Similarly 65 .the controller accesses the program from external memory. The coil current can be on or off so relays have two switch positions and most have double throw (changeover) switch contacts. If logic 1 is given to its pin no 1 the corresponding pin 16 goes low. If logic 0 is given at the input the relay switches off.

upto seven relays can be used for seven different loads to be switched on by the normally open(NO) contact or switched off by the normally closed contact(NC) Load off Load on OPERATION EXPLANATION CONNECTIONS: The output of power supply which is connected to the 40 th pin of microcontroller and ground is connected to its 20 th pin.1 TO Pin 0. PIN 0. Pin 0.16 are connected to relays. Seven push buttons are connected as an input to the port 3.7 of port 2 are connected to data lines of LCD.5.7 of the microcontroller. 66 .e. Pin 0. Pins 13.4 of microcontroller are connected to ULN2003.0 to pin 2.15. write and enable pins of LCD.3 to 3..7 of microcontroller are connected to read. The output of ULN2003 i.6. Pin 2. Pin 0.14.

setting mode. push button 1 to 4 can be used to switch ON/OFF the load through the relay if required. Thus any time interval between the loads can be selected. While manual mode is selected. 67 . While setting mode is selected the time difference in the sequential operation from one load to the next. All the operations above are displayed in an LCD display that helps during programming mode of time and mode selection. manual mode. can be changed up or down by pressing the manual and setting buttons respectively. The corresponding pins 16 to 13 go low accordingly to switch ON respective relay to turn on the load. the output the microcontroller pin 38 to pin 35 goes sequentially high as per preset time to develop high logic at the input of ULN2003 pin 1 to 4. Selecting auto mode.WORKING: This project is designed to work like a PLC for a specific operation such as programmable timing based sequential switching operation of industrial loads. Four loads are used independently from the contacts of four relays driven by a relay driver IC ULN2003 as explained above. Four more push buttons are separately provided for manual operation of the relays while manual mode is chosen. Three setup switches are used for auto mode.

7. PROJECT LAYOUT 68 .

69 .

BILL OF MATERIALS QTY PART-REFS VALUE Resistors 1 R1 330R 15 R2-R16 10K 4 1K R17-R20 Capacitors 1 C1 470UF 2 C2.C3 10UF 2 C4.C5 33PF Integrated Circuits 1 U1 7805 1 U2 AT89S52 1 U3 ULN2003A Ic Bases 70 .8.

0592MHz 4 L1-L4 LAMP 4 LAMP HOLDER 1 LCD LM016L(16X2) 5 LED1-LED5 LED-RED 1 POT 10K 4 RELAY1-RELAY4 12V 8 S1-S8 PUSH BUTTON 1 TRANSFORMER 0-12V 5 PCB CONNECTORS 2-PIN 1 FEMALE BURGE 16-PIN 1 MALE BURG 16-PIN 1 MALE BURG 2-PIN 71 .1 40-PIN 1 16-PIN Diodes 4 D1-D4 1N4007 Miscellaneous 1 CRYSTAL 11.

1 FEMALE BURG 1 HEAT SINK 2-PIN 72 .

9.CODING 73 .

Then Click on New Project 74 . Click on the Project menu from the title bar 4. Click on the Keil Vision Icon on Desktop 2.9.1 COMPILER 1. The following fig will appear 3.

Atmel…… 8. Then Click on Save button above.5. Click on the + Symbol beside of Atmel 75 .e. i. 7. Select the component for u r project. Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\ 6.

Then Click on “OK” 11.9. Select AT89C51 as shown below 10. The Following fig will appear 76 .

14. 15. 77 .12. Now double click on the Target1. 13. Then Click either YES or NO………mostly “NO”. you would get another option “Source group 1” as shown in next page. Now your project is ready to USE. Click on the file option from menu bar and select “new”.

17. For a program written in Assembly. and just maximize it by double clicking on its blue boarder. The next screen will be as shown in next page.16. Now start writing program in either in “EMBEDDED C” or “ASM”. then save it with extension “. 18.C” 78 . asm” and for “EMBEDDED C” based program save it with extension “ .

79 . Now you will get another window.19. 20. on which by default “EMBEDDED C” files will appear. Now right click on Source group 1 and click on “Add files to Group Source”.

24. Now select as per your file extension given while saving the file 22. 23. Now Press function key F7 to compile. The new window is as follows 80 . 25. If the file contains no error. Any error will appear if so happen.21. Click only one time on option “ADD”. then press Control+F5 simultaneously.

Then Click “OK”. Drag the port a side and click in the program file.26. and check your required port as shown in fig below. 28. 27. 81 . Now click on the Peripherals from menu bar.

29.

Now keep Pressing function key “F11” slowly and observe.

30.

You are running your program successfully.

82

10.HARDWARE TESTING
10.1 CONTINUITY TEST:
In electronics, a continuity test is the checking of an electric circuit to see if current
flows (that it is in fact a complete circuit). A continuity test is performed by placing a small
voltage (wired in series with an LED or noise-producing component such as a piezoelectric
speaker) across the chosen path. If electron flow is inhibited by broken conductors, damaged
components, or excessive resistance, the circuit is "open".
Devices that can be used to perform continuity tests include multi meters which
measure current and specialized continuity testers which are cheaper, more basic devices,
generally with a simple light bulb that lights up when current flows.
An important application is the continuity test of a bundle of wires so as to find the two ends
belonging to a particular one of these wires; there will be a negligible resistance between the
"right" ends, and only between the "right" ends.
This test is the performed just after the hardware soldering and configuration has been
completed. This test aims at finding any electrical open paths in the circuit after the soldering.
Many a times, the electrical continuity in the circuit is lost due to improper soldering, wrong
and rough handling of the PCB, improper usage of the soldering iron, component failures and
presence of bugs in the circuit diagram. We use a multi meter to perform this test. We keep
the multi meter in buzzer mode and connect the ground terminal of the multi meter to the
ground. We connect both the terminals across the path that needs to be checked. If there is
continuation then you will hear the beep sound.

10.2 POWER ON TEST:
This test is performed to check whether the voltage at different terminals is according
to the requirement or not. We take a multi meter and put it in voltage mode. Remember that
this test is performed without microcontroller. Firstly, we check the output of the transformer,
whether we get the required 12 v AC voltage.
83

Then we apply this voltage to the power supply circuit. Note that we do this test
without microcontroller because if there is any excessive voltage, this may lead to damaging
the controller. We check for the input to the voltage regulator i.e., are we getting an input of
12v and an output of 5v. This 5v output is given to the microcontrollers’ 40 th pin. Hence we
check for the voltage level at 40th pin. Similarly, we check for the other terminals for the
required voltage. In this way we can assure that the voltage at all the terminals is as per the
requirement.

84

11.RESULT

85

12.CONCLUSION 86 .

ATMEL 89S52 Data Sheets.wikipedia.com  www. “The 8051 Microcontroller and Embedded systems” by Muhammad Ali Mazidi and Janice Gillispie Mazidi .beyondlogic.atmel.BIBLIOGRAPHY TEXT BOOKS REFERED 1.org  www.alldatasheets.com 87 .org  www.com  www. Pearson Education.13.howstuffworks. 2. WEBSITES  www.