Sunteți pe pagina 1din 64

Table of Contents Download the original attachment

1.Introduction 2. Literature survey 3.Formation of the Problem 4.System specification 5.Design of solution 6.Implementation 7.Results and Discussions 8.System testing 9.Conclusion and future scope 10.References

List of Figures Figure 2.1 A typical embedded system block diagram Figure 2.2 The structure of a GSM network Figure 4.1: AT89C51 Pin Diagram Figure 4.2 Oscillator and timing circuit Figure 4.3 SMOD Register Figure 4.4 TCON Register Figure 4.5 TMOD Register Figure 4.6 IE Register Figure 4.7 IP Register Figure 4.8 PSW Register Figure 4.9 PORT3 Alternate Use Figure 4.10 Data framing Figure 4.11 Data transfer Figure 4.12 SCON Register Figure 4.13 UART modes Figure 4.14Voltage levels for RS232 and TTL ABSTRACT

TITLE:

DENSITY BASED TRAFFIC LIGHT CONTROL SYSTEM

AIM:

The main objective of this project is to control the traffic lights based on the density of the vehicles. DESCRIPTION: In this system IR sensors are used to measure the density of the vehicles which are fixed within a fixed distance. All the sensors are interfaced with the microcontroller which in turn controls the traffic signal system according to density detected by the sensors.

If the traffic density is high on particular side more priority is given for that side. The sensors continuously keep sensing density on all sides and the green signal is given to the side on priority basis, where the sensors detect high density. The side with next priority level follows the first priority level.

By using this system traffic can be cleared without irregularities and time delays even though there is no traffic on the other side can be avoided.

SOFTWARE: Embedded C. TOOLS USED: KEIL uvision2 IDE HARDWARE: 1. PCB for micro controllers 2. 8051 controller, 3. DB9 Connectors 4. IR sensor pairs 5. Red, green LEDs 6. 11.0592 MHz quartz crystal, 7. Resistors, Capacitors

BLOCK DIAGRAM

IR - E

LCD

Traffic signal lights

89C51

Key board

Step down
T/F

Bridge Rectifier

Filter Circuit

Regulator

Power supply to all sections

CHAPTER 1

Introduction 1.1Overview
The overview of this project is to implement Density based traffic controlling system using IR technology and 89S52 controller. 89S52 is very efficient architecture which can be used for low end security systems and IR is widely adapted technology for communication.

1.2Purpose
Purpose of the current work is to study and analyse the counting and controlling system by using 8051 controller.

1.3 Scope
Current work focuses on how to use effectively IR and 8051 controllers for digital security systems.

CHAPTER 2 Literature survey

2.1 Embedded Systems


An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, often with real-time computing constraints. It is usually embedded as part of a complete device including hardware and mechanical parts. In contrast, a general-purpose computer, such as a personal computer, can do many different tasks depending on programming. Embedded systems control many of the common devices in use today.

Since the embedded system is dedicated to specific tasks, design engineers can optimize it, reducing the size and cost of the product, or increasing the reliability and performance. Some embedded systems are mass-produced, benefiting from economics of scale. Physically, embedded systems range from portable devices such as digital watches and mp4 players, to large stationary installations like traffic lights, factory controllers, or the systems controlling nuclear power stations. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure. In general, "embedded system" is not an exactly defined term, as many systems have some element of programmability. For example, handheld computers share some elements with embedded systems such as the operating systems and microprocessors which power them but are not truly embedded systems, because they allow different applications to be loaded and peripherals to be connected

2.2 Characteristics
1. Embedded systems are designed to do some specific task, rather than be a general-purpose computer for multiple tasks. Some also have real-time performance constraints that must be met, for reasons such as safety and usability; others may have low or no performance requirements, allowing the system hardware to be simplified to reduce costs. 2. Embedded systems are not always standalone devices. Many embedded systems consist of small, computerized parts within a larger device that serves a more general purpose. For example, the features an embedded system for tuning the strings, but the overall purpose of the Robot Guitar is, of course, to play music. Similarly, an embedded system in automobiles provides a specific function as a subsystem of the car itself. 3. The program instructions written for embedded systems are referred to as firmware, and are stored in read-only memory or flash memory chips. They run with limited computer hardware resources: little memory, small or non-existent keyboard and/or screen.

Figure 2.1 A typical embedded system block diagram

2.3 Micro Controllers

The micro controller, nowadays, is an indispensable device for electrical/electronic engineers and also for technicians in the area, because of its versatility and its enormous application. .Born of parallel developments in computer architecture and integrated circuit fabrication ,the microprocessor or computer on chip first becomes a commercial reality in 1971.with the introduction of the 4 bit 4004 by a small, unknown company by the name of Intel corporation. Other, well established, semiconductor firms soon followed Intels pioneering technology so that by the late 1970s we could choose from a half dozen or so micro processor typThe 1970s also saw the growth of the number of personal computer users from a Handful of hobbyists and hackers to millions of business, industrial, governmental, defense, and educational and private users now enjoying the advantages of inexpensive computing. A bye product of microprocessor development was the micro controller. The same fabrication techniques and programming concepts that make possible general-purpose microprocessor also yielded the micro controller. Among the applications of a micro controller we can mention industrial automation, mobile telephones, radios, microwave ovens and VCRs. Besides, the present trend in digital electronics is toward restricting to micro controllers and chips that concentrate a great quantity of logical circuits, like PLDs (Programmable Logic Devices) and GALs (Gate Array Logic). In dedicated systems, the micro controller is the best solution, because it is cheap and easy to manage.

2.6 Communication:

Communication refers to the sending, receiving and processing of information by electric means. As such, it started with wire telegraphy in the early 80s, developing with telephony and radio some decades later. Radio communication became the most widely used and refined through the invention of and use of transistor, integrated circuit, and other semi-conductor devices. Most recently, the use of satellites and fiber optics has made communication even more wide spread, with an increasing emphasis on computer and other data communications.

A modern communications system is first concerned with the sorting, processing and storing of information before its transmission. The actual transmission then follows, with further processing and the filtering of noise. Finally we have reception, which may include processing steps such as decoding, storage and interpretation. In this context, forms of communications include radio, telephony and telegraphy, broadcast, point to point and mobile communications (commercial and military), computer communications, radar, radio telemetry and radio aids to navigation. It is also important to consider the human factors influencing a particular system, since they can always affect its design, planning and use.

