Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 86

A PROJECT REPORT ON

OBJECT COUNTER WITH 7 SEGMENT DISPLAY


Submitted in partial fulfillment of the requirements For the award of the degree BACHELOR OF ENGINEERING IN ELECTRONICS AND COMMUNICATION ENGINEERING SUBMITTED BY A.Sandeep Kumar G.Srikanth G.Srikanth (08D61A0402) (08D61A0442) (08D61A0438)

DEPARTMENT OF ELECTRONICS AND COMMUNICATIONS ENGINEERING RAJA MAHENDRA COLLEGE OF ENGINEERING AFFILIATED TO JNTUH UNIVERSITY

RAJA MAHENDRA COLLEGE OF ENGINEERING


1

CERTIFICATE
This is to certify that the dissertation work entitled OBJECT COUNTER WITH 7 SEGMENT DISPLAY 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

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
3

We, the undersigned, declare that the project entitled OBJECT COUNTER WITH 7 SEGMENT DISPLAY, being submitted in partial fulfillment for the award of Bachelor of Engineering Degree in Electronics and Communication Engineering, affiliated to _________ University, is the work carried out by us.

__________ __________

_________ _________

_________ _________

CONTENTS ABSTRACT

PAGE NO 9
4

1. INTRODUCTION TO EMBEDDED SYSTEMS 2. BLOCK DIAGRAM 3. HARDWARE REQUIREMENTS

10 16 17 19 20

3.1 TRANSFORMERS 3.2 VOLTAGE REGULATOR (LM7805) 3.3 RECTIFIER 23 3.4 FILTER 24
3.5 MICROCONTROLLER (AT89S52) 3.6 RELAY 3.7 PUSH BUTTONS

24

3.7 555 TIMER 3.8 BC 547 TRNSISTOR 3.9 IN4007 RECTIFIER DIODE 4. SOFTWARE REQUIREMENTS 4.1 IDE 57 4.2 CONCEPT OF COMPILER 4.3 CONCEPT OF CROSS COMPILER 4.4 KEIL C CROSS COMPILER 4.5 BUILDING AN APPLICATION IN UVISION2 4.6 CREATING YOUR OWN APPLICATION IN UVISION2 4.7 DEBUGGING AN APPLICATION IN UVISION2 4.8 STARTING UVISION2 & CREATING A PROJECT 4.9 WINDOWS_ FILES 61 4.10 BUILDING PROJECTS & CREATING HEX FILES 61
5

53 56

57 58 59 59 59 60 61

4.11 CPU SIMULATION 4.12 DATABASE SELECTION 4.13 START DEBUGGING 4.14 DISASSEMBLY WINDOW 4.15 EMBEDDED C 5. CODING 5.1 COMPILER 76 5.2 SOURCE CODE 6. HARDWARE TESTING 6.1 CONTINUITY TEST 6.2 POWER ON TEST 7. CONCLUSION 8. BIBLIOGRAPHY 93

62 62 63 63 64 75

84 88 88 89

94

1. ABSTRACT
This application keeps the database of the number of objects being entered. Sensor gets interrupted on to the IR receiver to sense the objects entering as well as exiting. This signal is fed to AT89C51 for analyzing and control purpose. The data obtained from micro controller is given to the 7-Seg which displays the number of persons being entered.
6

1. INTRODUCTION TO EMBEDDED SYSTEMS


What is embedded system?
An Embedded System is a combination of computer hardware and software, and perhaps additional mechanical or other parts, designed to perform a specific function. An embedded system is a microcontroller-based, software driven, reliable, real-time control system, autonomous, or human or network interactive, operating on diverse physical variables and in diverse environments and sold into a competitive and cost conscious market.
7

An embedded system is not a computer system that is used primarily for processing, not a software system on PC or UNIX, not a traditional business or scientific application. High-end embedded & lower end embedded systems. High-end embedded system - Generally 32, 64 Bit Controllers used with OS. Examples Personal Digital Assistant and Mobile phones etc .Lower end embedded systems - Generally 8,16 Bit Controllers used with an minimal operating systems and hardware layout designed for the specific purpose.

1.1. SYSTEM DESIGN CALLS:


Figure 1(a): Embedded system design calls

1.2.EMBEDDED SYSTEM DESIGN CYCLE

Figure 1(b):V Diagram

1.3.Characteristics of Embedded System


An embedded system is any computer system hidden inside a product other than a computer. They will encounter a number of difficulties when writing embedded system software in addition to those we encounter when we write applications.

Throughput Our system may need to handle a lot of data in a short period of time. ResponseOur system may need to react to events quickly. TestabilitySetting up equipment to test embedded software can be difficult.

DebugabilityWithout a screen or a keyboard, finding out what the software is doing wrong (other than not working) is a troublesome problem.

Reliability embedded systems must be able to handle any situation without human intervention. Memory space Memory is limited on embedded systems, and you must make the software and the data fit into whatever memory exists.

Program installation you will need special tools to get your software into embedded systems. Power consumption Portable systems must run on battery power, and the software in these systems must conserve power. Processor hogs computing that requires large amounts of CPU time can complicate the response problem. Cost Reducing the cost of the hardware is a concern in many embedded system projects; software often operates on hardware that is barely adequate for the job.

Embedded systems have a microprocessor/ microcontroller and a memory. Some have a serial port or a network connection. They usually do not have keyboards, screens or disk drives.

1.4. APPLICATIONS
1) Military and aerospace embedded software applications 2 ) C o mm un ic a ti on A p pl ic at io ns 3 ) In dus tr ia l a ut om at i on an d pr oc es s co nt ro l s of tw ar e 4) Mastering the complexity of applications. 5) Reduction of product design time. 6) Real time processing of ever increasing amounts of data. 7) Intelligent, autonomous sensors.

1.5. CLASSIFICATION
Real Time Systems. RTS is one which has to respond to events within a specified deadline. A right answer after the dead line is a wrong answer.
9

1.6. RTS CLASSIFICATION


Hard Real Time Systems Soft Real Time System

1.7. HARD REAL TIME SYSTEM


"Hard" real-time systems have very narrow response time. Example: Nuclear power system, Cardiac pacemaker.

1.8. SOFT REAL TIME SYSTEM


"Soft" real-time systems have reduced constrains on "lateness" but still must operate very quickly and repeatable. Example: Railway reservation system takes a few extra seconds the data remains valid.

2. BLOCK DIAGRAM
IR TX IR RX INTERRUPT SENSOR AT89C51 7-SEG DISPLAY

ASM / EMBEDDED C PROGRAM

2.1: project block diagram

3. HARDWARE REQUIREMENTS
HARDWARE COMPONENTS:
1 TRANSFORMER (230 12 V AC) 2 VOLTAGE REGULATOR (LM 7805)
10

3 RECTIFIER 4 FILTER 3 4 5 6 7 8 9 MICROCONTROLLER (AT89S52/AT89C51) RELAY PUSH BUTTONS BC547 TRNSISTOR IN4007 RECTIFIER DIODE SEVEN SEGMENT DISPLAY LED

10 RESISTORS 11 CAPACITORS

3.1 TRANSFORMER
Transformers convert AC electricity from one voltage to another with a little loss of power. Step-up transformers increase voltage, step-down transformers reduce voltage. Most power supplies use a step-down transformer to reduce the dangerously high voltage to a safer low voltage.

