You are on page 1of 61

ABSTRACT

Smart energy saver system (SESS) is used in many applications for saving the energy in a smarter way like for light control in a room automatically micro controller also imparts smartness to the system. This project aims at design of SESS by AT89S52 micro controller and some additional components as in the block diagram finally to save the power. Here based

on the data in sensors the no. of lights in a room are glowed automatically without wasting much energy here 555 timer are used which may act as timer or counter based on its value the LEDS will glow at the output side. The main advantage of this microcontroller is it saves a large amount of power which is essential for human life as we have to save energy so that we need not many problems in future. face

CHAPTER 01 INTRODUCTION

Smart energy saver system (SESS) is used in many applications for saving the energy in a smarter way like for light control in a room automatically micro controller also imparts smartness to the system. Smart lighting light can be used to transmit broadband data ,which is already implemented in IRDA standards using infrared LEDS ,because LEDs can cycle on and off millions of times per seconds , they can be wireless transmitters and access points for data transport. Lasers can also be modulated in this manner. Many sensor systems rely on light as the signal source LEDs are often ideal as a light source due to the requirements of the sensors. Leds are used as movements sensors, for example in optical computer mouse. In pulse oxi meters for measuring oxygen saturation some flatbed scanners use arrays of RGB LEDs rather than the typical cold cathode fluorescent lamp as the light source having independent control of three illuminated colors allows the scanner to calibrate itself for more accurate color balance, and there is no need for warm up .further,its sensors only need be monochromatic ,since at any one time the page being scanned is only lit by one color of light. Touch sensing since LEds can also be used as photo diodes they can be used for both photo emission and detection. This could be used in for example a touch- sensing screen that register reflected light from a finger

1.1 Objective of this project


This project aims at design of SESS by AT89S52 micro controller and some additional components as in the block diagram finally to save the power. Here based on the data in sensors

the no .of lights in a room are glowed automatically without wasting much energy here 555 timer are used which may act as timer or counter based on its value the LEDS will glow at the output side. The main advantage of this microcontroller is it saves a large amount of power which is essential for human life as we have to save energy so that we need not future. This project is a device that collects data from the sensors, codes the data into a format that can be understood by the controlling section. This system also collects information from the master device and implements commands that are directed by the master. 2 face many problems in

The objective of the project is to develop a microcontroller based control and display system. It consists of sensors, microcontroller, the display unit, and the loads.

1.2 Background of the Project

Design of SESS by AT89S52 micro controller and some additional components as in the block diagram finally to save the power. Here based on the data in sensors the no .of lights in a

room are glowed automatically without wasting much energy here 555 timer are used which may act as timer or counter based on its value the LEDS will glow at the output side. The main advantage of this microcontroller is it saves a large amount of power have to save energy so that we need not face many? Which is essential for human life as we

Problems in future :
The Controlling unit has an application program to allow the microcontroller read the data from the sensor, micro controller forward the signal to latch which stores the signal for certain period and makes glow the LED bar. And finally display it on the LCD. The performance of the design is maintained by controlling unit.

Chapter- 02 Overview of the Technology

Embedded Systems
An embedded system can be defined as a computing device that does a specific focused job. Appliances such as the air-conditioner, VCD player, DVD player, printer, fax machine, mobile phone etc. are examples of embedded systems. Each of these appliances will have a processor and special hardware to meet the specific requirement of the application along with the embedded software that is executed by the processor for meeting that specific requirement. The embedded software is also called firm ware. The desktop/laptop computer is a general purpose computer. You can use it for a variety of applications such as playing games, word processing, accounting, software development and so on. In contrast, the software in the embedded systems is always fixed listed below:

Following are the advantages of Embedded Systems:

1. They are designed to do a specific task and have real time performance constraints which must be met. 2. They allow the system hardware to be simplified so costs are reduced. 3. They are usually in the form of small computerized parts in larger devices which serve a general purpose. 4. The program instructions for embedded systems run with limited computer hardware resources, little memory and small or even non-existent keyboard or screen.

Chapter 3 Hardware Implementation of the Project

This chapter briefly explains about the Hardware Implementation of the project. It discusses the design and working of the design with the help of block diagram and circuit diagram and explanation of circuit diagram in detail. It explains the features, timer programming, serial communication, interrupts of AT89S52 microcontroller. It also explains the various modules used in this project.