Wireless communication has become an important feature for commercial products and a popular research topic within the last ten years. There are now more mobile phone subscriptions than wired-line subscriptions. Lately, one area of commercial interest has been low-cost, low-power, and short-distance wireless communication used for personal wireless networks." Technology advancements are providing smaller and more cost effective devices for integrating computational processing, wireless communication, and a host of other functionalities. These embedded communications devices will be integrated into applications ranging from homeland security to industry automation and monitoring. They will also enable custom tailored engineering solutions, creating a revolutionary way of disseminating and processing information. With new technologies and devices come new business activities, and the need for employees in these technological areas. Engineers who have knowledge of embedded systems and wireless communications will be in high demand. Unfortunately, there are few adorable environments available for development and classroom use, so students often do not learn about these technologies during hands-on lab exercises. The communication mediums were twisted pair, optical fiber, infrared, and generally wireless radio.

2.7

IR Remote Theory

The cheapest way to remotely control a device within a visible range is via Infra-Red light. Almost all audio and video equipment can be controlled this way nowadays. Due to this wide spread use the required components are quite cheap, thus making it ideal for us hobbyists to use IR control for our own projects. IR sensor is the combination of IR LED with PHOTO DIODE. After this combination we are connecting the DARLINGTON PAIR TRANSISTOR. End of the IR sensor we have to connect a NOT gate for the inverting purpose means low input have corresponding low output. At last this entire connector is connected to any one external interrupt to generating the interruption of the main program.

Infra-Red actually is normal light with a particular colour. We humans can't

see this

colour because its wave length of 950nm is below the visible spectrum. That's one of the reasons why IR is chosen for remote control purposes, we want to use it but we're not interested in seeing it. Another reason is because IR LEDs are quite easy to make, and therefore can be very cheap.
IR LED wave length range 1.6m to 2.4m. Materials used for IR LED are InSB, Ge,Si, GaAs, CdSe . These IR s are not visible range for observation purpose we have to connect LED s are not.

CHAPTER 3

Problem formulation
The problem with the traffic system is that for every minute the vehicles at the 4-way road will be heavy and the traffic lights shall be changed to each side for some fixed time. Even though there are no vehicles at particular side, the traffic signals will glow for given fixed time.Due to that there is time waste process. Due to this other side vehicles have to wait for the time to complete the process. So to reduce the wastage of time, we can implement the system that controls the traffic based on the heavy flow of vehicles at any particular side. With this system, we shall count the number of vehicles at each side at the junction and give th path to the particular side which has heavy flow of vehicles and keep remaining stop position. So that for this to count the number of vehicles at side of the junction, we shall use IR technology.

CHAPTER 4

System Specification 4.1 89S52 Micro Controller


Features: Compatible with MCS-51 Products 8K Bytes of In-System Programmable (ISP) Flash Memory Endurance: 1000 Write/Erase Cycles 4.0V to 5.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

Description The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of insystem programmable Flash memory. The device is manufactured using Atmels high-density nonvolatile 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 nonvolatile 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 highlyflexible 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 twolevel interrupt architecture, a full duplex serial port, on-chip 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.

Pin Description VCC: Pin 40 provides supply voltage to the chip. The voltage source is + 5V. GND: Pin 20 provides 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 high impedance 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. 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), respectively, as shown in the following table. Port 1 also receives the low-order address bytes during Flash programming and verification.

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 2 also receives the high-order address bits and some control signals during Flash programming and verification. 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. Port 3 also serves the functions of various special features of the AT89S52, as shown in the following table. Port 3 also receives some control signals for Flash programming and verification.

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 96 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. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode. PSEN: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.

Special Function Registers


A map of the on-chip memory area called the Special Function Register (SFR) space is shown in Table 1. Note that not all of the addresses are occupied, and unoccupied addresses may not be implemented on the chip. Read accesses to these addresses will in general return random data, and write accesses will have an indeterminate effect. User software should not write 1s to these unlisted locations, since they may be used in future products to invoke new features. In that case, the reset or inactive values of the new bits will always be 0. Timer 2 Registers: Control and status bits are contained in registers T2CON (shown in Table 2) and T2MOD (shown in Table 3) for Timer 2. The register pair (RCAP2H, RCAP2L) is the Capture/Reload registers for Timer 2 in 16-bit capture mode or 16-bit auto-reload mode. Interrupt Registers: The individual interrupt enable bits are in the IE register. Two priorities can be set for each of the six interrupt sources in the IP register.

Dual Data Pointer Registers: To facilitate accessing both internal and external data memory, two banks of 16-bit Data Pointer Registers are provided: DP0 at SFR address locations 82H-83H and DP1 at 84H85H. Bit DPS = 0 in SFR AUXR1 selects DP0 and DPS = 1 selects DP1. The user should always initialize the DPS bit to the appropriate value before accessing the respective Data Pointer Register.

Power Off Flag: The Power Off Flag (POF) is located at bit 4 (PCON.4) in the PCON SFR. POF is set to 1 during power up. It can be set and rest under software control and is not affected by reset.

Memory Organization
MCS-51 devices have a separate address space for Program and Data Memory. Up to 64K bytes each of external Program and Data Memory can be addressed. Program Memory If the EA pin is connected to GND, all program fetches are directed to external memory. On the AT89S52, if EA is connected to VCC, program fetches to addresses 0000H through 1FFFH are directed to internal memory and fetches to addresses 2000H through FFFFH are to external memory. Data Memory The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel address space to the Special Function Registers. This means that the upper 128 bytes have the same addresses as the SFR space but are physically separate from SFR space. When an instruction accesses an internal location above address 7FH, the address mode used in the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR space. Instructions which use direct addressing access of the SFR space. For example, the following direct addressing instruction accesses the SFR at location 0A0H (which is P2).

MOV 0A0H, #data Instructions that use indirect addressing access the upper 128 bytes of RAM. For example, the following indirect addressing instruction, where R0 contains 0A0H, accesses the data byte at address 0A0H, rather than P2 (whose address is 0A0H). MOV @R0, #data Note that stack operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available as stack space.