FIG 3.1: A TYPICAL TRANSFORMER


11

The input coil is called the primary and the output coil is called the secondary. There is no electrical connection between the two coils; instead they are linked by an alternating magnetic field created in the soft-iron core of the transformer. The two lines in the middle of the circuit symbol represent the core. Transformers waste very little power so the power out is (almost) equal to the power in. Note that as voltage is stepped down and current is stepped up. The ratio of the number of turns on each coil, called the turns ratio, determines the ratio of the voltages. A step-down transformer has a large number of turns on its primary (input) coil which is connected to the high voltage mains supply, and a small number of turns on its secondary (output) coil to give a low output voltage. TURNS RATIO = (Vp / Vs) = (Np / Ns) Where, Vp = primary (input) voltage. 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.

3.2 VOLTAGE REGULATOR 7805


Features
Output Current up to 1A. Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24V. Thermal Overload Protection. Short Circuit Protection. Output Transistor Safe Operating Area Protection.

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, making them useful in a Wide range of applications. Each type employs internal current limiting, thermal shutdown and safe operating area protection, making it essentially indestructible.
12

If adequate heat sinking is provided, they can deliver over 1A output Current. Although designed primarily as fixed voltage regulators, these devices can be used with external components to obtain adjustable voltages and currents.

Internal Block Diagram

FIG 3.2(a): BLOCK DIAGRAM OF VOLTAGE REGULATOR


13

Absolute Maximum Ratings

TABLE 3.2(b): RATINGS OF THE VOLTAGE REGULATOR

Typical Performance Characteristics

14

FIG 3.2(c): PERFORMANCE CHARACTERISTICS OF REGULATOR

3.3 RECTIFIER
A rectifier is an electrical device that converts alternating current (AC), which periodically reverses direction, to direct current (DC), current that flows in only one direction, a process known as rectification. Rectifiers have many uses including as components of power supplies and as detectors of radio signals. Rectifiers may be made of solid state diodes, vacuum tube diodes, mercury arc valves, and other components. The output from the transformer is fed to the rectifier. It converts A.C. into pulsating D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge rectifier is used because of its merits like good stability and full wave rectification.

3.4 FILTER
Capacitive filter is used in this project. It removes the ripples from the output of rectifier and smoothens the D.C. Output received from this filter is constant until the mains voltage and load is maintained constant. However, if either of the two is varied,
15

D.C. voltage received at this point changes. Therefore a regulator is applied at the output stage. The simple capacitor filter is the most basic type of power supply filter. The use of this filter is very limited. It is sometimes used on extremely high-voltage, low-current power supplies for cathode-ray and similar electron tubes that require very little load current from the supply. This filter is also used in circuits where the power-supply ripple frequency is not critical and can be relatively high.

3.5 MICROCONTROLLER AT89S52


The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density non volatile memory technology and is compatible with the industry standard 80C51 instruction set and pin out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional non volatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, onchip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.

Features:
Compatible with MCS-51 Products 8K Bytes of In-System Programmable (ISP) Flash Memory Endurance: 10,000 Write/Erase Cycles 4.0V to 5.5V Operating Range
16

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:

17

FIG 3.3(A): BLOCK DIAGRAM OF AT89S52

Pin Configurations of AT89S52


18

FIG 3.3(b): PIN DIAGRAM OF AT89S52

Pin Description: VCC: Supply voltage. GND: Ground Port 0: Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance inputs. 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, P0 has internal pull-ups. Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. External pull-ups are required during program verification. Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups.
19

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

Program Store Enable (PSEN) is the read strobe to external program memory. When the AT89S52 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory. EA/VPP: External Access Enable. 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. Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming. XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2: Output from the inverting oscillator amplifier. Oscillator Characteristics: XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in Figure 1. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure 6.2. There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flipflop, but minimum and maximum voltage high and low time specifications must be observed.

FIG 3.3(c): Oscillator Connections


21

FIG 3.3(d): External Clock Drive Configuration Idle Mode In idle mode, the CPU puts itself to sleep while all the on chip peripherals remain active. The mode is invoked by software. The content of the on-chip RAM and all the special functions registers remain unchanged during this mode. The idle mode can be terminated by any enabled interrupt or by a hardware reset. Power down Mode In the power down mode the oscillator is stopped, and the instruction that invokes power down is the last instruction executed. The on-chip RAM and Special Function Registers retain their values until the power down mode is terminated. The only exit from power down is a hardware reset. Reset redefines the SFRs but does not change the on-chip RAM. 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.

3.6 RELAY
A relay is an electrical switch that opens and closes under the control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contact. Since a relay is able to control an output circuit of higher power than the input circuit, it can be considered to be, in a broad sense, a form of an electrical amplifier.

22

Fig 3.4(a): RELAY

Basic design and operation


A simple electromagnetic relay, such as the one taken from a car in the above figure , is an adaptation of an electromagnet. It consists of a coil of wire surrounding a soft iron core, an iron yoke, which provides a low reluctance path for magnetic flux, a moveable iron armature, and a set, or sets, of contacts; that is two in the relay for above figure . The armature is hinged to the yoke and mechanically linked to a moving contact or contacts. It is held in place by a spring so that when the relay is de-energised there is an air gap in the magnetic circuit. In this condition, one of the two sets of contacts in the relay is closed, and the other set is open. Other relays may have more or fewer sets of contacts depending on their function. The relay also has a wire connecting the armaturto the yoke. This ensures continuity of the circuit between the moving contacts on the armature, and the circuit track on thePrintedCircuit Board (PCB) via the yoke, which is soldered to the PCB.

Fig 3.4(b):INTERNAL CIRCUIT OF RELAY When an electric current is passed through the coil, the resulting magnetic field attracts the armature, and the consequent movement of the movable contact or contacts either makes or breaks a connection with a fixed contact. If the set of contacts was closed when the relay was de-energised, then the movement opens the contacts and breaks the connection, and vice versa if the contacts were open. When the current to the coil is switched off, the armature is returned by a force, approximately half as strong as the magnetic force, to its relaxed position.
23

Usually this force is provided by a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing. If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a voltage spike dangerous to circuit components. Some automotive relays already include that diode inside the relay case. Alternatively a contact protection network, consisting of a capacitor and resistor in series, may absorb the surge. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-of-phase current, which increases the minimum pull on the armature during the AC cycle. By analogy with the functions of the original electromagnetic device, a solidstate relay is made with a thyristor or other solid-state switching device. To achieve electrical isolation an optocoupler can be used which is a light-emitting diode (LED) coupled with photo diode .

Applications
Relays are used to and for: Control a high-voltage circuit with a low-voltage signal, as in some types of modems or audio amplifiers. Control a high-current circuit with a low-current signal, as in the starter solenoid of an automobile.

24

Detect and isolate faults on transmission and distribution lines by opening and closing circuit breakers. Time delay functions. 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. Current flowing in the disk maintains magnetic field for a short time, lengthening release time. For a slightly longer (up to a minute) delay, a dashpot is used. A dashpot is a piston filled with fluid that is allowed to escape slowly. The time period can be varied by increasing or decreasing the flow rate. For longer time periods, a mechanical clockwork timer is installed.