3.1 Project Design


The implementation of the project design can be divided in two parts. Hardware implementation Software implementation

Hardware implementation deals in drawing the schematic on the plane paper according to the application, testing the schematic design over the bread board using the various ICs to find if the design meets the objective, carrying out the PCB layout of the schematic tested on breadboard, finally preparing the board and testing the designed hardware. The software part deals in programming the microcontroller so that it can control the operation of the ICs used in the implementation. In the present work, we have used the Orcad design software for PCB circuit design, the Keil v3 software development tool to write and compile the source code, which has been written in the C language. The Pro load programmer has been used to write this compile code into the microcontroller. The software implementation is explained in the next chapter. The project design and principle are explained in this chapter using the block diagram and circuit diagram. The block diagram discusses about the required components of the design and working condition is explained using circuit diagram and system wiring diagram.

3.1.1 Block Diagram of the Project


The block diagram of the design is as shown in Fig 3.1. It consists of microcontroller sensors, timers, latches LED bar and LCD. The brief description of each unit is explained as follows.

3.2 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

Fig 2. Block diagram of power supply

Transformer
A transformer is a device that transfers electrical energy from one circuit to another

through inductively coupled conductors-the transformer's coils. A varying current in the first or primary winding creates a varying magnetic flux in the transformer's core and thus a varying magnetic field through the secondary winding. This varying magnetic field induces a varying electromotive force (EMF) or "voltage" in the secondary winding. This effect is called mutual induction. If a load is connected to the secondary, an electric current will flow in the secondary winding and electrical energy will be transferred from the primary circuit through the transformer to the load. In an ideal transformer, the induced voltage in the secondary winding (Vs) is in proportion to the primary voltage (Vp), and is given by the ratio of the number of turns in the secondary (Ns) to the number of turns in the primary (Np) as follows:

By appropriate selection of the ratio of turns, a transformer thus allows an alternating current (AC) voltage to be "stepped up" by making Ns greater than Np , or "stepped down" by making Ns less than Np. In the vast majority of transformers, the windings are coils wound around a ferromagnetic core, aircore transformers being a notable exception. Transformers range in size from a thumbnail-sized coupling transformer hidden inside a stage microphone to huge units weighing hundreds of tons used to interconnect portions of power grids. All operate with the same basic principles, although the range of designs is wide. While new technologies have eliminated the need for transformers in some electronic circuits, transformers are still found in nearly all electronic devices designed for household ("mains") voltage. Transformers are essential for high voltage power transmission, which makes long distance transmission economically practical.

Figure: 3.Transformer

Bridge Rectifier
A bridge rectifier makes use of four diodes in a bridge arrangement 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. 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 4. Bridge rectifier Three pin 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.

Figure :5. Three pin regulator-7805

3.3 Microcontrollers
Microprocessors and microcontrollers are widely used in embedded systems products. Microcontroller is a programmable device. A microcontroller has a CPU in addition to a fixed amount of RAM, ROM, I/O ports and a timer embedded all on a single chip. The fixed amount of onchip ROM, RAM and number of I/O ports in microcontrollers makes them ideal for many applications in which cost and space are critical. The Intel 8051 is Harvard architecture, single chip microcontroller (C) which was developed by Intel in 1980 for use in embedded systems. It was popular in the 1980s and early 1990s, but today it has largely been superseded by a vast range of enhanced devices with 8051-compatible processor cores that are manufactured by more than 20 independent manufacturers including Atmel, Infineon Technologies and Maxim Integrated Products. 8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. 8051 is available in different memory types such as UV-EPROM, Flash and NV-RAM.

3.3.1 Features of AT89S52


RAM is 256 bytes. 4.0V to 5.5V Operating Range. Fully Static Operation: 0 Hz to 33 MHzs 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.

Power-off flag. Fast programming time.

Description
The AT89s52 is a low-voltage, high-performance CMOS 8-bit microcomputer with 8K bytes of Flash programmable memory. The device is manufactured using Atmels high density nonvolatile memory technology and is compatible with the industry-standard MCS-51 instruction set. 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 Flash on a monolithic chip, the Atmel AT89s52 is a powerful microcomputer, which provides a highly flexible and cost-effective solution to many embedded control applications. 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 hardware reset.