Watchdog Timer
(One-time Enabled with Reset-out) The WDT is intended as a recovery method in situations where the CPU may be subjected to software upsets. The WDT consists of a 13-bit counter and the Watchdog Timer Reset (WDTRST) SFR. The WDT is defaulted to disable from exiting reset. To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H). When the WDT is enabled, it will increment every machine cycle while the oscillator is running. The WDT timeout period is dependent on the external clock frequency. There is no way to disable the WDT except through reset (either hardware reset or WDT overflow (reset). When WDT overflows, it will drive an output RESET HIGH pulse at the RST pin. Using the WDT To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H). When the WDT is enabled, the user needs to service it by writing 01EH and 0E1H to WDTRST to avoid a WDT overflow. The 13-bit counter overflows when it reaches 8191 (1FFFH), and this will reset the device. When the WDT is enabled, it will increment every machine cycle while the oscillator is running. This means the user must reset the WDT at least every 8191 machine cycles. To reset the WDT the user must write 01EH and 0E1H to WDTRST. DTRST is a write-only register. The WDT counter cannot be read or written. When WDT overflows, it will generate an output RESET pulse at the RST pin. The RESET pulse duration is 96xTOSC, where TOSC=1/FOSC. To make the best use of the WDT, it should be serviced in those sections of code that will periodically be executed within the time required

to prevent a WDT reset.

WDT during Power-down and Idle In Power-down mode the oscillator stops, which means the WDT also stops. While in Powerdown mode, the user does not need to service the WDT. There are two methods of exiting Power-down mode: by a hardware reset or via a level-activated external interrupt which is enabled prior to entering Power-down mode. When Power-down is exited with hardware reset, servicing the WDT should occur as it normally does whenever the AT89S52 is reset. Exiting Power-down with an interrupt is significantly different. The interrupt is held low long enough for the oscillator to stabilize. When the interrupt is brought high, the interrupt is serviced. To prevent the WDT from resetting the device while the interrupt pin is held low, the WDT is not started until the interrupt is pulled high. It is suggested that the WDT be reset during the interrupt service for the interrupt used to exit Power-down mode. To ensure that the WDT does not overflow within a few states of exiting Power-down, it is best to reset the WDT just before entering Power-down mode. Before going into the IDLE mode, the WDIDLE bit in SFR AUXR is used to determine whether the WDT continues to count if enabled. The WDT keeps counting during IDLE WDIDLE bit = 0) as the default state. To prevent the WDT from resetting the AT89S52 while in IDLE mode, the user should always set up a timer that will periodically exit IDLE, service the WDT, and reenter IDLE mode. With WDIDLE bit enabled, the WDT will stop to count in IDLE mode and resumes the count upon exit from IDLE. UART Serial data communication uses two methods, asynchronous and synchronous. The synchronous method transfers a block of data (characters ) at a time, while the asynchronous method transfers a single byte at a time. It is possible to write software to use either of these methods, but programs can be tedious and long. For this reason, there are special IC chips made by the manufacturers for the serial data communications. These chips are commonly referred to as UART ( universal asynchronous receivertransmitter) and USART ( universal synchronous receiver-transmitter). The 8052 has built-in UART.

Timer 0 The 16-bit register of timer 0 is accessed as low byte and high byte. The low byte register is called TL0 ( Timer 0 low byte) and the high byte register is referred to as TH0 ( Timer 0 high byte). These registers can be accessed like any other registers , such as A,B,R0,R1,R2 etc. for example the instruction MOV TL0,#4FH moves the value 4FH into TL0, the low byte of Timer 0. These registers can also be read like any other register. For example, MOV R5,TH0 saves TH0 ( high byte of Timer 0) in R5. Timer1 Timer 1 is also 16 bits and its 16-bit register is split into two bytes, referred to as TL1 (Timer 1 low byte ) and TH1 ( Timer 1 high byte). These registers are accessible in the same way as the registers of Timer 0. Timer 2 Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event counter. The type of operation is selected by bit C/T2 in the SFR T2CON (shown in Table 2). Timer 2 has three operating modes: capture, auto-reload (up or down counting), and baud rate generator. The modes are selected by bits in T2CON, as shown in Table 3. Timer 2 consists of two 8-bit registers, TH2 and TL2. In the Timer function, the TL2 register is incremented every machine cycle. Since a machine cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency.

In the Counter function, the register is incremented in esponse to a 1-to-0 transition at its corresponding external input pin, T2. In this function, the external input is sampled during S5P2 of every machine cycle. When the samples show a high in one cycle and a low in the next cycle, the count is incremented. The new count value appears in the register during S3P1 of the cycle following the one in which the

transition was detected. Since two machine cycles (24 oscillator periods) are required to recognize a 1to-0 transition, the maximum count rate is 1/24 of the oscillator frequency. To ensure that a given level is sampled at least once before it changes, the level should be held for at least one full machine cycle. Capture Mode In the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 is a 16-bit timer or counter which upon overflow sets bit TF2 in T2CON. This bit can then be used to generate an interrupt. If EXEN2 = 1, Timer 2 performs the same operation, but a 1- to-0 transition at external input T2EX also causes the current value in TH2 and TL2 to be captured into RCAP2H and RCAP2L, respectively. In addition, the transition at T2EX causes bit EXF2 in T2CON to be set. The EXF2 bit, like TF2, can generate an interrupt. The capture mode is illustrated in Figure 5. Auto-reload (Up or Down Counter) Timer 2 can be programmed to count up or down when configured in its 16-bit auto-reload mode. This feature is invoked by the DCEN (Down Counter Enable) bit located in the SFR T2MOD (see Table 4). Upon reset, the DCEN bit is set to 0 so that timer 2 will default to count up. When DCEN is set, Timer 2 can count up or down, depending on the value of the T2EX pin.

options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow. The overflow also causes the timer registers to be reloaded with the 16-bit value in RCAP2H and RCAP2L. The values in Timer in Capture ModeRCAP2H and RCAP2L are preset by software. If EXEN2 = 1, a 16-bit reload can be Figure 6 shows Timer 2 automatically counting up when

DCEN=0. In this mode, two triggered either by an overflow or by a 1-to-0 transition at external input T2EX. This transition also sets the EXF2 bit. Both the TF2 and EXF2 bits can generate an interrupt if enabled. Setting the DCEN bit enables Timer 2 to count up or down, as shown in Figure 6. In this mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makes Timer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow also causes the 16-bit value in RCAP2H and RCAP2L to be reloaded into the timer registers, TH2 and TL2, respectively. A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH to be reloaded into the timer registers .The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a 17th bit of resolution. In this operating mode, EXF2 does not flag an interrupt.

Timer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in T2CON (Table 2). Note that the baud rates for transmit and receive can be different if Timer 2 is used for the receiver or transmitter and Timer 1 is used for the other function. Setting RCLK and/or TCLK puts Timer 2 into its baud rate generator mode, as shown in Figure 8. The baud rate generator mode is similar to the autoreload mode, in that a rollover in TH2 causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L, which are preset by software. The baud rates in Modes 1 and 3 are determined by Timer 2s overflow rate according to the following equation.