3.7 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. Buttons are typically made out of hard material, usually plastic or metal. The surface is usually flat or shaped to accommodate the human finger or hand, so as to be easily depressed or pushed. Buttons are most often biased switches, though even many un-biased buttons (due to their physical nature) require a spring to return to their un-pushed state. Different people use different terms for the "pushing" of the button, such as press, depress, mash, and punch. 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 stop button can "force" a start button to be released. This method
25

of linkage is used in simple manual operations in which the machine or process have no electrical circuits for control. Pushbuttons are often color-coded to associate them with their function so that the operator will not push the wrong button in error. Commonly used colors are red for stopping the machine or process and green for starting the machine or process. Red pushbuttons can also have large heads (mushroom shaped) for easy operation and to facilitate the stopping of a machine. These pushbuttons are called emergency stop buttons and are mandated by the electrical code in many jurisdictions for increased safety. 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 flushmounted push button. As an aid for operators and users in industrial or commercial applications, a pilot light is commonly added to draw the attention of the user and to provide feedback if the button is pushed. Typically this light is included into the center of the pushbutton and a lens replaces the pushbutton hard center disk. 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. 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. In popular culture, the phrase "the button" refers to a (usually fictional) button that a military or government leader could press to launch nuclear weapons.

Push to ON button:

Fig 3.7(a): push on button Initially the two contacts of the button are open. When the button is pressed they become connected. This makes the switching operation using the push button.
26

Electronics Expansion specificatio of n and n abbreviatio abbreviatio n

British mains wiring name

America n electrical Description Symbol wiring name A simple on-off switch: The two terminals are either IEC 60617

SPST

Single pole, single throw

One way

Two way

connected together or not connected to anything. An example is a light switch. A simple changeover switch: C

SPDT

Single pole, double throw

Two way

Three way

(COM, Common) is connected to L1 or to L2.

SPCO SPTT, c.o.

Single pole changeover or Single pole, centre off or

Similar to SPDT. Some suppliers use


27

SPCO/SPT T for Single Pole, Triple Throw switches with a stable off position in the centre and SPDT. Equivalent to two DPST Double pole, single throw Double pole Double pole SPST switches controlled by a single mechanism Equivalent to two SPDT switches controlled by a single DPDT Double pole, double throw mechanism: A is connected to B and D to E, or A is connected to C and D to F. DPCO Double pole changeover or Double Equivalent to DPDT. Some
28

suppliers use DPCO for switches with a pole, centre off stable off position in the centre and DPDT for those without. Intermediat 4-way e switch switch DPDT switch internally wired for polarityreversal applications : only four rather than six wires are brought outside the switch housing; with the above, B is connected to F and C to E; hence A is connected to B and D
29

to C, or A is connected to C and D to B. Fig 3.7(b): TABLE TYPES OF PUSH BUTTONS

3.8 BC 547,BC557, BC558


The BC547 transistor is an NPN Epitaxial Silicon Transistor. The BC547 transistor is a general-purpose transistor in small plastic packages. It is used in generalpurpose switching and amplification BC847/BC547 series 45 V, 100 mA NPN generalpurpose transistors.

FIG 3.8(a): BC 547 TRANSISTOR PINOUT The BC547 transistor is an NPN bipolar transistor, in which the letters "N" and "P" refer to the majority charge carriers inside the different regions of the transistor. Most bipolar transistors used today are NPN, because electron mobility is higher than hole mobility in semiconductors, allowing greater currents and faster operation. NPN transistors consist of a layer of P-doped semiconductor (the "base") between two Ndoped layers. A small current entering the base in common-emitter mode is amplified in the collector output. In other terms, an NPN transistor is "on" when its base is pulled high relative to the emitter. The arrow in the NPN transistor symbol is on the emitter leg and points in the direction of the conventional current flow when the device is in forward active mode. One mnemonic device for identifying the symbol for the NPN transistor is "not pointing in." An NPN transistor can be considered as two diodes with a shared anode region. In typical operation, the emitter base junction is forward biased and the base collector junction is reverse biased. In an NPN transistor, for example, when a positive
30

voltage is applied to the base emitter junction, the equilibrium between thermally generated carriers and the repelling electric field of the depletion region becomes unbalanced, allowing thermally excited electrons to inject into the base region. These electrons wander (or "diffuse") through the base from the region of high concentration near the emitter towards the region of low concentration near the collector. The electrons in the base are called minority carriers because the base is doped p-type which would make holes the majority carrier in the base.

Voltage Controlled Switch with a BC547 Transistor:


This voltage controlled switch circuit operates when a voltage level which is previously adjusted is applied to the input. Circuit is designed for 24V supply but can be used in a range of 18V-36V. Voltage level which triggers the circuit can be adjusted by P1 potentiometer. A stabilized voltage is applied to this potentiometer through zener diode and Tr5. When the input voltage level exceeds this value TR1 starts conducting and afterwards Tr2, Tr3, Tr4 transistors conduct and relay switches on. Switch S1 that is connected to relay, carries the signal from Tr3 to Tr1 through R1 and keeps Tr1 conducting. When the input is short circuited, D1 diode keeps the circuit operating and you can omit it if you want.

3.8(b): VOLTAGE CONTROLLED SWITCH WITH BC547

31

3.9 IN4007 RECTIFIER DIODE


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

3.10 SEVEN SEGMENT DISPLAY

FIG 3.10(a): SEVEN SEGMENT DISPLAY LAY OUT The illustration to the right shows the basic layout of the segments in a seven-segment display. The segments themselves are identified with lower-case letters "a" through "g," with segment "a" at the top and then counting clockwise. Segment "g" is the centre bar.

32

Most seven-segment digits also include a decimal point ("dp"), and some also include an extra triangle to turn the decimal point into a comma. This improves readability of large numbers on a calculator, for example. The decimal point is shown here on the right, but some display units put it on the left, or have a decimal point on each side. In addition, most displays are actually slanted a bit, making them look as if they were in italics. This arrangement allows us to turn one digit upside down and place it next to another, so that the two decimal points look like a colon between the two digits. The technique is commonly used in LED clock displays.

FIG. 3.10(b): PACKAGES OF SEVEN SEGMENT DISPLAY Seven-segment displays can be packaged in a number of ways. Three typical packages are shown above. On the left we see three small digits in a single 12-pin DIP package. The individual digits are very small, so a clear plastic bubble is molded over each digit to act as a magnifying lens. The sides of the end bubbles are flattened so that additional packages of this type can be placed end-to-end to create a display of as many digits as may be needed. The second package is essentially a 14-pin DIP designed to be installed vertically. Note that for this particular device, the decimal point is on the left. This is not true of all seven-segment displays in this type of package. One limitation of the DIP package is that it cannot support larger digits. To get larger displays for easy reading at a distance, it is necessary to change the package size and shape. The package on the right above is larger than the other two, and thus can display a digit that is significantly larger than will fit on a standard DIP footprint. Even larger displays are also available; some digital clocks sport digits that are two to five inches tall.

33

CONSTRUCTION:
Seven-segment displays can be constructed using any of a number of different technologies. The three most common methods are fluorescent displays (used in many line-powered devices such as microwave ovens and some clocks and clock radios), liquid crystal displays (used in many battery-powered devices such as watches and many digital instruments), and LEDS (used in either line-powered or battery-powered devices). However, fluorescent displays require a fairly high driving voltage to operate, and liquid crystal displays require special treatment that we are not yet ready to discuss. Therefore, we will work with a seven-segment LED display in this experiment.