PIN DIAGRAM

10

3.4 BLOCK DIAGRAM OF 8051

11

Pin description Vcc Pin 40 provides supply voltage to the chip. The voltage source is +5V.

GND Pin 20 is the 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.

12

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

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.

13

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.

14

XTAL2 Output from the inverting oscillator amplifier.

Fig 8. Oscillator Connections C1, C2 = 30 pF 10 pF for Crystals = 40 pF 10 pF for Ceramic Resonators

Fig 9.External Clock Drive Configuration

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier that can be configured for use as an on-chip oscillator. 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. 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

15

3.5. Liquid Crystal Display 3.5.1 Introduction to LCD:


In recent years the LCD is finding widespread use replacing LED s (seven-segment LED or other multi segment LED s). This is due to the following reasons: 1. The declining prices of LCD s. 2. The ability to display numbers, characters and graphics. This is in

contract to LED s, which are limited to numbers and a few characters. 3. Incorporation of a refreshing controller into the LCD, there by relieving the CPU of the task of refreshing the LCD. In the contrast, displaying the data. 4. Ease of programming for characters and graphics. the LED must be refreshed by the CPU to keep

FIG 10. LCD

USES
The LCD s used exclusively in watches, calculators and measuring instruments is the simple seven-segment displays, having a limited amount of numeric data. The recent advances in technology have resulted in better legibility, more information displaying capability and a wider temperature range. These have resulted in the LCD s being extensively used in telecommunications and entertainment electronics. The LCD s has even started replacing the cathode ray tubes (CRTs) used for the display of text and graphics, and also in small TV applications

16

Fig 11 (i) rear view

fig 11 (ii) side view

3.5.2. Specifications

Number of Characters: 16 characters x 2 Lines Character Table: English-European (RS in Datasheet) Module dimension: 80.0mm x 36.0mm x 13.2mm(MAX) View area: 66.0 x 16.0 mm Active area: 56.2 x 11.5 mm Dot size: 0.56 x 0.66 mm Dot pitch: 0.60 x 0.70 mm Character size: 2.96 x 5.46 mm Character pitch: 3.55 x 5.94 mm LCD type: STN, Positive, Transflective, Yellow/Green Duty: 1/16 View direction: Wide viewing angle Backlight Type: yellow/green LED Ro HS Compliant: lead free Operating Temperature: -20C to + 70

17

3.5.3. LCD PIN DIAGRAM

Fig 12. LCD pin diagram

Pins Functions: s 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 Pin 1 2 3 Symbol Vss Vcc VEE I/O ---Description Ground +5V power supply Power supply to

control contrast 4 RS I RS=0 to select

command register RS=1 to select data register 5 R/W I R/W=0 for write R/W=1 for read 6 7 E DB0 I/O I/O Enable The 8-bit data bus

18

8 9 10 11 12 13 14

DB1 DB2 DB3 DB4 DB5 DB6 DB7

I/O I/O I/O I/O I/O I/O I/O

The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus

TABLE 3: Pin description for LCD

Basic Commands of LCD 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:

Code (hex)

Command to LCD Instruction Register

Clear display screen

19

2 4 6 5 7 8 A C E F 10 14 18 1C 80 C0 38

Return home Decrement cursor Increment cursor Shift display right Shift display left Display off, cursor off Display off, cursor on Display on, cursor off Display on, cursor on Display on, cursor blinking Shift cursor position to left Shift cursor position to right Shift the entire display to the left Shift the entire display to the right Force cursor to beginning of 1st line Force cursor to beginning of 2nd line 2 lines and 5x7 matrix TABLE 4: LCD Command Codes

3.6 IR SENSORS
The solution proposed doesn't contain any special components, like photo-diodes, phototransistors, or IR receiver ICs, only a couple if IR leds, an Op amp, a transistor and a couple of resistors. In need, as the title says, a standard IR led is used for the purpose of detection. Due to that

20

fact, the circuit is extremely simple, and any novice electronics hobbyist can easily understand and build it. To detect the IR light that was emitted from another led of the exact same type! This is an electrical property of Light Emitting Diodes (LEDs) which is the fact that a led produces a voltage difference across its leads when it is subjected to light. As if it was a photo-cell, but with much lower output current. In other words the voltage generated by the leds can't be - in any way - used to generate electrical power from light, It can barely be detected. that's why as you will notice in the schematic,