The Timer can be configured for either timer or counter operation. In most applications, it is configured for timer operation (CP/T2 = 0). The timer operation is different for Timer 2 when it is used as a baud rate generator. Normally, as a timer, it increments every machine cycle (at 1/12 the oscillator frequency). As a baud rate generator, however, it increments every state time (at 1/2 the oscillator

frequency). The baud rate formula is given below.

Where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-bit unsigned integer. Timer 2 as a baud rate generator is shown in Figure 8. This figure is valid only if RCLK or TCLK = 1 in T2CON. Note that a rollover in TH2 does not set TF2 and will not generate an interrupt. Note too, that if EXEN2 is set, a 1-to-0 transition in T2EX will set EXF2 but will not cause a reload from (RCAP2H, RCAP2L) to (TH2, TL2). Thus, when Timer 2 is in use as a baud rate generator, T2EX can be used as an extra external interrupt. Note that when Timer 2 is running (TR2 = 1) as a timer in the baud rate generator mode, TH2 or TL2 should not be read from or written to. Under these conditions, the Timer is incremented every state time, and the results of a read or write may not be accurate. The RCAP2 registers may be read but should not be written to; because a write might overlap a reload and cause write and/or reload errors. The timer should be turned off (clear TR2) before accessing the Timer 2 or RCAP2 registers. Interrupts The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), three timer interrupts (Timers 0, 1, and 2), and the serial port interrupt. These interrupts are all shown in Figure 10. Each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special Function Register IE. IE also contains a global disable bit, EA, which disables all interrupts at once. Note that Table 5 shows that bit position IE.6 is unimplemented. In the AT89S52, bit position IE.5 is also unimplemented. User software should not write 1s to these bit positions, since they may be used in future AT89 products. Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register T2CON. Neither of these flags is cleared by hardware when the service routine is vectored to. In fact, the service routine may have to determine whether it was TF2 or EXF2 that generated the interrupt, and that bit will have to be cleared in software. The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers overflow. The values are then polled by the circuitry in the next cycle. However, the Timer 2 flag, TF2, is set at S2P2 and is polled in the same cycle in which the timer overflows.

Oscillator Characteristics XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier that can be configured for use as an on-chip oscillator, as shown in Figure 11. 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 12. 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 flip-flop, but minimum and maximum voltage high and low time specifications must be

observed. Oscillator connections Note: C1, C2 = 30 pF 10 pF for Crystals = 40 pF 10 pF for Ceramic Resonators 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. Note that when idle mode is terminated by a hardware reset, the device normally resumes program execution from where it left off, up to two machine cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to internal RAM in this event, but access to the port pins is not inhibited. To eliminate the possibility of an unexpected write to a port pin when idle mode is terminated by a reset, the instruction following the one that invokes idle mode should not write to a port pin or to external memory. 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. Exit from Power-down mode can be initiated either by a hardware reset or by an enabled external interrupt. 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.

Status of External Pins during Idle and Power-down Modes

4. LIQUID CRYSTAL DISPLAY: LCD stands for Liquid Crystal Display. LCD is finding wide spread use replacing LEDs (seven segment LEDs or other multi segment LEDs) because of the following reasons: 1. The declining prices of LCDs. 2. The ability to display numbers, characters and graphics. This is in contrast to LEDs, which are limited to numbers and a few characters. 3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep displaying the data. 4. Ease of programming for characters and graphics.

These components are specialized for being used with the microcontrollers, which means that they cannot be activated by standard IC circuits. They are used for writing different messages on a miniature LCD.

A model described here is for its low price and great possibilities most frequently used in practice. It is based on the HD44780 microcontroller (Hitachi) and can display messages in two lines with 16 characters each . It displays all the alphabets, Greek letters, punctuation marks, mathematical symbols etc. In addition, it is possible to display symbols that user makes up on its own. Automatic shifting message on display (shift left and right), appearance of the pointer, backlight etc. are considered as useful characteristics. Pins Functions There are pins along one side of the small printed board used for connection to the microcontroller. There are total of 14 pins marked with numbers (16 in case the background light is built in). Their function is described in the table below: Function Ground Power supply Contrast Pin Number 1 2 3 Name Vss Vdd Vee Logic State Description 0V +5V 0 - Vdd D0 D7 are interpreted as commands D0 D7 are interpreted as data

RS

0 1

Control of operating

R/W

0 1

Write data (from controller to LCD) Read data (from LCD to controller) Access to LCD disabled Normal operating Data/commands are transferred to LCD Bit 0 LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 MSB

0 6 E 1 From 1 to 0

7 8 9 10 Data / commands 11 12 13 14 LCD screen:

D0 D1 D2 D3 D4 D5 D6 D7

0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1

LCD screen consists of two lines with 16 characters each. Each character consists of 5x7 dot matrix. Contrast on display depends on the power supply voltage and whether messages are displayed in one or two lines. For that reason, variable voltage 0-Vdd is applied on pin marked as Vee. Trimmer potentiometer is usually used for that purpose. Some versions of displays have built in backlight (blue or green diodes). When used during operating, a resistor for current limitation should be used (like with any LE diode).

LCD Basic Commands All data transferred to LCD through outputs D0-D7 will be interpreted as commands or as data, which depends on logic state on pin RS: RS = 1 - Bits D0 - D7 are addresses of characters that should be displayed. Built in processor addresses built in map of characters and displays corresponding symbols. Displaying position is determined by DDRAM address. This address is either previously defined or the address of previously transferred character is automatically incremented. RS = 0 - Bits D0 - D7 are commands which determine display mode. List of commands which LCD recognizes are given in the table below:
Command Clear display Cursor home Entry mode set Display on/off control Cursor/Display Shift Function set RS RW D7 D6 D5 D4 D3 D2 D1 D0 Execution Time 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 x 1.64mS 1.64mS 40uS 40uS 40uS 40uS

1 I/D S D U B x x

0 0 0 1 D/C R/L x 0 0 1 DL N F x

Set CGRAM address Set DDRAM address Read BUSY flag (BF) Write to CGRAM or DDRAM Read from CGRAM or DDRAM

0 0 0 1 1

0 0

0 1 1

CGRAM address DDRAM address DDRAM address

40uS 40uS 40uS 40uS