Schematic Diagram

As shown in the two schematic diagrams above, the LEDs in a seven-segment display are not isolated from each other. Rather, either all of the cathodes, or all of the anodes, are connected together into a common lead, while the other end of each LED is individually available. This means fewer electrical connections to the package, and also allows us to easily enable or disable a particular digit by controlling the common lead. (In some cases, the common connections are made to groups of LEDs, and the external
34

wiring must make the final connections between them. In other cases, the common connection is made available at more than one location for convenience in laying out printed circuit boards. When laying out circuits using such devices, you simply need to take the specific connection details into account.)There is no automatic advantage of the common-cathode seven-segment unit over the common-anode version, or vice-versa.

3.11 LED
LEDs are semiconductor devices. Like transistors, and other diodes, LEDs are made out of silicon. What makes an LED give off light are the small amounts of chemical impurities that are added to the silicon, such as gallium, arsenide, indium, and nitride. When current passes through the LED, it emits photons as a byproduct. Normal light bulbs produce light by heating a metal filament until it is white hot. LEDs produce photons directly and not via heat, they are far more efficient than incandescent bulbs.

Fig 3.11(a): Typical LED

Fig 3.11(b): circuit symbol

Not long ago LEDs were only bright enough to be used as indicators on dashboards or electronic equipment. But recent advances have made LEDs bright enough to rival traditional lighting technologies. Modern LEDs can replace incandescent bulbs in almost any application.

Types of LEDS
LEDs are produced in an array of shapes and sizes. The 5 mm cylindrical package is the most common, estimated at 80% of world production. The color of the plastic lens is often the same as the actual color of light emitted, but not always. For instance, purple plastic is often used for infrared LEDs, and most blue devices have clear housings. There are also LEDs in extremely tiny packages, such as those found on blinkers and on cell phone keypads. The main
35

types of LEDs are miniature, high power devices and custom designs such as alphanumeric or multi-color. Fig 4.13(c) Different types of LEDS

Colors and materials of LEDS


Conventional LEDS are made from a variety of inorganic semiconductor materials, the following table shows the available colours with wavelength range, voltage drop and material.

Color

Wavelength

(nm)

Voltage (V)
V < 1.9

Semiconductor Material
Gallium arsenide (GaAs) Aluminum gallium arsenide (AlGaAs) Aluminum gallium arsenide (AlGaAs) Gallium arsenide phosphide (GaAsP) Aluminum gallium indium phosphide

Infrared > 760

Red

610 < < 760

1.63 < V < 2.03

(AlGaInP)
Gallium(III) phosphide (GaP) Gallium arsenide phosphide (GaAsP)

Orange 590 < < 610

2.03 < V < Aluminum 2.10 (AlGaInP)

gallium

indium

phosphide

Gallium(III) phosphide (GaP) Gallium arsenide phosphide (GaAsP) Yellow

570 < < 590

2.10 < V < Aluminum 2.18 (AlGaInP)

gallium

indium

phosphide

Gallium(III) phosphide (GaP) Indium gallium nitride Gallium(III) nitride (GaN) Green

(InGaN)

500 < < 570

1.9 < V < Gallium(III) phosphide (GaP) 4.0


Aluminum gallium indium phosphide

(AlGaInP)
Blue Aluminum gallium phosphide (AlGaP) 450 < < 500 2.48 < V < Zinc selenide (ZnSe) 36

Indium gallium nitride (InGaN)

3.7

Silicon carbide (SiC) as substrate Silicon

(Si)

as

substrate

(under

development)
Violet

400 < < 450

2.76 < V < 4.0 2.48 < V < 3.7

Indium gallium nitride (InGaN)

Dual blue/red LEDs, blue with red phosphor, or white with purple plastic Diamond (235 nm)[42]
Boron nitride (215 nm)[43][44]

Purple

multiple types

Ultraviol et

< 400

3.1 < V < Aluminum nitride (AlN) (210 nm)[45] 4.4


Aluminum gallium nitride (AlGaN) Aluminum gallium indium nitride

(AlGaInN) (down to 210 nm)[46] X White Broad spectrum V = 3.5 Blue/UV diode with yellow phosphor

White LEDS
Light Emitting Diodes (LED) have recently become available that are white and bright, so bright that they seriously compete with incandescent lamps in lighting applications. They are still pretty expensive as compared to a GOW lamp but draw much less current and project a fairly well focused beam. The diode in the photo came with a neat little reflector that tends to sharpen the beam a little but doesn't seem to add much to the overall intensity. When run within their ratings, they are more reliable than lamps as well. Red LEDs are now being used in automotive and truck tail lights and in red traffic signal lights. You will be able to detect them because they look like an array of point sources and they go on and off instantly as compared to conventional incandescent lamps.

37

LEDs are monochromatic (one color) devices. The color is determined by the band gap of the semiconductor used to make them. Red, green, yellow and blue LEDs are fairly common. White light contains all colors and cannot be directly created by a single LED. The most common form of "white" LED really isn't white. It is a Gallium Nitride blue LED coated with a phosphor that, when excited by the blue LED light, emits a broad range spectrum that in addition to the blue emission, makes a fairly white light. There is a claim that these white LED's have a limited life. After 1000 hours or so of operation, they tend to yellow and dim to some extent. Running the LEDs at more than their rated current will certainly accelerate this process. There are two primary ways of producing high intensity white-light using LEDS. One is to use individual LEDS that emit three primary coloursred, green, and blue and then mix all the colours to form white light. The other is to use a phosphor material to convert monochromatic light from a blue or UV LED to broad-spectrum white light, much in the same way a fluorescent light bulb works. Due to metamerism, it is possible to have quite different spectra that appear white.
38

Advantages of using LEDs Efficiency: LEDs produce more light per watt than incandescent bulbs; this is useful in battery powered or energy-saving devices. Size: LEDs can be very small (smaller than 2 mm2) and are easily populated onto printed circuit boards. On/Off time: LEDs light up very quickly. A typical red indicator LED will achieve full brightness in microseconds. LEDs used in communications devices can have even faster response times. Cycling: LEDs are ideal for use in applications that are subject to frequent on-off cycling, unlike fluorescent lamps that burn out more quickly when cycled frequently, or HID lamps that require a long time before restarting. Cool light: In contrast to most light sources, LEDs radiate very little heat in the form of IR that can cause damage to sensitive objects or fabrics. Wasted energy is dispersed as heat through the base of the LED. Lifetime: LEDs can have a relatively long useful life. One report estimates 35,000 to 50,000 hours of useful life, though time to complete failure may be longer. No Toxicity: LEDs do not contain mercury, unlike fluorescent lamps. Disadvantages of using LEDs High price: LEDs are currently more expensive, price per lumen, on an initial capital cost basis, than most conventional lighting technologies. Temperature dependence:

39

LED performance largely depends on the ambient temperature of the operating environment. Over-driving the LED in high ambient temperatures may result in overheating of the LED package, eventually leading to device failure. Voltage sensitivity: LEDs must be supplied with the voltage above the threshold and a current below the rating. This can involve series resistors or current-regulated power supplies. Area light source: LEDs do not approximate a point source of light, but rather a lambertian distribution. So LEDs are difficult to use in applications requiring a spherical light field. LEDs are not capable of providing divergence below a few degrees. This is contrasted with lasers, which can produce beams with divergences of 0.2 degrees or less. Blue Hazard: There is increasing concern that blue LEDs and cool-white LEDs are now capable of exceeding safe limits of the so-called blue-light hazard as defined in eye safety.