3.7 555 TIMERS


The LM555 is a highly stable device for generating accurate time delays or oscillation. Additional terminals are provided for triggering or resetting if desired. In the time delay mode of Operation, the time is precisely controlled by one external resistor and capacitor. For astable operation as an oscillator the free running frequency and duty cycle are accurately controlled with two external resistors and one capacitor. The circuit may be triggered and reset on falling waveforms, and the output circuit can source or sink up to 200mA or drive TTL circuits.

Features

Direct replacement for SE555/NE555 Timing from microseconds through hours Operates in both astable and monostable modes 21

Adjustable duty cycle Output can source or sink 200 mA Output and supply TTL compatible Temperature stability better than 0.005% per C Normally on and normally off output Available in 8-pin MSOP package

Fig 15 555 timer IC

PIN DIAGRAMS

pin diagram

22

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 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). T he 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

Purpose

3.8 LIGHT EMITING DIODES


It is a semiconductor diode having radioactive recombination. It requires a definite amount of energy to generate an electron-hole pair. The same energy is released when an electron recombines with a hole. This released energy may result in the emission of photon and such a recombination. Hear the amount of energy released when the electro reverts from the conduction band to the valence band appears in the form of radiation. Alternatively the released energy may result in a series of phonons causing lattice vibration. Finally the released energy may be transferred to another electron. The recombination radiation may be lie in the infra-red and visible light spectrum. In forward is peaked around the band gap energy and the phenomenon is called injection luminescence. I n a junction biased in the avalanche break down region, there results a spectrum of photons carrying much higher energies. Almost White light then gets emitted from micro-plasma breakdown region in silicon junction. Diodes having radioactive recombination are termed as Light Emitting Diode, abbreviated as LEDs.

Fig 16 . Leds

23

3.8.1 Function
LEDs emit light when an electric current passes through them.

3.8.2 Connecting and soldering


LEDs must be connected the correct way round, the diagram may be labeled a or + for anode and k or - for cathode (yes, it really is k, not c, for cathode!). The cathode is the short lead and there may be a slight flat on the body of round LEDs. If you can see inside the LED the cathode is the larger electrode (but this is not an official identification method).

LEDs can be damaged by heat when soldering, but the risk is small unless you are very slow. No special precautions are needed for soldering most LEDs.

3.9 LATCH (74LS373)


The 74LS373 consists of eight latches with 3-state outputs for bus organized system applications. The flip- flop appears transparent to the data (data changes asynchronously) when Latch enable (LE) is HIGH. When LE is LOW, the data that meets the setup times in latched. Data appears on the bus .when the Output Enable (OE) is LOW. When OE is HIGH the bus output is in The high impedance state.

The 74LS374 is a high-speed, low-power Octal D-type Flip-Flop featuring separate D-type inputs for each flip-flop and 3-state outputs for bus oriented applications. A buffered Clock (CP) and Output Enable (OE) is common to all flip-flops. The SN54 /74LS374 is manufactured using advanced Low Power Schottky technology and is compatible with all Motorola TTL families

Features Eight Latches in a Single Package


3-State Outputs for Bus Interfacing Hysteresis on Latch Enable Edge-Triggered D-Type Inputs

Buffered Positive Edge-Triggered Clock


24

Hysteresis on Clock Input to Improve Noise Margin Input Clamp Diodes Limit High Speed Termination Effects

PIN NAMES
D0D7LE CP OE O0O7 data inputs Latch Enable (Active HIGH) Input Clock (Active HIGH going edge) Input Output Enable (Active LOW) Input Outputs

PINDIAGRAM

74LS373 latch

Fig 18 latch IC

25

TRUTH TABLE

D-N H L X X

LE H H L X
Table no 07

OE

O-N H L Q0 Z*

L L L H

H = HIGH Voltage Level L = LOW Voltage Level

X= Immaterial Z= high impedance

Note: Contents of flip-flops unaffected by the state of the Output Enable input (OE)

3.10 LED BARS