1 BF

0 D7 D6 D5 D4 D3 D2 D1 D0 1 D7 D6 D5 D4 D3 D2 D1 D0

I/D 1 = Increment (by 1) 0 = Decrement (by 1) S 1 = Display shift on 0 = Display shift off D 1 = Display on 0 = Display off U 1 = Cursor on 0 = Cursor off B 1 = Cursor blink on 0 = Cursor blink off LCD Connection

R/L 1 = Shift right 0 = Shift left DL 1 = 8-bit interface 0 = 4-bit interface N 1 = Display in two lines 0 = Display in one line F 1 = Character format 5x10 dots 0 = Character format 5x7 dots D/C 1 = Display shift 0 = Cursor shift

Depending on how many lines are used for connection to the microcontroller, there are 8bit and 4-bit LCD modes. The appropriate mode is determined at the beginning of the process in a phase called initialization. In the first case, the data are transferred through outputs D0-D7 as it has been already explained. In case of 4-bit LED mode, for the sake of saving valuable I/O pins of the microcontroller, there are only 4 higher bits (D4-D7) used for communication, while other may be left unconnected.

Consequently, each data is sent to LCD in two steps: four higher bits are sent first (that normally would be sent through lines D4-D7), four lower bits are sent afterwards. With the help of initialization, LCD will correctly connect and interpret each data received. Besides, with regards to the fact that data are rarely read from LCD (data mainly are transferred from microcontroller to LCD) one more I/O pin may be saved by simple connecting R/W pin to the Ground. Such saving has its price. Even though message displaying will be normally performed, it will not be possible to read from busy flag since it is not possible to read from display. LCD Initialization Once the power supply is turned on, LCD is automatically cleared. This process lasts for approximately 15mS. After that, display is ready to operate. The mode of operating is set by default. This means that: 1. Display is cleared 2. Mode DL = 1 Communication through 8-bit interface N = 0 Messages are displayed in one line F = 0 Character font 5 x 8 dots 3. Display/Cursor on/off D = 0 Display off U = 0 Cursor off B = 0 Cursor blink off 4. Character entry ID = 1 Addresses on display are automatically incremented by 1 S = 0 Display shift off

Automatic reset is mainly performed without any problems. Mainly but not always! If for any reason power supply voltage does not reach full value in the course of 10mS, display will start perform completely unpredictably. If voltage supply unit can not meet this condition or if it is needed to provide completely safe operating, the process of initialization by which a new reset enabling display to operate normally must be applied. Algorithm according to the initialization is being performed depends on whether connection to the microcontroller is through 4- or 8-bit interface. All left over to be done after that is to give basic commands and of course- to display messages.

Fig: Procedure on 8-bit initialization. CONTRAST CONTROL: To have a clear view of the characters on the LCD, contrast should be adjusted. To adjust the contrast, the voltage should be varied. For this, a preset is used which can behave like a variable voltage device. As the voltage of this preset is varied, the contrast of the LCD can be adjusted.

Potentiometer Variable resistors used as potentiometers have all three terminals connected. This arrangement is normally used to vary voltage, for example to set the switching point of a circuit with a sensor, or control the volume (loudness) in an amplifier circuit. If the terminals at the ends of the track are connected across the power supply, then the wiper terminal will provide a voltage which can be varied from zero up to the maximum of the supply.

Presets These are

Potentiometer Symbol

miniature versions of the standard variable

resistor. They are designed to be mounted directly onto the circuit board and adjusted only when the circuit is built. For example to set the frequency of an alarm tone or the sensitivity of a lightsensitive circuit. A small screwdriver or similar tool is required to adjust presets. Presets are much cheaper than standard variable resistors so they are sometimes used in projects where a standard variable resistor would normally be used. Multiturn presets are used where very precise adjustments must be made. The screw must be turned many times (10+) to move the slider from one end of the track to the other, giving very fine control.

Preset Symbol

LCD INTERFACING WITH THE MICROCONTROLLER:

P2.0 P2.1 P2.2

4 (RS) 5 (R/W) 6(EN)

1 2 3

LCD

Gnd

89S52

P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7

D0 D1 D2 D3 D4 D5 D6 D7 15 16

Infrared LED (IR LED)

IR sensor is the combination of IR LED with PHOTO DIODE. After this combination we are connecting the DARLINGTON PAIR TRANSISTOR. End of the IR sensor we have to connect a NOT gate for the inverting purpose means low input have corresponding low outputInfra-Red actually is normal light with a particular colour. We humans can't see this

colour because its wave length of 950nm is below the visible spectrum. That's one of the reasons why IR is chosen for remote control purposes, we want to use it but we're not interested in seeing it. Another reason is because IR LEDs are quite easy to make, and therefore can be very cheap. Although we humans can't see the Infra-Red light emitted from a remote control doesn't mean we can't make it visible. A video camera or digital photo camera can "see" the Infra-Red
light as you can see in this picture. If you own a web cam, point your remote to it, press any button and you'll see the LED flicker. They do dozens of different jobs and are found in all kinds of
devices. Among other things, they form the numbers on digital clocks, transmit information from remote controls, light up watches and tell you when your appliances are turned on. Collected together, they can form images on a jumbo television screen or illuminate a traffic light.

FIG.3.1 IR LED USED IN REMOTE CONTRO

DARLINGTON PAIR: An emitter follower offers high impedance of 500Kohms. For applications requiring still higher input impedance, we may use what is called Darlington in place of conventional transistor. This Darlington pair basically consists of two transistors cascaded in cc configuration. In the figure shown below the input impedance of the second transistor

Constitutes the load impedance of the first.

We thus conclude that in comparison with a conventional single transistor emitter follower has in higher current gain, higher input impedance and almost the same voltage gain lower out put impedances.

Fig:

Darlington Pair

Modulation
Modulation is the answer to make our signal stand out above the noise. With modulation we make the IR light source blink in a particular frequency. The IR receiver will be tuned to that frequency, so it can ignore everything else. You can think of this blinking as attracting the receiver's attention. We humans also notice the blinking of yellow lights at construction sites instantly, even in bright daylight.

In the picture above you can see a modulated signal driving the IR LED of the transmitter on the left side. The detected signal is coming out of the receiver at the other side. In serial communication we usually speak of 'marks' and 'spaces'. The 'space' is the default signal, which is the off state in the transmitter case. No light is emitted during the 'space' state. During the 'mark' state of the signal the IR light is pulsed on and off at a particular frequency. Frequencies between 30kHz and 60kHz are commonly used in consumer electronics.