3.12 TSOP1738
IR RECEIVER:

Description
40

The TSOP17 series are miniaturized receivers for infrared remote control systems. PIN diode and preamplifier are assembled on lead frame, the epoxy package is designed as IR filter. The demodulated output signal can directly be decoded by a microprocessor. TSOP1738 is the standard IR remote control receiver series, supporting all major transmission codes.

Features
Photo detector and preamplifier in one package Internal filter for PCM frequency Improved shielding against electrical field disturbance TTL and CMOS compatibility Output active low Low power consumption High immunity against ambient light Continuous data transmission possible (up to 2400 bps) Suitable burst length .10 cycles/burst

Block Diagram

The circuit of the TSOP17 is designed in that way that unexpected output pulses due to noise or disturbance signals are avoided. A band pass filter, an integrator stage and an automatic gain control are used to suppress such disturbances. The distinguishing mark between data signal and disturbance signal are carrier frequency, burst length and duty cycle. The data signal should full fill the following condition: Carrier frequency should be close to center frequency of the band pass (e.g. 38kHz). Burst length should be 10 cycles/burst or longer. After each burst which is between 10 cycles and 70 cycles a gap time of at least 14 cycles is necessary.
41

For each burst which is longer than 1.8ms a corresponding gap time is necessary at some time in the data stream. This gap time should have at least same length as the burst. Up to 1400 short bursts per second can be received continuously. Some examples for suitable data format are: NEC Code, Toshiba Micom Format, Sharp Code, RC5 Code, RC6 Code, R2000 Code, Sony Format (SIRCS). When a disturbance signal is applied to the TSOP17.It can still receive the data signal. However the sensitivity is reduced to that level that no unexpected pulses will occur. Some examples for such disturbance signals which are suppressed by the TSOP17 series are: DC light (e.g. from tungsten bulb or sunlight) Continuous signal at 38 kHz or at any other frequency Signals from fluorescent lamps with electronic ballast (an example of the signal modulation is in the figure below).

3.13 555 TIMER


The 555 Timer IC is an integrated circuit (chip) implementing a variety of timer and multivibrator applications. The IC was designed by Hans R. Camenzind in 1970 and brought to market in 1971 by Signetics (later acquired by Philips). The original name was the SE555 (metal can)/NE555 (plastic DIP) and the part was described as "The IC Time Machine". It has been claimed that the 555 gets its name from the three 5 k resistors used in typical early implementations, but Hans Camenzind has stated that the number

42

was arbitrary. The part is still in wide use, thanks to its ease of use, low price and good stability. As of 2003[update], it is estimated that 1 billion units are manufactured every year.

FIG 3.13 (a) 555TIMER IC Depending on the manufacturer, the standard 555 package includes over 20 transistors, 2 diodes and 15 resistors on a silicon chip installed in an 8-pin mini dual-in-line package (DIP-8). Variants available include the 556 (a 14-pin DIP combining two 555s on one chip), and the 558 (a 16-pin DIP combining four slightly modified 555s with DIS & THR connected internally, and TR falling edge sensitive instead of level sensitive). Ultra-low power versions of the 555 are also available, such as the 7555 and TLC555. The 7555 is designed to cause less supply glitching than the classic 555 and the manufacturer claims that it usually does not require a "control" capacitor and in many cases does not require a power supply bypass capacitor. The 555 has three operating modes: Monostable mode: in this mode, the 555 functions as a "one-shot". Applications include timers, missing pulse detection, bouncefree switches, touch switches, frequency divider, capacitance measurement, pulse-width modulation (PWM) etc Astable - free running mode: the 555 can operate as an oscillator. Uses include LED and lamp flashers, pulse generation, logic clocks, tone generation, security alarms, pulse position modulation, etc. Bistable mode or Schmitt trigger: the 555 can operate as a flip-flop, if the DIS pin is not connected and no capacitor is used. Uses include bouncefree latched switches, etc.

43

Usage
The connection of the pins is as follows: Pin 1 2 3 4 5 6 7 8 Name GND TRIG OUT RESET CTRL THR DIS V+, VCC Purpose Ground, low level (0 V) OUT rises, and interval starts, when this input falls below 1/3 VCC. This output is driven to +VCC or GND. A timing interval may be interrupted by driving this input to GND. "Control" access to the internal voltage divider (by default, 2/3 VCC). The interval ends when the voltage at THR is greater than at CTRL. Open collector output; may discharge a capacitor between intervals. Positive supply voltage is usually between 3 and 15 V.

FIG3.13 (b) 555TIMER PIN DIAGRAM

555 Basics
The 555 timer IC is a simple 8 pin DIL package IC. It can: be used as a monostable be used as an astable source or sink 100mA use supply voltages of 5v to 15v disrupt the power supply - use a decoupling capacitor!

Using the 555 as a buffer


A buffer circuit allows an input circuit to be connected to an output circuit, it is like an interface between one circuit and another. The buffer circuit requires very little input current but should be able to supply adequate output current. The 555 can supply in
44

excess of 100mA of current and so can be used as a convenient buffer for logic gates which cannot supply much current. The 555 can also 'sink' a similar amount of current. The circuit used is:

FIG 3.13 (c): 555 TIMER AS A BUFFER The circuit acts like an inverter or NOT gate. When the input is held low, the output is high and will provide (source) current. When the input is held high, the output is low and will sink current. Remember, for a buffer for even higher power devices that require even larger currents, the 555 buffer can be used to drive a relay or a transistor circuit.

Using the 555 as a monostable


The 555 can be used as a monostable using the circuit shown:

FIG 3.13 (d) 555TIMER AS A MONOSTABLE The output is normally low but will go high for a short length of time depending on the values of the other components
45

R and C determine the time period of the output pulse The input is normally high and goes low to trigger the output (falling edge triggered) The length of the input pulse must be less than the length of the output pulse The 47uF capacitor 'decouples' the supply to avoid affecting other parts of the circuit It is standard to add a 10nF capacitor from pin5 to gnd T = 1.1 R C

T - seconds, R - ohms, C Farads The minimum value of R should be about 1k to avoid too much current flowing into the 555. The maximum value of R should be about 1M so that enough current can flow into the input of the 555 and there is also current to allow for the electrolytic capacitors leakage current. The minimum value of C = 100pF to avoid the timing equation being too far off The maximum value of C should be about 1000F as any bigger capacitors will discharge too much current through the chip. These maximum and minimum values give a minimum period of 0.1 s and a maximum period of 1000s.

Using the 555 as an astable


The 555 can be used as an astable using the circuit shown:

FIG 3.13 (e): 555 TIMER AS A ASTABLE


46

The output will oscillate between high and low continuously - the circuit is not stable in any state. Ra, Rb and C determine the time period of the output The reset, pin 4, must be held high for the circuit to oscillate. If pin 4 is held low then the output remains low. Pin 4 can be used to turn the astable 'on' and 'off' in effect

The 47uF capacitor 'decouples' the supply to avoid affecting other parts of the circuit It is standard to add a 10nF capacitor from pin5 to gnd. T = 0.7 ( Ra + 2Rb ) C