Description :
These 10 segment bar graph LEDs have many uses. With a compact footprint, simple hookup, they are easy for prototyping or finished products. Essentially, they are 10 individual red LEDs housed together, each with an individual anode and cathode connection

Fig 19.led bars

26

Chapter 4 Software Implementation of the project design

This chapter briefly explains about the software implementation of the project. The required software tools are discussed in section 4.2 Section 4.3 shows the flow diagram of the project design. Section 4.4 presents the software implementation of the project design.

4.1 Software Tools Required


Keil v3, Proload are the two software tools used to program microcontroller. The working of each software tool is explained below in detail.

4.1.1 Programming Microcontroller

A compiler for a high level language helps to reduce production time. To program the AT89S52 microcontroller the Keil v3 is used. The programming is done strictly in the embedded C language. Keil v3 is a suite of executable, open source software development tools for the microcontrollers hosted on the Windows platform. The compilation of the C program converts it into machine language file (.hex). This is the only language the microcontroller will understand, because it contains the original program code converted into a hexadecimal format. During this step there are some warnings about eventual errors in the program. This is shown in Fig 4.1. If there are no errors and warnings then run the program, the system performs all the required tasks and behaves as expected the software developed. If not, the whole procedure will have to be repeated again. Fig 4.2 shows expected outputs for given inputs when run compiled program.

27

SOURCE CODE

1. 2.

Click on the Keil vision Icon on Desktop The following fig will appear

3. 4. 5. 6. 7. 8.

Click on the Project menu from the title bar Then Click on New Project Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\ Then Click on save button above. Select the component for u r project. i.e. Atmel Click on the + Symbol beside of Atmel

9.

Select AT89S52 as shown below]

28

10. 11. 12. 13. 14. 15. 16.

Then Click on OK The Following fig will appear 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. Click on the file option from menu bar and select new 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 C or ASM For a program written in Assembly, then save it with extension . asm and for C based program save it with extension .C

19. 20.

Now right click on Source group 1 and click on Add files to Group Source Now you will get another window, on which by default C files will appear.

21. 22. 23. 24. 25.

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. If the file contains no error, then press Control+F5 simultaneously. The new window is as follows

26.

Then Click OK 29

27. 28.

Now Click on the Peripherals from menu bar, and check your required port as shown in fig below Drag the port a side and click in the program file.

29. 30.

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

30

Chapter - 05 Project code


SMART VISITING COUNTER FOR AUDITORIUM USING AT89S52 ; $mod52 Nhsec equ 0037H; define for delay BIDIRECTIONAL VISITOR COUNTER

count1equ 0020H; visitors in counter count2 equ result equ data1 equ asc_valequ digit0 equ digit1 equ digit2 equ limit1 equ limit2 equ limit3 equ enter1 bit exit1 bit flash bit 0024H ; 0026H ; 0028H ; visitors_out counter remaining visitors dummy variable

0030H ; 0031H ; 0032H ; 0033H ; 0034H 0035H 0036H p1.1 p1.2 p1.0 bit ; ; ; p2.7

for conversion hundreds tens units

enter door - 1 exit door - 1 Flash LED ; Latch_enable

latch_en

31

;********** Defining LCD Controls ********** ;p2.0 is used as select either instruction or data RS ;p2.1 is used as read/write select RW ;p2.2 is used as lcd enable EN ;p1.0 is used for diagnostic LED lcd_rs lcd_rw lcd_en bit bit bit p2.0 p2.1 p2.2 ; ; ; lcd RS lcd RW lcd EN

MAIN PROGRAMME START org sjmp 0000h start

;********************************************** ; APPLICATION STARTS

;********************************************** start: mov clr mov mov mov clr clr SP,#70H flash asc_val,#30h count1,#00h count2,#00h enter1 exit1 ; ; ; ; for visitors in for visitors out for enter door for exit door ; ; Move 70h in stack pointer LED ON

32

setb mov mov mov mov mov mov mov mov mov mov mov lcall lcall lcall lcall lcall

latch_en a,#0ffh p0,a data1,#00h result,#00h digit0,#00h digit1,#00h digit2,#00h p1,#0ffh limit1,#00H limit2,#1eH limit3,#0fh display_test delay delay bcd_asc in_display ; loops here ; ; ; hall empty limit is '0' 30 seats available ; 16 seats ; dummy variable for result