At the receiver side a 'space' is represented by a high level of the receiver's output. A 'mark' is then automatically represented by a low level. Please note that the 'marks' and 'spaces' are not the 1-s and 0-s we want to transmit. The real relationship between the 'marks' and 'spaces' and the 1-s and 0-s depends on the protocol that's being used. More information about that can be found on the pages that describe the protocols.

TRANSMITTER: In the picture below we can see a modulated signal driving the IR LED of the transmitter on the left side. The detected signal is coming out of the receiver at the other side.

:
FIG.3.2 IR TRANSMITTER

The transmitter usually is a battery powered handset. It should consume as little power as possible, and the IR signal should also be as strong as possible to achieve an acceptable control distance. Preferably it should be shock proof as well. Many chips are designed to be used as IR transmitters. The older chips were dedicated to only one of the many protocols that were invented. Nowadays very low power microcontrollers are used in IR transmitters for the simple reason that they are more flexible in their use. When no button is pressed they are in a very low power sleep mode, in which hardly any current is consumed. The processor when wakes up to transmit the appropriate IR command only a key is pressed

FIG.3.3 TRANSISTOR CIRCUIT USED TO DRIVE IR LED

Quartz crystals are seldom used in such handsets. They are very fragile and tend to break easily when the handset is dropped. Ceramic resonators are much more suitable here, because they can withstand larger physical shocks. The fact that they are a little less accurate is not important. The current through the LED (or LEDs) can vary from 100mA to well over 1A! In order to get an acceptable control distance the LED currents have to be as high as possible. A trade-off should be made between LED parameters, battery lifetime and maximum control distance. LED currents can be that high because the pulses driving the LEDs are very short. Average power dissipation of the LED should not exceed the maximum value though. You should also see to it that the maximum peek current for the LED is not exceeded. All these parameters can be found in the LED's data sheet. A simple transistor circuit can be used to drive the LED. A transistor with a suitable hfe and switching speed should be selected for this purpose. The resistor values can simply be calculated using Ohm's law. Remember that the nominal voltage drop over an IR LED is approximately 1.1V. The normal driver, described above, has one disadvantage. As the battery voltage drops, the current through the LED will decrease as well. This will result in a shorter control distance that can be covered. An emitter follower circuit can avoid this. The 2 diodes in series will limit the pulses on the base of the transistor to 1.2V. The base-emitter voltage of the transistor subtracts 0.6V from that, resulting in constant amplitude of 0.6V at the emitter. This constant amplitude across a constant resistor results in current pulses of a constant magnitude. Calculating the current through the LED is simply applying ohm law. PHOTODIODES:
Unfortunately for us there are many more sources of Infrared light. The sun is the brightest source of all, but there are many others, like: light bulbs, candles, central heating system, and even our body radiates Infrared light. In fact everything that radiates heat, also radiates Infrared light. Therefore

we have to take some precautions to guarantee that our IR message gets across to the receiver with out errors.

Photodiodes are used for the detection of optical power (UV, Visible, and IR) and for the
conversion of optical power to electrical power. The photodiode spectral response can be measured

in X-ray, UV, visible, or IR. X-ray photodiodes are optimized for X-ray, gamma ray, and beta radiation detection.

UV enhanced photodiodes are optimized for the UV and blue spectral regions, Photodiodes are a twoelectrode, radiation-sensitive junction formed in a semiconductor material in which the reverse current varies with illumination. Photodiodes are used for the detection of optical power and for the conversion of optical power to electrical power. Photodiodes can be PN, PIN, or avalanche. PN photodiodes feature a two-electrode, radiation-sensitive PN junction formed in a semiconductor material in which the reverse current varies with illumination. PIN photodiodes are diodes with a large intrinsic region sandwiched between P-doped and N-doped semiconducting regions. Photons absorbed in this region create electron-hole pairs that are then separated by an electric field, thus generating an electric current in a load circuit

REGULATED POWER SUPPLY:

The power supplies are designed to convert high voltage AC mains electricity to a suitable low voltage supply for electronic circuits and other devices. A RPS (Regulated Power Supply) is the Power Supply with Rectification, Filtering and Regulation being done on the AC mains to get a Regulated power supply for Microcontroller and for the other devices being interfaced to it. A power supply can by broken down into a series of blocks, each of which performs a particular function. A d.c power supply which maintains the output voltage constant irrespective of a.c mains fluctuations or load variations is known as Regulated D.C Power Supply

For example a 5V regulated power supply system as shown below:

Transformer:
A transformer is an electrical device which is used to convert electrical power from one Electrical circuit to another without change in frequency.

Transformers convert AC electricity from one voltage to another with little loss of power. Transformers work only with AC and this is one of the reasons why mains electricity is AC. Step-up transformers increase in output voltage, step-down transformers decrease in output voltage. Most power supplies use a step-down transformer to reduce the dangerously high mains voltage to a safer low voltage. 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 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.

An Electrical Transformer Turns ratio = Vp/ VS = Np/NS Power Out= Power In VS X IS=VP X IP
Vp = primary (input) voltage Np = number of turns on primary coil Ip = primary (input) current

RECTIFIER:

A circuit which is used to convert ac to dc is known as RECTIFIER. The process of conversion ac to dc is called rectification

TYPES OF RECTIFIERS:

Half wave Rectifier Full wave Rectifier 1. Centre tap full wave rectifier. 2. Bridge type full bridge rectifier.

Comparison of rectifier circuits:

Type of Rectifier Parameter Half wave Full wave Bridge

Number of diodes

PIV of diodes

Vm

2Vm

Vm

D.C output voltage

Vm/z

2Vm/

2Vm/

Vdc at no-load

0.318Vm

0.636Vm

0.636Vm

Ripple factor

1.21

0.482

0.482

Ripple frequency

2f

2f

Rectification efficiency Transformer Utilization Factor(TUF)

0.406

0.812

0.812

0.287

0.693

0.812

RMS voltage Vrms

Vm/2

Vm/2

Vm/2

Full-wave Rectifier:
From the above comparison we came to know that full wave bridge rectifier as more advantages than the other two rectifiers. So, in our project we are using full wave bridge rectifier circuit.

Bridge Rectifier:
A bridge rectifier makes use of four diodes in a bridge arrangement to achieve fullwave rectification. This is a widely used configuration, both with individual diodes wired as shown and with single component bridges where the diode bridge is wired internally.
A bridge rectifier makes use of four diodes in a bridge arrangement as shown in fig (a) to achieve full-wave rectification. This is a widely used configuration, both with individual diodes wired as shown and with single component bridges where the diode bridge is wired internally.