T - seconds, R - ohms, C Farads As with the monostable the minimum value of Ra should be about 1k to avoid too much current flowing into the 555. The maximum value of Ra or Rb should be about 1M so that enough current can flow into the input of the 555 and there is also current to allow for the electrolytic capacitors leakage current. The minimum value of C = 100pF to avoid the timing equation being too far off. The maximum value of C should be about 1000F as any bigger capacitors will discharge too much current through the chip. These maximum and minimum values give a minimum frequency of 0.001 Hz and a maximum frequency of 4.8 MHz (in reality it would not be able to attain these frequencies).

Considering the oscillations in more detail:


the output is controlled by the charging and discharging of the capacitor The capacitor charges through Ra and Rb but discharges through the discharge pin (pin 7) and thus only through Rb The time that the capacitor takes to charge or discharge is given as T = 0.7 R C Thus the charge time is 0.7 (Ra + Rb) C The discharge time is 0.7 Rb C Giving a total time of (0.7 (Ra + Rb) C) + (0.7 Rb C) = 0.7 (Ra + 2Rb) C The time the output is high (mark) is thus always longer than the time the output is low (space) The 555 astable cannot produce a square wave!
47

Operation of the 555


It is not necessary to know how the 555 works. In fact a systems approach to electronics would never consider how any such sub-block works. However, a knowledge of how the 555 functions is useful. A much simplified block diagram of the 555 timer is shown:

FIG 3.13 (f): OPERATION OF 555TIMER The resistors are arranged across the power supply to form a potential divider. The voltages at the junctions of the potential divider are 2/3 Vcc and 1/3 Vcc. They are connected to the inputs to a pair of comparators.

One comparator, switching at 2/3 Vcc is controlled via the threshold input. The voltage at which the threshold comparator switches can be changed from 2/3 Vcc by applying a voltage to the control pin. This pin is usually decoupled to ground via a 10nF capacitor and, in this case, the comparator switches at 2/3 Vcc as expected.

One comparator, switching at 1/3 Vcc is controlled via the trigger input. The outputs from the two comparators control a set-reset flip flop (bistable). The reset pin of the 555 (not of the bistable) is usually held high. Taking this pin momentarily low apply a voltage to the reset pin of the flip flop and the output falls to zero.

The output of the flip flop is connected to the output pin via a power amplifier circuit which includes short circuit protection etc.
48

The output goes high when the trigger input is less than 1/3 Vcc. The output then remains high until the threshold input rises above 2/3 Vcc. When the output is low, the discharge pin is connected to ground via a transistor. The capacitor can be organized to discharge through this pin but the value of the capacitor should be less than 1000F to avoid damaging the transistor.

4.SOFTWARE REQUIREMENTS
4.1 INTRODUCTION TO KEIL MICRO VISION (IDE)
Keil an ARM Company makes C compilers, macro assemblers, real-time kernels, debuggers, simulators, integrated environments, evaluation boards, and emulators for ARM7/ARM9/Cortex-M3, XC16x/C16x/ST10, 251, and 8051 MCU families. 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. When starting a new project, simply select the microcontroller you use from the Device Database and the Vision IDE sets all compiler, assembler, linker, and memory options for you. Keil is a cross compiler. So first we have to understand the concept of compilers and cross compilers. After then we shall learn how to work with keil.

4.2 CONCEPT OF COMPILER


Compilers are programs used to convert a High Level Language to object code. Desktop compilers produce an output object code for the underlying microprocessor, but not for other microprocessors. I.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 in the computer). For example compilers for Dos platform is different
49

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. The compiler derives its name from the way it works, looking at the entire piece of source code and collecting and reorganizing the instruction. See there is a bit little difference between compiler and an interpreter. Interpreter just interprets whole program at a time while compiler analyses and execute each line of source code in succession, without looking at the entire program. The advantage of interpreters is that they can execute a program immediately. Secondly programs produced by compilers run much faster than the same programs executed by an interpreter. However compilers require some time before an executable program emerges. Now as compilers translate source code into object code, which is unique for each type of computer, many compilers are available for the same language.

4.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). It means being in one environment you are writing a code for another environment is called cross development. And the compiler used for cross development is called cross compiler. So the definition of cross compiler is a compiler that runs on one computer but produces object code for a different type of computer.

4.4 KEIL C CROSS COMPILER


Keil is a German based Software development company. It provides several development tools like IDE (Integrated Development environment) Project Manager Simulator Debugger
50

C Cross Compiler, Cross Assembler, Locator/Linker

The Keil ARM tool kit includes three main tools, assembler, compiler and linker. An assembler is used to assemble the ARM assembly program. A compiler is used to compile the C source code into an object file. A linker is used to create an absolute object module suitable for our in-circuit emulator.

4.5 Building an Application in Vision2


To build (compile, assemble, and link) an application in Vision2, you must:
1. Select Project -(forexample,166\EXAMPLES\HELLO\HELLO.UV2).

2. Select Project - Rebuild all target files or Build target.Vision2 compiles, assembles, and links the files in your project.

4.6 Creating Your Own Application in Vision2


To create a new project in Vision2, you must: 1. Select Project - New Project. 2. Select a directory and enter the name of the project file. 3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the Device Database. 4. Create source files to add to the project. 5. Select Project - Targets, Groups, Files. Add/Files, select Source Group1, and add the source files to the project. 6. Select Project - Options and set the tool options. Note when you select the target device from the Device Database all special options are set automatically. You typically only need to configure the memory map of your target hardware. Default memory model settings are optimal for most applications. 7. Select Project - Rebuild all target files or Build target.

4.7 Debugging an Application in Vision2


To debug an application created using Vision2, you must: 1. Select Debug - Start/Stop Debug Session.
51

2. Use the Step toolbar buttons to single-step through your program. You may enter

G, main in the Output Window to execute to the main C function.


3. Open the Serial Window using the Serial #1 button on the toolbar.

Debug your program using standard options like Step, Go, Break, and so on.

4.8 Starting Vision2 and Creating a Project


Vision2 is a standard Windows application and started by clicking on the program icon. To create a new project file select from the Vision2 menu Project New Project. This opens a standard Windows dialog that asks you for the new project file name. We suggest that you use a separate folder for each project. You can simply use the icon Create New Folder in this dialog to get a new empty folder. Then select this folder and enter the file name for the new project, i.e. Project1. Vision2 creates a new project file with the name PROJECT1.UV2 which contains a default target and file group name. You can see these names in the Project.

4.9 Window Files.


Now use from the menu Project Select Device for Target and select a CPU for your project. The Select Device dialog box shows the Vision2 device data base. Just select the microcontroller you use. We are using for our examples the Philips 80C51RD+ CPU. This selection sets necessary tool Options for the 80C51RD+ device and simplifies in this way the tool Configuration.

4.10 Building Projects and Creating a HEX Files


Typical, the tool settings under Options Target are all you need to start a new application. You may translate all source files and line the application with a click on the Build Target toolbar icon. When you build an application with syntax errors, Vision2 will display errors and warning messages in the Output Window Build page. A double click on a message line opens the source file on the correct location in a Vision2 editor window. Once you have successfully generated your application you can start debugging.

52