LCD test

;********************************************** contnu: clr lcall lcall lcall p1.0 ; LED ON for visitors counting

visitor_count ; deviation data_compare

33

lcall setb lcall clr sjmp

delay p1.0 delay c contnu

; ; ;

1 Sec delay LED OFF 1 Sec delay

loops here

; ; data_compare: mov cjne mov setb nop nop nop clr mov mov lcall

END OF APPLICATION SUB-ROUTINES STARTS HERE

a,limit1 a,result,nxt1 p0,#0feh latch_en

latch_en count1,#00h data1,count1 hex_bcd ; calculating digit - 0,1,2

lcall lcall

bcd_asc line1_in_display

; ;

preparing for LCD display display for visitors in room

34

mov mov hex_bcd lcall lcall lcall ret nxt1: mov cjne mov setb nop nop nop clr lcall ret nxt2:

count2,#00h data1,count2lcall ; bcd_asc line1_out_display empty_display calculating digit - 0,1,2 ; ; preparing for LCD display display for visitors out

a,limit2 a,result,nxt2 p0,#00h latch_en

latch_en full_display

clr mov subb a,limit3 a,result

35

jc clr mov subb jc mov setb nop nop nop clr mov subb mov lcall lcall lcall ret nxt3: mov setb nop nop

nxt3 c a,limit1 a,result nxt4 p0,#0feh latch_en

latch_en a,limit2 a,result data1,a hex_bcd bcd_asc avail_display

p0,#80h latch_en

36

nop clr mov subb mov lcall lcall lcall ret nxt4: mov setb nop nop nop clr mov subb mov lcall lcall lcall ret
37

latch_en a,limit2 a,result data1,a hex_bcd bcd_asc avail_display

p0,#0f8h latch_en

latch_en a,limit2 a,result data1,a hex_bcd bcd_asc avail_display

deviation: mov subb mov mov ret

a,count 1 a,count2 result,a data1,a

;*****************VISITORS COUNTING******************* visitor_count: mov mov jnb jnb ret visitor_in: mov cjne ret next1: inc mov lcall calculating digit - 0,1,2lcall display lcall line1_in_display
38

data1,#00h result,#00h enter1,visitor_in exit1,visitor_out

a,limit2 a,count1,next1

count1 data1,count1 hex_bcd bcd_asc ; preparing for LCD

display for visitors in

ret visitor_out: mov cjne ret next2: inc mov lcall lcall lcall ret count2 data1,count2 hex_bcd bcd_asc line1_out_display ; ; ; calculating digit - 0,1,2 preparing for LCD display display for visitors out a,count1 a,count2,next2

*****************VISITOR IN DISPLAY************************ line1_in_display: MOV ACALL MOV ACALL MOV ACALL MOV a,#0C4H command a,digit0 display a,digit1 display a,digit2

ACALL

display
39

RET **************VISITOR OUT DISPLAY**************** line1_out_display: MOV ACALL MOV ACALL MOV ACALL MOV ACALL RET a,#0CDH command a,digit0 display a,digit1 display a,digit2 display

***********LINE1 DISPLAY********* in_display: LCALL MOV ACALL MOV ACALL MOV ACALL MOV a,#' '
40

display_init a,#0c0h ; address of second

command a,#'I' display a,#'N' display

ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV a,#' ' a,#'T' a,#'U' a,#'O' a,#' ' a,#'='

display

display a,digit0 display a,digit1 display a,digit2 display

display

display

display

display

ACALL MOV ACALL

display a,#'=' display

MOV

a,digit0
41

ACALL

display

MOV ACALL

a,digit1 display

MOV ACALL

a,digit2 display

RET

empty_display: MOV a,#80h ; ACALL address of second line command

MOV ACALL

a,#' ' display

MOV ACALL

a,#'H' display

MOV ACALL

a,#'A' display

42

MOV ACALL

a,#'L' display

MOV ACALL

a,#'L' display

MOV ACALL

a,#' ' display

MOV ACALL

a,#'I' display

MOV ACALL

a,#'S' display

MOV ACALL

a,#' ' display

MOV ACALL

a,#'E' display

MOV ACALL

a,#'M' display
43

MOV ACALL

a,#'P' display