Fig (A)

Operation: During positive half cycle of secondary, the diodes D2 and D3 are in forward biased while
D1 and D4 are in reverse biased as shown in the fig(b). The current flow direction is shown in the fig (b) with dotted arrows.

Fig (B)
During negative half cycle of secondary voltage, the diodes D1 and D4 are in forward biased while D2 and D3 are in reverse biased as shown in the fig(c). The current flow direction is shown in the fig (c) with dotted arrows.

Fig(C) Filter:
A Filter is a device which removes the ac component of rectifier output but allows the dc component to reach the load.

Capacitor Filter:
We have seen that the ripple content in the rectified output of half wave rectifier is 121% or that of full-wave or bridge rectifier or bridge rectifier is 48% such high percentages of ripples is not acceptable for most of the applications. Ripples can be removed by one of the following methods of filtering. (a) A capacitor, in parallel to the load, provides an easier by pass for the ripples voltage though it due to low impedance. At ripple frequency and leave the D.C. to appear at the load. (b) An inductor, in series with the load, prevents the passage of the ripple current (due to high impedance at ripple frequency) while allowing the dc (due to low resistance to dc). (c) Various combinations of capacitor and inductor, such as L-section filter section filter, multiple

section filter etc. which make use of both the properties mentioned in (a) and (b) above. Two cases of capacitor filter, one applied on half wave rectifier and another with full wave rectifier. Filtering is performed by a large value electrolytic capacitor connected across the DC supply to act as a reservoir, supplying current to the output when the varying DC voltage from the rectifier is falling. The capacitor charges quickly near the peak of the varying DC, and then discharges as it supplies current to the output. Filtering significantly increases the average DC voltage to almost the peak value (1.4 RMS value).

To calculate the value of capacitor(C), C = *3*f*r*Rl Where, f = supply frequency, r = ripple factor, Rl = load resistance Note: In our circuit we are using 1000F hence large value of capacitor is placed to reduce ripples and to improve the DC component.

Regulator:
Voltage regulator ICs is available with fixed (typically 5, 12 and 15V) or variable output voltages. The maximum current they can pass also rates them. Negative voltage regulators are available, mainly for use in dual supplies. Most regulators include some automatic protection from excessive current ('overload protection') and overheating ('thermal protection'). Many of the fixed voltage regulators ICs have 3 leads and look like power transistors, such as the 7805 +5V 1A regulator shown on the right. The LM7805 is simple to use. You simply connect the positive lead of your unregulated DC power supply (anything from 9VDC to 24VDC) to the Input pin, connect the negative lead to the Common pin and then when you turn on the power, you get a 5 volt supply from the output pin.

Fig 6.1.6 A Three Terminal Voltage Regulator

78XX:
The Bay Linear LM78XX is integrated linear positive regulator with three terminals. The LM78XX offer several fixed output voltages making them useful in wide range of applications. When used as a zener diode/resistor combination replacement, the LM78XX usually results in an effective output impedance improvement of two orders of magnitude, lower quiescent current. The LM78XX is available in the TO-252, TO-220 & TO-263packages,

Features:
Output Current of 1.5A Output Voltage Tolerance of 5%

Internal thermal overload protection Internal Short-Circuit Limited Output Voltage 5.0V, 6V, 8V, 9V, 10V, 12V, 15V, 18V, 24V.

CHAPTER 5

System Design
Designing of this system is possible when you select the specific controller to suite.For this we selected 89S52 controller.With the help of 89S52 controller traffic control system can be implemented successfully with the help IR technology.To the controller we connected IR transmitter and receiver circuit.Instead of IR transmitter and receiver we can go with photo diode and photo transmitters also.Here we are using four IR pairs for each side. Whenever vehicles reach the junction on each side, then IR detects the vehicle by sending signal to controller and the controller will counts the count of vehicles. And calculate the mximum count from them and give the path to side which has maximum count by glowing green LED and other three sides red LED shall be glow.

5.1 Hardware Design:


5.1.1 Schematic

J3 LCD VCC R6 CAP C7 U3 C4 2 6 P2 5 9 4 8 3 7 2 6 1 CONNECTOR DB9 J7 CON2 CAP 14 13 7 8 T1OUT R1IN T2OUT R2IN V+ VC2+ C2T1IN R1OUT T2IN R2OUT C1+ C11 3 4 5 11 12 10 9 CAP C5 VCC CAP C6 J3 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 J4 1 2 3 4 5 6 7 8 CON8 CAP Y1 CRYSTAL C2 19 CAP D1 DIODE D2 DIODE D4 DIODE D6 DIODE U5 +5V VIN GND 1 VOUT 2 C8 104 R5 R AT89S52 20 3 4 XTAL1 GND CON8 RXD TXD 10 11 12 13 14 15 16 17 18 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD XTAL2 P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 RST EA/VPP ALE/PROG PSEN P2.7/A15 P2.6/A14 P2.5/A13 P2.4/A12 P2.3/A11 P2.2/A10 P2.1/A9 P2.0/A8 31 30 29 J2 28 27 26 25 24 23 22 21 1 2 3 4 5 6 7 8 CON8 U1 VCC P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 40 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 J2 POT gnd vcc 3 RS W EN P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 VCC GND

TXD RXD

SW1

C1 C CON8 R4 R

MAX232

1 2

U6 t/f (4pin)

C9 = 1000UF/25V C

LM7805/TO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

VCC

C3

Title <Title> LED D5 Size A Date: Document Number <Doc> Thursday, July 15, 2010 Sheet 1 of 1 Rev <RevCode>

5.1.2. Schematic Description

The main aim of this power supply is to convert the 230V AC into 5V DC in order to give supply for the TTL. This schematic explanation includes the detailed pin connections of every device with the microcontroller. This schematic explanation includes the detailed pin connections of every device with the microcontroller. Let us see the pin connections of each and every device with the microcontroller in detail.

Power Supply:
In this process we are using a step down transformer, a bridge rectifier, a smoothing circuit and the RPS. At the primary of the transformer we are giving the 230V AC supply. The secondary is connected to the opposite terminals of the Bridge rectifier as the input. From other set of opposite terminals we are taking the output to the rectifier. The bridge rectifier converts the AC coming from the secondary of the transformer into pulsating DC. The output of this rectifier is further given to the smoother circuit which is capacitor in our project. The smoothing circuit eliminates the ripples from the pulsating DC and gives the pure DC to the RPS to get a constant output DC voltage. The RPS regulates the voltage as per our requirement.