After you have tested your application, it is required to create an Intel HEX file to download the software into an EPROM programmer or simulator. Vision2 creates HEX files with each build process when Create HEX files under Options for Target Output is enabled. You may start your PROM programming utility after the make process when you specify the program under the option Run User Program #1.

4.11 CPU Simulation


Vision2 simulates up to 16 Mbytes of memory from which areas can be mapped for read, write, or code execution access. The Vision2 simulator traps and reports illegal memory accesses. In addition to memory mapping, the simulator also provides support for the integrated peripherals of the various 8051 derivatives. The onchip peripherals of the CPU you have selected are configured from the Device.

4.12 Database selection


You have made when you create your project target. Refer to page 58 for more Information about selecting a device. You may select and display the on-chip peripheral components using the Debug menu. You can also change the aspects of each peripheral using the controls in the dialog boxes.

4.13 Start Debugging


You start the debug mode of Vision2 with the Debug Start/Stop Debug Session Command. Depending on the Options for Target Debug Configuration, Vision2 will load the application program and run the startup code Vision2 saves the editor screen layout and restores the screen layout of the last debug session. If the program execution stops, Vision2 opens an editor window with the source text or shows CPU instructions in the disassembly window. The next executable statement is marked with a yellow arrow. During debugging, most editor features are still available.

53

For example, you can use the find command or correct program errors. Program source text of your application is shown in the same windows. 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. The additional debug windows are discussed in the following. _ The project structure or tool parameters cannot be modified. All build commands are disabled.

4.14 Disassembly Window


The Disassembly window shows your target program as mixed source and assembly program or just assembly code. A trace history of previously executed instructions may be displayed with Debug View Trace Records. To enable the trace history, set Debug Enable/Disable Trace Recording. If you select the Disassembly Window as the active window all program step commands work on CPU instruction level rather than program source lines. You can select a text line and set or modify code breakpoints using toolbar buttons or the context menu commands. You may use the dialog Debug Inline Assembly to modify the CPU instructions. That allows you to correct mistakes or to make temporary changes to the target program you are debugging. Numerous example programs are included to help you get started with the most popular embedded 8051 devices. The Keil Vision Debugger accurately simulates on-chip peripherals (IC, CAN, UART, SPI, Interrupts, I/O Ports, A/D Converter, D/A Converter, and PWM Modules) of your 8051 device. Simulation helps you understand hardware configurations and avoids time wasted on setup problems. Additionally, with simulation, you can write and test applications before target hardware is available.

54

4.15 EMBEDDED C
Use of embedded processors in passenger cars, mobile phones, medical equipment, aerospace systems and defense systems is widespread, and even everyday domestic appliances such as dish washers, televisions, washing machines and video recorders now include at least one such device. Because most embedded projects have severe cost constraints, they tend to use low-cost processors like the 8051 family of devices considered in this book. These popular chips have very limited resources available most such devices have around 256 bytes (not megabytes!) of RAM, and the available processor power is around 1000 times less than that of a desktop processor. As a result, developing embedded software presents significant new challenges, even for experienced desktop programmers. If you have some programming experience - in C, 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.

5.SCHEMATIC DIAGRAM
55

56

57

Fig.5: Schematic Diagram

58

5.1 DESCRIPTION
POWER SUPPLY
The circuit uses standard power supply comprising of a step-down transformer from 230v to 12v and 4 diodes forming a Bridge Rectifier that delivers pulsating dc which is then filtered by an electrolytic capacitor of about 470microf to 100microF. The filtered dc being un regulated IC LM7805 is used to get 5v constant at its pin no 3 irrespective of input dc varying from 9v to 14v. The input dc shall be varying in the event of input ac at 230volts section varies in the ratio of v1/v2=n1/n2. The regulated 5volts dc is further filtered by a small electrolytic capacitor of 10 micro f for any noise so generated by the circuit. One LED is connected of this 5v point in series with a resistor of 330ohms to the ground i.e. negative voltage to indicate 5v power supply availability. The 5v dc is at 12v point is used for other applications as on when required.

STANDARD CONNECTIONS TO MICRO CONTROLLER


ATMEL series of 8051 family of micro controllers need certain standard connections. The actual number of the Micro controller could be 89C51 , 89C52 , 89S51 , 89S52 , as regards to 20 pin configuration a number of 89C2051. The 4 set of I/O ports are used based on the project requirement. Every micro controller 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. A crystal ranging from 2 to 20 MHz are required to be used at its pin number 18 and 19 for the oscillator. Typically 11.0592 MHz crystal is used in general for most of
59

the circuits. Crystal provides the reference frequency only and it is not a crystal oscillator as miss understood by many but it oscillates at 11.0592MHz. Two small value ceramic capacitors of 33PF each is used as a standard connection for the crystal as shown in the circuit diagram.

RESET:
Pin no 9 is provided with an RESET arrangement by a combination of an electrolytic capacitor and a register forming RC time constant. At the time of switch on the capacitor gets charging supply behaving a full short circuit from the positive to the pin number 9 in this early .After the capacitor gets fully charged the current stops flowing and pin number 9 is pulled down by a 10k resistor to the ground. This arrangement of reset pin 9 going high initially and then to 0 i.e. low helps the program execution to start from the beginning. In absence of this the program execution could have taken place habitually anywhere from the program cycle .A pushbutton switch is connected across the capacitor so that at any given time as desired can be pressed that discharges the capacitor and while released the capacitor starts charging again and then pin number 9 goes to high and then back to low , to enable the program re execution from the beginning. 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. For example: A 10 microf capacitor and a 10k resistor would render a 100ms time to pin number 9 from high to low , there after the pin number 9 remains low.

60

OPERATION EXPLANATION
Connections
In this project of Object Counting of Seven Segment Display we are using on Board power supply using stop down transformer, bridge rectifier & voltage regulator o/p of the regulator 7805 from Pin 3 is connected to 40th Pin of Microcontroller and 20th Pin is connected to 2nd Pin of 7805 is GND. Here we using two TSOP 1738 and two 555 timers which makes two different sections. First TSOP which consist of 3 Pins. Whos first Pin is connected to GND 2nd Pin is connected to VCC & 3rd Pin is connected to base of the transistor (BC547) whose collector is connected to +5V through resistor of 3.3k. Where emitter is connected to GND and Pin 2 of 555 timer is connected to collector of transistor Pin 8 is connected to +5V Pin 4 & 7 is connected to VCC through resistor of 100K. Pin 1 is connected to GND 3rd Pin is o/p Pin which is connected to 2nd Pin of Microcontroller with one LED and resistor of B30R. Pin 5 is connected to GND. Same connection will be followed for other section of ISOP and 555 but 3 rd Pin of 555 is connected to first Pin of Microcontroller for display purpose we are using two seven segment display whose seven Pins are connected to Port 0 of Microcontroller starting from Pin 33 to 39 through 330R resistors Pin no 32 of Microcontroller is connected to Base of the transistor BC547 which is used to drive the display whose emitters are connected to 7 segment display 26th Pin of Microcontroller is connected to Base 2nd transistor whose collector is connected to -5V.

Working
The project uses a pair of IR transmitter formed out of 555 U1 & U2 in the circuit 19,IR transmitter 555 2/2 used in astable mode at 38khz being delivered from pin 3 of both the timers that drives the IR LEDs via R4 & R9 through transistors BC547. A pair of receivers using TSOP1738 as seen in the circuit diagram bottle counter whose o/p at pin no 3drives transistor BC547 via 100k resistor. While the transmitter IR light falls on the TSOP1738 its o/p goes low that maintain logic HIGH being driven from the collector at pin no 2 of 555 timers. This results in o/p pin 3 to remain LOW placing a logic zero at pin 2 of the microcontroller. Similar arrangement is made for receiving logical signal at
61