MOV ACALL

a,#'T' display

MOV ACALL

a,#'Y' display

MOV ACALL

a,#' ' display

MOV ACALL

a,#' ' display

RET

full_display: MOV a,#80h ; ACALL MOV a,#' ' address of second line command

44

ACALL MOV a,#' ' ACALL MOV a,#'H' ACALL MOV a,#'A' ACALL MOV a,#'L' ACALL MOV a,#'L' ACALL MOV a,#' ' ACALL MOV a,#'I' ACALL MOV a,#'S' ACALL MOV a,#' ' ACALL MOV a,#'F' ACALL MOV a,#'U'

display

display

display

display

display

display

display

display

display

display

display

45

ACALL MOV a,#'L'

display

ACALL MOV a,#'L' ACALL MOV a,#' ' ACALL MOV a,#' ' ACALL RET avail_display: MOV a,#80h ; ACALL MOV a,#'A' ACALL MOV a,#'V' ACALL MOV a,#'L' ACALL MOV a,#'B' ACALL MOV a,#'L' ACALL

display

display

display

display

address of second line command

display

display

display

display

display
46

MOV

a,#'E' ACALL display

MOV

a,#' ' ACALL display

MOV

a,#'S' ACALL display

MOV

a,#'E' ACALL display

MOV

a,#'A' ACALL display

MOV

a,#'T' ACALL display

MOV

a,#'S' ACALL display

MOV

a,#' ' ACALL display

MOV

a,digit0 ACALL display

MOV

a,digit1 ACALL display


47

MOV ACALL RET hex_bcd: MOV

a,digit2 display

a,data1 MOV DIV MOV MOV MOV DIV MOV MOV RET b,#100 ; ab digit0,a a,b b,#10 ab digit1,a digit2,b Move 100 to b register ; ; ; ; ; ; ; Didide Acc by b Move Acc to digit1_dat Move b to Acc Move 10 to b register Divide Acc by b Move Acc to digit2_dat Move b to digit3_dat

bcd to asc conversion bcd_asc:

48

MOV ADD MOV MOV

a,digit0 a,#asc_val digit0,a a,digit1 ADD MOV a,#asc_val digit1,a ; tens ; hundreds

MOV

a,digit2 ADD MOV a,#asc_val digit2,a ; units

RET

;********************************************** ; Title Display for 3 Seconds

;**********************************************

display_test:

LCALL

display_init

49

MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL

a,#' ' display a,#'S' display a,#'M' display a,#'A' display a,#'R' display a,#'T' display a,#' ' display a,#'V' display a,#'I' display a,#'S' display a,#'I' display
50

MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL

a,#'T' display a,#'O' display a,#'R' display a,#' ' display a,#' ' display

MOV ACALL

a,#0c0h

address of second line

command

MOV ACALL MOV ACALL MOV ACALL MOV ACALL

a,#'C' display a,#'O' display a,#'U' display a,#'N' display


51

MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV

a,#'T' display a,#'R' display a,#' ' display a,#'U' display a,#'S' display a,#'N' display a,#'G' display a,#' ' display a,#'8' display a,#'9' display a,#'5' display a,#'2'
52

ACALL

display

LCALL

delay

RET

;************************************************************* ; lcd initialisation

;*************************************************************

display_init:

CLR MOV ACALL MOV ACALL MOV ACALL MOV ACALL MOV ACALL

a a,#3ch ; 8 bits/char, 2 rows,5*10 dots/char

command a,#0eh ; screen and cursor on,no blink

command a,#06h ; shift cursor right

command a,#01h ; clear memory and home cursor

command a,#80h ; move cursor to start of first line

command
53

RET

;************************************************************* ; command sub-routine

;************************************************************* ;p0 is used as data port for LCD ;p2.0 is used as select either instruction or data RS ;p2.1 is used as read/write select RW ;p2.2 is used as lcd enable EN ;p0.7 is used as busy flag

command:

ACALL CLR CLR

ready lcd_en ; lcd_rs ; Disable display Command register chosen

MOV

p0,a

move data

CLR SETB CLR

lcd_rw ; lcd_en ; lcd_en ;

LCD write enabled Enable display Disble display


54

RET

;************************************************************* ; display sub-routine sending data to port p2

;*************************************************************