Microcontroller:
The microcontroller AT89S52 with Pull up resistors at Port0 and crystal oscillator of 11.0592 MHz crystal in conjunction with couple of capacitors of is placed at 18th & 19th pins of 89S51 to make it work (execute) properly.

IR Module:
The IR transmitter and receiver are input and output devices. This is connected to the port P2 of the Microcontroller.

LCD:
The LCD data lines are connected to port 0 of the microcontroller in the schematic and the control signals like RS, EN are connected to pin2,3 of port 1.

LEDs :
Here the LEDs are connected to one of microcontroller port by using resistor.

5.2.SOFTWARE Components
5.2.1. ABOUT SOFTWARE Software used is:
*Keil software for C programming *Express PCB for lay out design *Express SCH for schematic design

KEIL Vision3
Vision3 is an IDE (Integrated Development Environment) that helps you write, compile, and debug embedded programs. It encapsulates the following components: A project manager. A make facility. Tool configuration. Editor. A powerful debugger.

This software is used for execution of microcontroller programs. Keil development tools for the MC architecture support every level of software developer from the professional applications engineer to the student just learning about embedded software development. The industry-standard keil C compilers, macro assemblers, debuggers,real, time Kernels, Single-board computers and emulators support all avr derive--atives and help you to get more projects completed on schedule. The keil software development tools are designed to solve the complex problems facing embedded software developers. When starting a new project, simply select the microcontroller you the device database

and the vision IDE sets all compiler, assembler, linker, and memory options for you. Numerous example programs are included to help you get started with the most

popular embedded avr devices.

The keil Vision debugger accurately simulates on-chip peripherals(PC, CAN, UART,

SPI,Interrupts,I/O ports, A/D converter, D/A converter and PWM modules)of your avr device. Simulation helps you understand h/w configurations and avoids time wasted on setup problems. Additionally, with simulation, you can write and test applications before target h/w is available. When you are ready to begin testing your s/w application with target h/w, use the

MON51, MON390, MONADI, or flash MON51 target monitors, the ISD51 In-System Debugger, or the ULINK USB-JTAG adapter to download and test program code on your target system.

Express PCB Express PCB is a Circuit Design Software and PCB manufacturing service. One can learn
almost everything you need to know about Express PCB from the help topics included with the programs given. Details: Express PCB, Version 5.6.0

Express SCH The Express SCH schematic design program is very easy to use. This software enables
the user to draw the Schematics with drag and drop options. A Quick Start Guide is provided by which the user can learn how to use it. Details: Express SCH, Version 5.6.0

EMBEDDED C: The programming Language used here in this project is an Embedded C Language. This Embedded C Language is different from the generic C language in few things like a) Data types b) Access over the architecture addresses. The Embedded C Programming Language forms the user friendly language with access over Port addresses, SFR Register addresses etc. Signed char: o o Used to represent the or + values. As a result, we have only 7 bits for the magnitude of the signed number, giving us values from 128 to +127.

Embedded C Data types:

Data Types unsigned char signed char unsigned int signed int sbit Bit sfr

Size in Bits 8-bit 8-bit 16-bit 16-bit 1-bit 1-bit 8-bit

Data Range/Usage 0-255 -128 to +127 0 to 65535 -32,768 to +32,767 SFR bit addressable only RAM bit addressable only RAM addresses 80-FFH only

CHAPTER 6

Implementation
The applications as discussed in the design are implemented and the source code related to the current work is pasted in the appendix.

SOFTWARE
Vision3
Vision3 is an IDE (Integrated Development Environment) that helps you write, compile, and debug embedded programs. It encapsulates the following components: A project manager. A make facility. Tool configuration. Editor. A powerful debugger.

To help you get started, several example programs (located in the \C51\Examples, \C251\Examples, \C166\Examples, and \ARM\...\Examples) are provided. HELLO is a simple program that prints the string "Hello World" using the Serial Interface.

Building an Application in Vision2:


To build (compile, assemble, and link) an application in Vision2, you must: 1. Select Project - (for example, 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.

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.

Debugging an Application in Vision2


To debug an application created using Vision2, you must: 1. Select Debug - Start/Stop Debug Session. 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. 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

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 database. 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

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.

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.

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 being done.

In addition to memory mapping, the simulator also provides support for the integrated peripherals of the various 8051 derivatives. The on-chip peripherals of the CPU you have selected are configured from the Device 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.

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.

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. 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

CHAPTER 7

System Testing
Density based traffic control system is a system which shall be able to count the vehicles at each side of the junction road when vehicles are reached near to that junction. After connecting the circuit and writing the code, then test it by sensing the IR sensor dated term used to describe an opto-electronic means of sensing something, most commonly a photodetector of some type.The system can be tested with the use of KEIL compiler.This one we are using to write programs for 8051 controller.After writing programs using 8051 programmer we can dump code in to the controller. Now develop the system by using IR transmitter and receiver, we can use photo diode and photo transistors.To test the board,First of all write a program in terms of like first enable LCD.To activate LCD send proper commands to it and after that configure baudrate,parity and number of bits for the serial port. After initializing all the devices connected to the controller, While testing keep the transmitter & receiver aligned in a straight position facing each other about a distance more than 2 meter but not less than that.If the transmitter and receiver are not in a aligned position data communication is not possible.Connect the output of IR receiver to the controller port pin.If there is no intruder the output pin will show low value.If there is any introduce it will show high value.In program monitor for high value and when you the value is high sens a message to a number indicating that intruder detected.

CHAPTER 8

Results and Evaluation


This chpater lists down the results realized from the practical work and examines whether ideas/ solution approaches recommended in research are met by the practical implementation. For this project the main communication is by using IR technology.

CHAPTER 9

Conclusion
The controller we used having the following featurtes like 8 bit 8051 architecture in a tiny 40 pin DIP package,128B RAM and 4kB on-chip Flash Program Memory. For low end applications this controller is very easy to use and at the same time IR also widely accepted protocol for mobile communication.By using IR technology and 8051 architecture based microcontroller we implemented electronic based traffic density control system.

References
[1] 8051 Architecture and Programming by Mazidi
[2] 8051

Programming by Ayala

[3] Wikipedia [4] IR theory

Source code:

S-ar putea să vă placă și