pin 1 of the microcontroller when the light falling on TSOP is interrupted by movement of a bottle. The TSOP o/p goes high that results the transistor (BC547) collector to go low placing (-ve) trigger pulse to 555 timer that results in pin 3 going high placing a logic 1 at pin 2 of microcontroller this further indicated by one led connected in series with a 330ohm resistor to GND this change in logic state advances the counter by executing the program on the microcontroller which is displayed by 2 numbers of seven segment displays duly interfaced from port ZERO and are driven by a two transistors BC547 from pin 32 and 26 of the microcontroller. The modulated 38 KHz signals are fed to one IR diode which is received by the TSOP1738 placed opposite to the IR diode at a distance. While one set say A is placed at the entrance and another set B is placed little away from the first set. While a bottle enters the belt IR interrupt takes place 1st at A and then B. The receiver A and B outputs connected to port 1.0 and 1.1 accordingly go high from low to enable the program incrementing the count at the display. Thus every bottle that enters from A to B the counting advances. Which is displayed by the seven segment display

62

6. LAYOUT DIAGRAM

Fig.6: Layout Diagram

63

8.CODING
8.1 COMPILER
1. 2. Click on the Keil Vision Icon on Desktop The following fig will appear

3. 4.

Click on the Project menu from the title bar Then Click on New Project

64

5.

Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\

6. 7. 8.

Then Click on Save button above. Select the component for u r project. i.e. Atmel Click on the + Symbol beside of Atmel
65

9.

Select AT89C51 as shown below

10. 11.

Then Click on OK The Following fig will appear

66

12. 13. 14.

Then Click either YES or NOmostly NO. Now your project is ready to USE. Now double click on the Target1, you would get another option Source group 1 as shown in next page.

15.

Click on the file option from menu bar and select new.

67

16.

The next screen will be as shown in next page, and just maximize it by double clicking on its blue boarder.

17. 18.

Now start writing program in either in EMBEDDED C or ASM. For a program written in Assembly, then save it with extension . asm and for EMBEDDED C based program save it with extension .C

68

19.

Now right click on Source group 1 and click on Add files to Group Source.

20.

Now you will get another window, on which by default EMBEDDED C files will appear.

69

21. 22. 23.

Now select as per your file extension given while saving the file Click only one time on option ADD. Now Press function key F7 to compile. Any error will appear if so happen.

24. 25.

If the file contains no error, then press Control+F5 simultaneously. The new window is as follows

70

26. 27.

Then Click OK. Now click on the Peripherals from menu bar, and check your required port as shown in fig below.

28.

Drag the port a side and click in the program file.

71

29. 30.

Now keep Pressing function key F11 slowly and observe. You are running your program successfully.

8.2 PROGRAM CODE

#include<reg52.h> sbit sbit bit bit bit bit //sbit relay gate1 gate2 = = gate1_falg gate2_falg flag1 flag2 = P1^0; P1^1; = = = = P2^7;
72

0x10; 0x11; 0x12; 0x13;

//7- segment digit selection

sbit sbit

digit1 digit2

= =

P0^7; P2^5;

//7 segments hardware pins sbit sbit sbit sbit sbit sbit sbit seg_A seg_B seg_C seg_D seg_E seg_F seg_G = = = = = = = P0^2; P0^3; P0^4; P0^6; P0^5; P0^1; P0^0;

void timer0_init(); void led_display(unsigned char void delay(unsigned char ch); unsigned char data char data digit = 0x30; temp);

count = 0x31;

void main() { flag1 = flag2 = 0; //relay = 0; digit1 = 0; digit2 = 0; digit = 0;


73

count = 0; gate1_falg = 0; gate2_falg = 0; gate1 = 1; gate2 = 1; timer0_init(); while(1) { if(gate1 == 0) { while(gate2 == 1); count = count+1; if(count == 99) count =0; delay(250); } else { if(gate2 == 0) { while(gate1 == 1); count = count-1; if(count <= 0) { count = 0;
74

} delay(250); } } } }

void timer0_init() { TMOD = 0X01; TH0 = 0XFF; TL0 = 0XFE; ET0 = 1; TR0 = 1; }

void timer0_isr(void) interrupt 1 { if(digit == 0) { digit1 = 1; digit2 = 0; led_display(count/10);

} else if(digit == 1)
75

{ digit1 = 0; digit2 = 1; led_display(count%10);

digit = digit+1; if(digit == 2) digit = 0; TH0 = 0XFF; TL0 = 0XFE; } void delay(unsigned char ch) { unsigned char i; for(i=0;i<ch;i++); }

void led_display(unsigned char { if(temp == 0) { seg_A = 0; seg_B = 0; seg_C = 0;

temp)

76

seg_D = 0; seg_E = 0; seg_F = 0; seg_G = 1; } else if(temp == 1) { seg_A = 1; seg_B = 0; seg_C = 0; seg_D = 1; seg_E = 1; seg_F = 1; seg_G = 1; } else if(temp == 2) { seg_A = 0; seg_B = 0; seg_C = 1; seg_D = 0; seg_E = 0; seg_F = 1; seg_G = 0; } else if(temp == 3)
77

seg_A = 0; seg_B = 0; seg_C = 0; seg_D = 0; seg_E = 1; seg_F = 1; seg_G = 0; } else if(temp == 4) {

seg_A = 1; seg_B = 0; seg_C = 0; seg_D = 1; seg_E = 1; seg_F = 0; seg_G = 0; } else if(temp == 5) { seg_A = 0; seg_B = 1; seg_C = 0;
78

seg_D = 0; seg_E = 1; seg_F = 0; seg_G = 0; } else if(temp == 6) { seg_A = 0; seg_B = 1; seg_C = 0; seg_D = 0; seg_E = 0; seg_F = 0; seg_G = 0; } else if(temp == 7) { seg_A = 0; seg_B = 0; seg_C = 0; seg_D = 1; seg_E = 1; seg_F = 1; seg_G = 1; } else if(temp == 8)
79

{ seg_A = 0; seg_B = 0; seg_C = 0; seg_D = 0; seg_E = 0; seg_F = 0; seg_G = 0; } else if(temp == 9) { seg_A = 0; seg_B = 0; seg_C = 0; seg_D = 0; seg_E = 1; seg_F = 0; seg_G = 0; } else { seg_A = 1; seg_B = 1; seg_C = 1; seg_D = 1; seg_E = 1;
80

seg_F = 1; seg_G = 1; }

81

9.HARDWARE TESTING
9.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.

82

9.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. 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 40th 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.

83

10. RESULT

84

11. CONCLUSION

12.BIBLIOGRAPHY
85

TEXT BOOKS REFERED


1. The 8051 Microcontroller and Embedded systems by Muhammad Ali Mazidi and Janice Gillespie Mazidi, Pearson Education. 2. ATMEL 89S52 Data Sheets.

WEBSITES
www.atmel.com www.beyondlogic.org www.wikipedia.org www.howstuffworks.com www.alldatasheets.com

86

You might also like