ready:

wait:

CLR CLR SETB

lcd_en lcd_rs lcd_rw

; ; ;

Disble display RS RW

MOV

p0,#0ffh

SETB JB CLR CLR

lcd_en p0.7,wait lcd_en lcd_rw

Enable display

; ;

Disble display RW

RET
55

;************************************************************* ; display sub-routine sending data to port p0

;*************************************************************

display:

ACALL SETB MOV SETB CLR

ready ; lcd_rs ; p0,a ; set Rs

calling ready sub routine

mov accumulator content to p0 Enable display Disble display

lcd_en ; lcd_en ;

RET

;********************************************** ; delay at 11.059Mhz

;**********************************************

delay:

PUSH PUSH

acc psw
56

MOV

nhsec,#05h

@12Mhz

relo:

DEC MOV

nhsec b,#41h

again5:

DEC MOV

b a,#0ffh

again6:

DEC JNZ MOV JNZ MOV JZ LJMP clint1 again5 again6

a,b

a,nhsec

relo

clint1:
57

POP POP

psw acc

RET

END OF PROJECT PROGRAMME ;**********************************************

58

Chapter 6 Results and Discussions

Working procedure
The smart energy saver system works as follows we get the power supply from the 5 volts power supply circuit connected externally which is given as input to the micro controller port 1.0 and the standard micro controller is built as per its connections its diagram is been shown. I.e. the crystal oscillator connections n reset signal connections n the ground connections. Here we use two sensors which will sense the presence of persons entering and leaving the room i.e. one sensor is kept at the entrance one at the exit n these sensors will count the number of people entering and leaving the hall the output of the sensors is given to the port 1.1 (entrance) and the output of other sensor is given to port1.2 (exit). The sensors will add and subtract the number of persons entering n leaving the hall n gives the input to the micro controller. the port 0 of the micro controller is given to the LCD data pins where the display comes about the strength of persons in room The same port 0 is also given as the data input to the 74ls373 d latch and the outputs of the latch is given to the 8 segment led bar and the overall thing is controlled by the micro controller. Based on the number of persons entering n leaving the room that much sufficient light will glow without wasting much energy. This is the overall aim of the project. Suppose if the room is empty a single led will be glowing If the number of persons present in room is between 2 to 15 next 4 LEDS will glow. If the number of persons exceed 15 i.e. 16 and above then all the LEDS will glow.

Benefits of office lighting by LED light bulbs

1. Long-lasting - LED bulbs last up to 10 times more than any other bulb.
2. Durable LED bulbs are solid they are not made from filament. Thats why they are not damaged under circumstances when a regular incandescent bulb would be broken.

59

3. Cool LED bulbs do not cause heat build-up and cuts down on air conditioning costs in the home. 4. More efficient - LED light bulbs use only 2-10 watts of electricity which is upto 1/30th of Incandescent or CFL bulbs. Replacing with LED bulbs will be reduced electricity costs by 80% or more. 5. Innovative Lighting Redesign ESI brings you innovative lighting redesign and LED Retrofit program to match IESNA specifications. 6. ZERO out of pocket expense - We are paid through savings on your electric bill. 7. Positive Cash Flow - Realize cash back from day one after the retrofit is complete. 8. Protection Plan - 5 year all-inclusive protection plan. We mean everything. 9. Energy Efficient Lighting Make your building energy efficient with eco friendly lighting.

Results
Assemble the schematic circuit on the general purpose board after assembling the circuit on the general purpose board; check it for proper connections before switching on the power supply.

Conclusion
The main advantage of this microcontroller is it saves a large amount of power which is essential for human life as we have to save energy so that we need not future. face many problems in

60

REFERENCES:

1. Muhammad Ali Mazidi,, The 8051 Microcontroller and Embedded systems, 2nd Edition. 2. Micro processors and interfacing Technical publications 3. www.8051.com 4. en.wikipedia.org/wiki/Infrared sensors 5. en.wikipedia.org/wiki/Light-emitting diode 6. en.wikipedia.org/wiki/Liquid_crystal_display 7. www.datasheetarchive.com/555-datasheet.html
8 www.alldatasheet.com/datasheet-pdf/pdf/.../74LS373 9. www.alldaatsheets.com

61

You might also like