You are on page 1of 127

1.

INTRODUCTION

In its most simple form Home Automation is the ability to control lighting & household appliances remotely. Almost everyone already has a limited amount of Home Automation. Home Automation is analogous to earlier developments in factory and office automation. It includes the remote control and monitoring of domestic appliances, home security and energy management. Home automation systems are a result of an attempt to enhance the standards of living around and inside the house and were made possible by the breakthrough in the area of integrated circuits and microcontrollers. These systems provide the consumers with increased security and safety, economic benefit through energy control, and convenience by giving them control over every piece of domestic electrical equipment in the house.

1111

Designing a home automation system for monitoring and controlling various devices in remote locations can be done through a variety of communications options such as wireless LAN technologies, dial-up modems, private radio networks, satellite communication, internet, cellular network and so on. Different studies on home automation work on different types of these controlling methods. Since the first step of the home automation is real-time monitoring of the status changes of the devices that we control in the house, the system that we design should have the capability of warning the users no matter where they are right at the time at which the changes occur. Thus, our main objective for using Infrared network for the communication between the home and the users and vice versa. Other advantages of using IR systems in home automation is because of its security and its features and moreover its characteristics.

2222

Intelligent buildings can provide safety, convenience and welfare for society in the 21st century, and allow effective management of resource with minimum lifetime costs at the same time. An intelligent building system (IBS) is the integration of various services and contains security system, building heating, ventilating and air-conditioning (HVAC) technologies, computer system , telecommunication and Internet. The most important components are building security in an intelligent building. In the security system, redundant and complementally information results can enhance system reliability and certainty of intelligent building using multi sensor fusion method. In generally, the home automation is a part of the intelligent building. The most important of the home automation is the security system. The appliance control is not negligent. The structure of features of a modern BAS was introduced and future trends of BAS are discussed. Azegami and Fujiyoshi described a systematic approach to intelligent building design. Kujuro and Yasuda discussed the systems evolution in intelligent building. The quality of building services can be enhanced by updated information processing and communications functions of building
3333 3

automation systems. Finley et al. presented a survey of intelligent building and reviews issues such as system perspective, subsystem services, and multi-tenant building. Flax discussed components and cost benefits of the intelligent building. Chung and Fu expect to set up the standard of appliances and communication protocols, and propose complete system architecture with integrate control kernel to construct an intelligent building system. In this project the appliances that we are going to control are connected to the Microcontroller circuit.When the command is given from the pc ,8051 microcontroller receives the command from TSOP. The received data is processed by the controller circuit to the relay circuit to control the particular appliance.

2. OVERVIEW

4444

2.1 BLOCK DIAGRAM

5555

2.2 DESCRIPTION IR based home automation block diagram consist of different blocks . They are, Microcontroller, Current driver IC, TSOP, IR Remote, LCD display Relays.

2.2.1 MICROCONTROLLER AT89C51 Microcontroller is used for our application .The appliance to be controlled is interfaced to one of the ports of the microcontroller and an ALP is programmed in to it. In the later sections this book mainly focuses on different issues such as how data is being transmitted and received
6

6666

, which type of modulation process is used by the RF modem, features of modem , description of Microcontroller , Assembly program and its Advantages and disadvantages. 2.2.2 LCD DISPLAY It is LED (light emitting diode) crystal display. LCD display is connected to 8051 microcontroller. When we give commands from computer, microcontroller receives that command and checks with the internal command. If the command is present then it displays on the LCD display.

2.2.3 CURRENT DRIVER IC The microcontroller cannot provide the required supply to relays. So, we use the IC(ULN2003) which is the current driver IC. This IC provides required supply to relays.
7

7777

2.2.4 TSOP It is the receiver for infrared remote control systems. The demodulated output signal can directly be decoded by a microprocessor 2.2.5 IR REMOTE

In our project we are using an RC5 standard IR remote control as t By the IR receiver for producing the IR signal communication. 2.2.6 RELAY It is an electrically operated switch used to control the devices. It sees that no two voltages mix up.

transmitter to emit out the necessary IR signals that are to be receiv

required f

8888

3. EMBEDDED SYSTEMS 3.1 INTRODUCTION In this chapter we deal with the embedded systems. Various aspects like Embedded system constituents, life cycle, working etc are covered. We shall also learn about other topics like development tools, system types, their classification and characteristics, features and applications, advantages and disadvantages etc. 3.2 WHAT IS A SYSTEM? A system is something that maintains its existence and functions as a whole through the interaction of its parts. E.g. Body, Mankind, Access Control, etc A system is a part of the world that a person or group of persons during some time interval and for some
9999 9

purpose choose to regard as a whole, consisting of interrelated components, each component characterized by properties that are selected as being relevant to the purpose.

Fig 2.1: System constituents 3.3 EMBEDDED SYSTEM DEFINITION

We can define an embedded system as a computing device, built in to a device that is not a computer, and meant for doing specific computing tasks.

10101010

10

An embedded system is a special-purpose computer system usually built into a smaller device. An embedded system is required to meet very different requirements than a general-purpose personal computer. Some Features of Embedded System are, Embedded System is a combination of hardware and software used to achieve a single specific task. Embedded systems are computer systems that monitor, respond to, or control an external environment. Environment connected to systems through sensors, actuators and other I/O interfaces. Embedded system must meet timing & other constraints imposed on it by environment.

11111111

11

2.4 LIFE CYCLE 2.4.1 REQUIRMENTS Finalize the functional requirement of the system that has to be implemented 2.4.2 ANALYSIS Analyze the requirements and finalize the system requirements . DESIGN Based on the requirements design the system. Hardware Orcad Eagle

Software
12

12121212

Flowchart IMPLEMENTATION Based on the hardware design make the layout of the PCB and design the routing Get the PCB fabricated Mount the components on to the PCB PROGRAMMING Use the designated tools for programming the microcontroller or processor whichever is selected

Atmel

Keil C- compiler uc Flash programmer

Microchip

Mplab IDE

ICD2 ARM ARM - GCC, ADS

Jtag / Flash programmer


13

13131313

TESTING/DEBUGGING Hardware debugging Software debugging Functionality test PACKAGING/IMPLEMENTATION Mount the module into the designed enclosure Install the designed system in the required application area

14141414

14

Fig 2.2: Life cycle of embedded system

15151515

15

2.5 Embedded system tools: Assembler: An assembler is a computer program for translating assembly language essentially, a mnemonic representation of machine language into object code. A cross assembler (see cross compiler) produces code for one type of processor, but runs on another. The computational step where an assembler is run is known as assembly time. Translating assembly instruction mnemonics into opcodes, assemblers provide the ability to use symbolic names for memory locations (saving tedious calculations and manually updating addresses when a program is slightly modified), and macro facilities for performing textual substitution typically used to encode common short sequences of instructions to run inline instead of in a subroutine. Assemblers are far simpler to write than compilers for high-level languages. 2.6 Embedded Systems Types and Classification:
16

16161616

High-end embedded & Lower end embedded systems: High-end embedded system - Generally 32, 64 Bit Controllers used with OS. Examples Personal Digital Assistant and Mobile

phones etc . Lower end embedded systems: Generally 8, 16 Bit Controllers used with a minimal operating systems and hardware layout designed for the specific purpose. Examples Small controllers and devices in our every day life like Washing Machine, Microwave Owens, where they are embedded in. Classification Real Time Systems RTS classification RTS is one which has to respond to events within a specified deadline A right answer after the dead line is a wrong answer Hard Real Time Systems Soft Real Time System
17

17171717

"Hard" real-time systems have very narrow response time Example: Nuclear power system, Cardiac pacemaker. "Soft" real-time systems have reduced constrains on "lateness" but still must operate very quickly and repeatable. Example: Railway reservation system takes a few extra seconds the data remains valid. 2.7 CHARACTERISTICS: Designs are cost-sensitive Have real-time performance constraints

Used with Real-Time Operating Systems (RTOS)

Software failure can be life-threatening May have constraints on power consumption Operate conditions Fewer system resources then a desktop system All code might be stored in ROM Require specialized design tools
18181818 18

over

wide-range

of

environmental

2.8 FEATURES: Response Security Availability Cost Size/Weight Survivability Maintainability Throughput

19191919

19

MICROCONTROLLER 3.1) FEATURES: Compatible with MCS-51 Products 4K Bytes of In-System Reprogrammable Flash Memory Endurance: 1,000 Write/Erase Cycles Fully Static Operation: 0 Hz to 24 MHz Three-level Program Memory Lock 128 x 8-bit Internal RAM 32 Programmable I/O Lines Two 16-bit Timer/Counters Six Interrupt Sources Programmable Serial Channel Low-power Idle and Power-down Modes Description: The AT89C51 is a low-power, highperformance CMOS 8-bit microcomputer with 4K bytes of Flash programmable and erasable read only memory
20202020 20

(PEROM). The device is manufactured using Atmels highdensity nonvolatile memory technology and is compatible with the industry-standard MCS-51 instruction set and pinout. 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 Flash on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer which provides a highly-flexible and cost-effective solution to many embedded control applications.

PIN CONFIGURATIONS:

21212121

21

22222222

22

23232323

23

3.3) Pin Description VCC -Supply voltage. GND- Ground. Port 0 Port 0 is an 8-bit open-drain bi-directional 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 may 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 pull ups Flash are programming, and outputs the code bytes during program verification. External required during program verification.
24242424 24

Port 1 Port 1 is an 8-bit bi-directional 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 pullups 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. Port 1 also receives the low-order address bytes during Flash programming and verification. Port 2 Port 2 is an 8-bit bi-directional I/O port with internal pullups. 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
25252525 25

pullups 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 pullups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that use 16-bit addresses (MOVX @DPTR). In this application, it uses strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.Port 2 also receives the highorder address bits and some control signals during Flash programming and verification. Port 3 Port 3 is an 8-bit bi-directional I/O port with internal pullups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written
26262626 26

to Port 3 pins they are pulled high by the internal pullups and can be used as inputs. As inputs Port 3 pins that are externally being pulled low will source current (IIL) because of the pullups. Port 3 also serves the functions of various special features of the AT89C51 as listed below:

Port 3 also receives some control signals for Flash programming and verification.

27272727

27

RST Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. ALE/PROG Address Latch Enable 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
28282828 28

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 is the read strobe to external program memory. When the AT89C51 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
29292929 29

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, for parts that require 12-volt VPP. XTAL1 Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2 Output from the inverting oscillator Amplifier.

Oscillator Characteristics:

30303030

30

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in Figure 1. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure 2.There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed. 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
31313131

RAM

and

all
31

the

special

functions

registers remain unchanged during this mode. The idle mode can be terminated by any enabled interrupt or by a hardware reset. It should be noted that when idle is terminated by a hard ware 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 is terminated by reset, the instruction following the one that invokes Idle should not be one that writes to a port pin or to external memory.

32323232

32

Note: C1, C2 = 30 pF 10 pF for Crystals = 40 pF 10 pF for Ceramic resonators. Memory Organization

4.1) Program Memory: The TEMIC C51 Microcontroller Family has separate address spaces for program Memory and Data Memory. The program memory can be up to 64 K bytes long. The lower 4 K for the 89C51 (8 K for the 80C52, 16 K for the 83 C154 and 32 K for the 83C154D) may reside on chip. Figure 1 to 4 show a map of 80C51, 80C52,
33

33333333

83C154 and 83C154D program memory.

Figure1. The 89C51 Program Memory.

4.2) Data Memory: The C51 Microcontroller Family can address up to 64 K bytes of Data Memory to the chip. The MOVX instruction is used to access the external data memory (refer to the C51 instruction set, in
34343434 34

this

chapter,

for

detailed

description

of

instructions). The 89C51 has 128 bytes of on-chip-RAM (256 bytes in the 89C52, 83C154 and 83C154D) plus a number of Special Function Registers (SFR). The lower 128 bytes of RAM can be accessed either by direct addressing (MOVdata addr). or by indirect addressing (MOV @Ri). Figure5 and 6 show the 89C51, 89C52, 83C154 and 83C154D Data Memory organization. Figure5. The 89C51 Data Memory

Organisation.

35353535

35

Note that in Figure 6 - the SFRs and the indirect address RAM have the same addresses (80HOFFH).Nevertheless, they are two separate areas
36363636 36

and are accessed in two different ways. For example the instruction MOV 80H, #0AAH writes 0AAH to Port 0 which is one of the SFRs and the instruction MOV R0, # 80H MOV @ R0, # 0BBH writes 0BBH in location 80H of the data RAM. Thus,after execution of both of the above instructions Port 0 will contain 0AAH and location 80 of the the RAM will contain are 0BBH.Note that stack operations

examples of indirect addressing, so the upper 128 bytes of data RAM are available as stack space in those devices which implement 256 bytes of internal RAM.

Direct and Indirect Address Area: The 128 bytes of RAM which can be accessed by both direct and indirect
37373737 37

addressing can be divided into 3segments as listed below and shown in figure. 1.Register Banks 0-3: Locations 0 through 1FH (32bytes). ASM-51 and the device after reset default to register bank 0. To use the other register banks the user must select them in the software. Each register bank contains 8 one-byte registers, 0 through 7.Reset initializes the Stack Pointer to location 07H and it is incremented once to start from location 08H which is the first register (R0) of the second register bank. Thus, in order to use more than one register bank, the SP should be initialized to a different location of the RAM where it is not used for data storage (ie, higher part of the RAM). 2. Bit Addressable Area:
38383838 38

16 bytes have been assigned for this segment, 20H-2FH. Each one of the 128 bits of this segment can be directly addressed (0-7FH). The bits can be referred to in two ways both of which are acceptable by the ASM-51. One way is to refer to their addresses, i.e., 0 to 7FH. The other way is with reference to bytes 20H to 2FH. Thus, bits 0-7 can also be referred to as bits 20.0-20.7 and bits 8-FH are the same as 21.0-21.7 and so on. Each of the 16 bytes in this segment can also be addresses as a byte. 3. Scratch Pad Area: Bytes 30H through 7FH are available to user as data RAM. However, if the stack pointer has been initialized to this area, enough number of bytes should be left aside to prevent SP data destruction.
39393939 39

Figure7.

128

Bytes

of

RAM

Direct

and

Indirect Addressable.

40404040

40

Special Function Registers: Table 1 contains a list of all the SFRs and their addresses. Comparing table 1 and figure 8 shows that all of the SFRs that are byte and bit addressable are located on the first column of the diagram in figure 8. What do the SFRs Contain just after Poweron or a Reset ? Table 2 lists the contents of each SFR after a power-on reset or a hardware reset.

41414141

41

42424242

42

PSW

Program

Status

Word

(Bit

Addressable):

CY

PSW.7

Carry Flag.

43434343

43

AC F0

PSW.6 PSW.5

Auxiliary Carry Flag. Flag 0 available to the user

for general purpose. RS1 RS0 OV F1 P PSW.4 PSW.3 PSW.2 PSW.1 PSW.0 Register Bank selector bit Register Bank selector bit Overflow Flag. Flag F1 available to the Parity flag. Set/cleared by

1 (SEE NOTE). 0 (SEE NOTE).

user for general purpose. hardware each instruction cycle to indicate an odd/even number of 1 bits in the accumulator. Note: The value presented by RS0 and RS1 selects the corresponding register bank.

44444444

44

Timer/Counters: The AT89C51 has two 16-bit Timer/Counter registers: Timer 0 and Timer 1. The AT89C52 has these two Timer/Counters, and in addition Timer 2. All three can be configured to operate either as Timers or event Counters.

45454545

45

As a Timer, the register is incremented every machine cycle. Thus, the register counts machine cycles. Since a machine cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency. As a Counter, the register is incremented in response to a l to-0 transition at its corresponding external input pin, T0, T1, or (in the AT89C52) T2. 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 2 machine cycles (24 oscillator periods) are required to recognize a l-to-0 transition, the maximum count rate is 1/24 of the oscillator frequency. There are no restrictions on the duty cycle of the external input signal, but it should be held for at least one full machine cycle to
46464646 46

ensure that a given level is sampled at least once before it changes. In addition to the Timer or Counter functions, Timer 0 and Timer 1 have four operating modes: 1.13 bit timer, 2.16 bit timer, 3.8 bit auto-reload, 4.Split timer Timer 2 in the AT89C52 has three modes of operation: Capture, Auto-Reload, and baud rate generator. Timer 0 and Timer 1: Timer/Counters 1 and 0 are present in both the AT89C51 and AT89C52. The Timer or Counter function is selected by control bits C/T have
47474747

in

the

Special

Function modes,

Register are

TMOD(Figure). These two Timer/Counters four operating


47

which

selected by bit pairs (M1, M0) in TMOD. Modes 0, 1, and 2 are the same for both Timer/Counters,but Mode 3 is different. The four modes are described in the following sections.

Mode 0: Both Timers in Mode 0 are 8-bit Counters with a divide-by-32 pre scalar. Figure 7 shows the Mode 0 operation as it applies to Timer 1.In this mode, the Timer register is configured as a 13-bit register. As the count rolls over from all 1s to all 0s, it sets the Timer interrupt flag TF1. The counted input is enabled to the Timer when TR1 = 1 and either GATE = 0 orINT1 =1. Setting GATE=1 allows the Timer to be controlled by external input INT1, to facilitate pulse width measurements.TR1 is a control bit in
48484848 48

the Special Function Register TCON GATE is in TMOD.

(Figure 8).

The 13-bit register consists of all 8 bits of TH1and the lower 5 bits of TL1. The upper 3 bits of TL1 are indeterminate and should be ignored. Setting the run flag (TR1) does not clear the registers.Mode 0 operation is the same for Timer 0 as for Timer 1,except that TR0, TF0 and INT0 replace the corresponding Timer 1 signals in Figure 7. There are two different GATE bits, one for Timer 1 (TMOD.7) and one for Timer 0 (TMOD.3). Mode 1: Mode 1 is the same as Mode 0, except that the Timer register is run with all 16 bits. The clock is applied to the combined high and low timer registers (TL1/TH1). As clock pulses are
49494949 49

received,

the

timer

counts flag. or

up: The

0000H, timer by

0001H,0002H, etc. An overflow occurs on the FFFFH-to-0000H bit in TCON overflow that is continues to count. The overflow flag is the TF1 read written software.See Figure 8. Mode 2: Mode 2 configures the Timer register as an 8-bit Counter (TL1) with automatic reload, as shown in Figure 9. Overflow from TL1 not only sets TF1, but also reloads TL1 with the contents of TH1, which is preset by software. The reload leaves TH1 unchanged. Mode 2 operation is the same for Timer/Counter 0.

50505050

50

51515151

51

Mode 3: Timer 1 in Mode 3 simply holds its count. The effect is the same as setting TR1 = 0. Timer 0 in Mode 3 establishes TL0 and TH0 as two separate counters. The logic for Mode 3 on Timer 0 is shown in Figure 10. TL0 uses the
52525252 52

Timer 0 control bits: C/T, GATE, TR0, INT0, and TF0. TH0 is locked into a timer function (counting machine cycles) and over the use of TR1 and TF1 from Timer 1. Thus, TH0 now controls the Timer 1 interrupt. Mode 3 is for applications requiring an extra 8-bit timer or counter. With Timer 0 in Mode 3, the AT89C51 can appear to have three Timer/Counters, and an AT89C52, can appear to have four. When Timer 0 is in Mode 3, Timer 1 can be turned on and off by switching it out of and into its own Mode 3. In this case, Timer 1 can still be used by the serial port as a baud rate generator or in any application not requiring an interrupt.

53535353

53

54545454

54

55555555

55

56565656

56

INFRARED TECHNOLOGY INFRARED COMMUNICATION 5.1. Introduction Earlier, when man had everything written by hand, the purpose or the need for Data Transfer was null and void. The Wireless Transaction started with the use of Telegraphs, Television, Telephones and Radios etc. with the help of Radio Waves. But, as technology further developed in past few decades, giving birth to the DIGITAL WORLD, where everything is being replaced by the Digital Signals or converted to Digital Signals, the need for Data Transfer has become quintessential, making it compulsory to be coping up with this fast world. Further developments are expected to be in the same. The major part of Communication or Data Transfer these days is done through RF signals, IR signals and Microwaves. 5.2. History of Infrared The discovery of infrared radiation is commonly ascribed to William Herschel, the astronomer, in the early 19th century. Herschel used a prism to refract light from the sun and detected the infrared, beyond the red part of the
57575757 57

spectrum, through an increase in the temperature record on a Thermometer. Simple infrared sensors were used by British, American and German forces in the Second World War as night vision aids snipers. Some snakes and pit-vipers have Infrared sensory organs on their heads to detect their prey in the night. 5.3. What is Infrared? Infrared (IR) radiation is electromagnetic radiation of a wavelength longer than that of visible light, but shorter than that of microwave radiation. The name means below red (from the Latin infra, below), red being the color of visible light of longest wavelength. Infrared radiation spans three orders of magnitude and has wavelengths between approximately 750nm and 1mm.

58585858

58

Infrared IR LEDs are applied in opto-electronics such as in auto-focus cameras and television remote controls and as light sources in some long-range optical-fiber communication systems. Infrared light is not visible to the human eyes. However infrared light is extremely useful in a wide range of applications. The infrared transmitters and receivers used in remote controls allow us to change television channels without having to get out of the chair. The infrared light vision in some video cameras allows video footage to be taken at night.

59595959

59

Infrared in electronics: Infra-Red is interesting, because it is easily generated and doesn't suffer electromagnetic interference, so it is nicely used to communication and control, but it is not perfect, some other light emissions could contains infrared as well, and that can interfere in this communication. The sun is an example, since it emits a wide spectrum or radiation. Lots of things can generate infrared, anything that radiate heat do it, including out body, lamp, stove, oven, car's engine, car's tires, hot asphalt and rocks, plants, even the hot water at the faucet. The massive use of IR LEDs at TV/VCR remote controls and other applications, brought infra-red diodes and transistors (emitter and receivers) at very low cost at the market. To allow a good communication using infra-red, and avoid those "fake" signals, it is imperative to use a "key" that can tell the receiver what is the real data transmitted and what
60606060 60

is generated by the surrounding environment. As an analogy, looking eye naked to the night sky you can see hundreds of stars, but you can spot easily a far away airplane just by its flashing strobe light, even if that blinking light is dimmer than the stars light. That strobe light is the "key", the "coding" element that alerts us. Similar to the airplane at the night sky, the room where the TV is installed may have hundreds of tinny IR sources, our body, and the lamps around, even the hot cup of tea. A way to avoid all those other sources, is generating a key, like the flashing airplane. So, remote controls use to pulsate its infrared in a certain frequency. The IR receiver module at the TV, VCR or stereo "tunes" to this certain frequency and ignores all other IR received. The best frequency for the job is between 30 and 60kHz, the most used is around 36kHz. It works exactly as a radio tunning to a specific station. In this case, the receiver tune to the IR "radio" at 36kHz, and ignores the rest. Your cup of hot tea generates IR, but not at 36kHz, it is flat and plain IR emission, and then, ignored by the TV IR receiver. So, remote controls use the 36kHz (or around) to transmit information. InfraRed light emitted by IR Diodes is
61616161 61

pulsated at 36 thousand times per second, when transmitting logic level "1" and silence for "0". To generate a 36kHz pulsating infrared is quite easy, more difficult is to receive and identify this frequency. This is why some companies produce infrared receives, that contains the filters, decoding circuits and the output shaper, that delivers a square wave, meaning the existence or not of the 36kHz incoming pulsating infrared. It means that those 3 dollars small units, have an output pin that goes high (+5V) when there is a pulsating 36kHz infrared in front of it, and zero volts when there is not this radiation. A square wave of approximately 27uS (microseconds) injected at the base of a transistor, can drive an infrared LED to transmit this pulsating light wave. Upon its presence, the commercial receiver will switch its output to high level (+5V). 5.3.1. (a). Object Detection Using Infrared Light Another very useful application of infrared light is in the detection of objects. This feature is widely used in
62

62626262

hospital operating theatres and in the food preparation industry. A doctor waves his hand past an infrared sensor to turn on and off the water tap in order to eliminate the risk of contaminating his hands on the taps. (b). Infrared (IR) Output and Detection A circuit diagram of the IR LED Transmitter connected to RB3 of the micro-controller. The value of the resistor determines the strength of the light emitted from the IR LED Transmitter. 5.3.2. Sub-Division or IR 1) Near infrared NIR, IR-A DIN: 0.751.4 m in wavelength Defined by the water absorption, and commonly used in fiber optic telecommunication because of low attenuation losses in the SiO2 glass (silica) medium. 2) Short-Wavelength IR SWIR, IR-B DIN: 1.43 m in wavelength. Water absorption increases significantly at 1450 nm. 3) Mid-Wavelength IR MWIR, IR-C DIN: 38 m in wavelength.
63

63636363

4) Long-Wavelength IR LWIR, IR-DIN: 815 min wavelength. 5) Far IR FIR: 151000 m in wavelength. However, these terms are not precise, and are used differently in various studies i.e. near (0.755 m) / mid (530 m) / long (301000 m). Especially at the telecomwavelengths the spectrum is further subdivided into individual bands, due to limitations of detectors, amplifiers and sources. Infrared radiation is often linked to heat, since objects at room temperature will emit radiation mostly concentrated in the mid-infrared band. 5.4. Usage of LED for IR Communication 5.4.1. Introduction A Light-Emitting Diode (LED) is a semiconductor device that emits incoherent narrow spectrum light when electrically biased in the forward direction. This effect is a form of Electro-Luminescence. The color of the emitted light depends on the chemical composition of the semiconductor material used, and can be near-ultraviolet, visible or infrared. Rubin Braun Stein (born 1922), of the Radio Corporation of America, was the first to report on infrared emission from GaAs (Gallium Arsenide) and other
64646464 64

semiconductor alloys in 1955. Nick Holonyak Jr. (born 1928), of the General Electric Company, developed the first practical visible-spectrum LED in 1962. 5.4.2. LED Technology An LED is special type of semiconductor diode. Like a normal diode, it consists of a chip of semiconductor material impregnated, or doped, with impurities to create a structure called a p-n junction. As in other diodes, current flows easily from the p-side or anode to the n-side or cathode, but not in the reverse direction. Charge carrierselectrons and holes flow into the junction from electrodes with different voltages. When electron meets a hole, it falls into a lower energy level, and releases energy in the form of a photon as it does so. The wavelength of the light emitted, and therefore its color, depends on the band-gap energy of the materials forming the p-n junction. In Silicon or Germanium diodes, the electrons and holes recombine by a non-radiating transition which produces no optical emission, because these are indirect band-gap materials. The materials used for an LED have a direct band-gap with energies
65

65656565

corresponding to near-infrared, visible or near-ultraviolet light. LED development began with infrared and red devices made with Gallium Arsenide. Advances in materials science have made possible the production of devices with ever shorter wavelengths, producing light in a variety of colors. Conventional LEDs are made from a variety of inorganic semiconductor materials, producing the following colors: Aluminium Gallium Arsenide (AlGaAs) red and infrared. Aluminium Gallium Phosphide (AlGaP) green. Aluminium Gallium Indium Phosphide (AlGaInP) high-brightness orange-red, orange, yellow and green. Gallium Arsenide Phosphide (GaAsP) red, orangered, orange and yellow. Gallium Phosphide (GaP) red, yellow and green. Gallium Nitride (GaN) green, pure green (or emerald green) and blue. Indium Gallium Nitride (InGaN) near ultraviolet, bluish-green and blue.
66666666 66

Silicon Carbide (SiC) as substrate blue. Silicon (Si) as substrate blue (under development). Sapphire (Al2O3) as substrate blue. Zinc Selenide (Zn Se) blue. Diamond (C) ultraviolet 5.4.3. COLOURED LEDs 5.4.3.1. BLUE AND WHITE LEDs An ultraviolet GaN LED, commercially viable blue LEDs based on the wide band-gap semiconductor Gallium Nitride and Indium Gallium Nitride were invented by Shuji Nakamura while working in Japan at Nichia Corporation in1993 and became widely available in the late 1990s. They can be added to existing red and green LEDs to produce white light, though white LEDs today rarely use this principle. Most white LEDs in production today use a 450 nm 470 nm blue GaN (Gallium Nitride) LED covered by a yellowish phosphor coating usually made of cerium-doped yttrium Aluminium Garnet (Ce3+:YAG) crystals which have been powdered and bound in a type of viscous adhesive. The LED chip emits blue light, part of which is
67676767 67

efficiently converted to a broad spectrum centered at about 580 nm (yellow) by the Ce3+: YAG. The single crystal form of Ce3+:YAG is actually considered a scintillator rather than a Phosphor. Since yellow light simulates the red and green receptors of the eye, the resulting mix of blue and yellow light gives the appearance of white, the resulting shade often called Lunar White. This approach was developed by Nichia and was used by them from 1996 for manufacturing of white LEDs. The pale yellow emission of the Ce3+: YAG can be tuned by substituting the Cerium with other rare earth elements such as Terbium and Gadolinium and can even be further adjusted by substituting some or all of the Aluminium in the YAG with Gallium. Due to the spectral characteristics of the diode, the red and green colors of objects in its blue+yellow light are not as vivid as in broadspectrum light. Manufacturing variations make the LEDs produce light with different color temperatures, from warm yellowish to cold bluish; the LEDs have to be sorted during manufacture by their actual characteristics. White LEDs can also be made by coating near ultraviolet (NUV) emitting LEDs with a mixture of high
68686868 68

efficiency europium based red and blue emitting phosphors plus green emitting Copper and Aluminium doped Zinc Sulphide (ZnS: Cu, Al). This is a method analogous to the way fluorescent lamps work. However the ultraviolet light causes photo degradation to the epoxy resin and many other materials used in LED packing, causing manufacturing challenges and shorter lifetimes. This method is less efficient than the blue LED with YAG: Ce phosphor, as the Stokes Shift is larger and more energy is therefore converted to heat, but yields light with better spectral characteristics, which renders colors better. Due to the higher radiating output of the ultraviolet LEDs than of the blue ones, both approaches offer comparable brightness. The newest method used to produce white light LEDs uses no phosphors at all and is based on homo epitaxially grown Zinc Selenide (ZnSe) on a ZnSe substrate which simultaneously emits blue light from its active region and yellow light from the substrate. A new technique just developed by Michael Bowers, a graduate student at Vanderbilt University in Nashville, involves coating a blue LED with quantum dots that glow white in response to the blue light from the LED. This
69696969 69

technique produces a warm, yellowish-white light similar to that produced by incandescent bulbs. 5.4.4. OPERATION PARAMETERS AND

EFFICIENCY Most typical LEDs are designed to operate with no more than 30-60 mw of electrical power. Around 1999, commercial LEDs capable of continuous use at one watt of input. As well, the semiconductor dies were mounted to metal slugs to allow for heat removal from the LED die. In 2002, 5-watt LEDs were available with efficiencies of 1822 lumens per watt. It is projected that by 2005, 10-watt units will be available with efficiencies of 60 lumens per watt. These devices will produce about as common 50-watt incandescent bulb, and will facilitate use of LEDs for general illumination needs. In September 2003 a new type of blue LED was demonstrated by the company Cree, Inc. to have 35% efficiency at 20 mA. In 2005 they have demonstrated a prototype with a record white LED efficiency of 70 lumens per watt at 350 mA. Today, OLEDs operate at substantially lower efficiency than inorganic (crystalline) LEDs. The
70707070 70

best efficiency of an OLED so far is about 10%. These promise to be much cheaper to fabricate than inorganic LEDs, and large arrays of them can be deposited on a screen using simple printing methods to create a color graphic display. 5.4.5. SPECIFICATION OF LED being used Lens Color Water clear IF = 20mA, VF = 1.4-1.6 V Peak Wavelength = 850 nm View Angle = 70 degrees Transmitting distance = 26 cm (max) We are using this IR LED since Inexpensive, flexible displays Light sources Wall decorations Luminous cloth FEATURES: High sensitivity. Long reception distance. TTL and CMOS compatible. High immunity against ambient light. Low voltage and low power consumption.
71717171 71

Photodiode with integrated circuit. Elliptical lens to improve the characteristics against. High protection ability to EMI. 5.4.6. ADVANTAGES LEDs are capable of emitting light of an intended color without the use of color filters that traditional lighting methods require. The shape of the LED package allows light to be focused. Incandescent and fluorescent sources often require an external reflector to collect and direct it in a useable manner. LEDs are insensitive to vibration and shocks, unlike incandescent and discharge sources. LEDs are built inside solid cases that protect them, making them hard to break and extremely durable. LEDs have an extremely long life span: typically ten years, twice as long as the best fluorescent bulbs and twenty times longer than the best incandescent bulbs. Further, LEDs fail by dimming over time, rather than the abrupt burn-out of incandescent bulbs. LEDs give off less heat than incandescent light bulbs with similar light output.
72727272 72

LEDs light up very quickly. An illumination LED will achieve full brightness in approximately 0.01 seconds, 10 times faster than an incandescent light bulb(0.1 second), and many times faster than a compact fluorescent lamp, which starts to come on after 0.5 seconds or 1 second, but does not achieve full brightness in microseconds, or possibly less if its used for communication devices.

5.4.7. DISADVANTAGES LEDs are currently more expensive than more conventional lighting technologies. The additional expense partially stems from the relatively low lumen output (requiring more light sources) and drive circuitry/power supplies needed. A good measure to compare lighting technologies is lumen/dollar. LED performance largely depends on the ambient temperature of the operating environment. Driving an LED hard in high ambient temperatures may result in overheating of the LED package, eventually to device failure. Adequate heat-sinking is required to maintain long life. This is especially important when considering automotive/military applications where the device must
73737373 73

operate over a large range of temperatures, with government-regulated output. 5.4.8. LIST OF APPLICATIONS LEDs are used as informative indicators in various types of embedded systems. Status indicators. Optical switch. Continuity indicators. Thin, lightweight message Displays at airports and railway stations and as destination displays for trains, buses, trams and ferries. Red or yellow LEDs are used in indicator and alphanumeric displays in environments where night vision must be retained: aircraft cockpits, submarine and ship bridges, astronomy observatories, and in the field, e.g. night time animal watching and military field use. To transmit digital information. Remote controls for TVs, VCRs etc, using Infrared LEDs. In Optical fiber communications. In dot matrix arrangements for displaying messages.
74747474 74

In traffic signals, LED clusters are replacing colored incandescent bulbs. Movement sensors, for example, in optical computer mouse.

IR TRANSMITTER: In our project we are using an RC5 standard IR remote control for producing the IR signal required for communication. Remote controls use the 36kHz (or around) to transmit information. Infrared light emitted by IR Diodes is pulsated at 36 thousand times per second, when transmitting logic level "1" and silence for "0".
75757575 75

Fig5.1: RC5 standard IR Remote Control Each time we press a button at the remote control, it sends a train of 14 bits, 1.728ms per bit, the whole train is repeated every 130ms if you keep the button pressed. Each bit is sliced in two halves. The left and right half has opposed levels. If the bit to be transmitted is one (1), its left side is zero while its right side is one. If the bit to be transmitted is zero (0), its left side is one while the right side is zero.

FIG5.2: BIT PULSE EMITTED FROM THE IR REMOTE

76767676

76

It means that the second half of the bit is actually the same meaning of the bit to be transmitted. The Philips remote control sends 14 bits in sequence as you can see below. .

FIG 5.3: 14 BIT PULSE EMITTED FROM THE PHILIPS REMOTE The 14 bits include 2 start bits for the automatic gain control in the infrared receiver. 1 toggle bit (changes every time when a new button is pressed on the IR transmitter) 5 address bits for the system address
77777777 77

6 instructions bits for the pressed key We need not decode the first two bits, not even the CHK bit. So you can skip those 3 bits and start to receive the ADDRESS bits. So, upon sensing the first low level, the software should wait for 4.752 milliseconds(approximately 1.728x3 ms) and then start to read the next 11 bits spaced 1.728ms each. The first 5 bits are Address and the next 6 bits are Command bits. To generate a 36kHz pulsating infrared is quite easy, more difficult is to receive and identify this frequency. This is why some companies produce infrared receives, that contains the filters, decoding circuits and the output shaper, that delivers a square wave, meaning the existence or not of the 36kHz incoming pulsating infrared. A square wave of approximately 27uS (microseconds) injected at the base of a transistor, can drive an infrared LED to transmit this pulsating light wave. Upon its presence, the commercial receiver will switch its output to high level (+5V).

78787878

78

FIG5.4: IR TRANSMITTER CIRCUIT If you can turn on and off this frequency at the transmitter, your receiver's output will indicate when the transmitter is on or off. IR Receiver:

The IR receiver is used to receive the IR signal, this circuit is designed to receive 36 kHz signal with use of IR receiver module (TSOP1738). The 5V DC power
79

79797979

supply is given to the receiver. The IR receiver module (TSOP1738), which gets 5.1V power supply through, receives the transmitted signal of about 36 kHz. 5.3.1 TSOP 1738 The TSOP17.. series are miniaturized receivers for infrared remote control systems. PIN diode and preamplifier are assembled on lead frame, the epoxy package is designed as IR filter. The demodulated output signal can directly be decoded by a microprocessor. TSOP17.. is the standard IR remote control receiver series, supporting all major transmission codes. They are frequently used for RAM or Flash memory ICs dues to their high pin count and small volume.

FIG5.5 TSOP 1738 Features 1. Photo detector and preamplifier in one package
80808080 80

2. Internal filter for PCM frequency 3. Improved shielding against electrical field disturbance 4. TTL and CMOS compatibility 5. Output active low 6. Low power consumption 7. High immunity against ambient light 8. Continuous data transmission possible(up to 2400 bps) 9. Suitable burst length .10 cycles/burst The arrow mark in the figure below shows the transmitted IR signal being received by the TSOP receiver.

FIG5.6: TSOP used as IR receiver Those IR demodulators have inverted logic at its output, when a burst of IR is sensed it drives its output to low level, meaning logic level = 1.

81818181

81

The output of the TSOP receiver is connected to pin 3.2(interrupt pin) of the micro controller as shown below. It is for accepting external interrupts.

FIG5.7: The IR receiver interfaced to microcontroller

HARDWARE INTERFACING 6.1.1) RELAY


82

82828282

A relay is an electrically operated switch. Current flowing through the coil of the relay creates a magnetic field which attracts a lever and changes the switch contacts. The coil current can be on or off so relays have two switch positions and they are double throw (changeover) switches. Relays allow one circuit to switch a second circuit which can be completely separate from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. There is no electrical connection inside the relay between the two circuits, the link is magnetic and mechanical. The coil of a relay passes a relatively large current, typically 30mA for a 12V relay, but it can be as much as 100mA for relays designed to operate from lower voltages. Most ICs (chips) cannot provide this current and a transistor is usually used to amplify the small IC current to the larger value required for the relay coil. The maximum output current for the popular 555 timer IC is 200mA so these devices can supply relay coils directly without amplification. Circuit symbol for a relay:
83

83838383

Relays are usuallly SPDT or DPDT but they can have many more sets of switch contacts, for example relays with 4 sets of changeover contacts are readily available. For further information about switch contacts and the terms used to describe them please see the page on switches. Most relays are designed for PCB mounting but you can solder wires directly to the pins providing you take care to avoid melting the plastic case of the relay. The supplier's catalogue should show you the relay's connections. The coil will be obvious and it may be connected either way round. Relay coils produce brief high voltage 'spikes' when they are switched off and this can destroy transistors and ICs in the circuit. To prevent damage you must connect a protection diode across the relay coil.

84848484

84

The animated picture shows a working relay with its coil and switch contacts. You can see a lever on the left being attracted by magnetism when the coil is switched on. This lever moves the switch contacts. There is one set of contacts (SPDT) in the foreground and another behind them, making the relay DPDT. The relay's switch connections are usually labelled COM, NC and NO. COM = Common, always connect to this, it is the moving part of the switch. NC = Normally Closed, COM is connected to this when the relay coil is off. NO = Normally Open, COM is connected to this when the relay coil is on. Choosing a relay: You need to consider several features when choosing a relay: 1. Physical size and pin arrangement: If you are choosing a relay for an existing PCB you will need to ensure that its dimensions and pin arrangement are suitable. You should find this information in the supplier's catalogue.
85

85858585

2. Coil voltage: The relay's coil voltage rating and resistance must suit the circuit powering the relay coil. Many relays have a coil rated for a 12V supply but 5V and 24V relays are also readily available. Some relays operate perfectly well with a supply voltage which is a little lower than their rated value. 3. Coil resistance: The circuit must be able to supply the current required by the relay coil. You can use Ohm's law to calculate the current: Relay coil current = supply voltage /Coil Resistances. For example: A 12V supply relay with a coil resistance of 400 passes a current of 30mA. This is OK for a 555 timer IC (maximum output current 200mA), but it is too much for most ICs and they will require a transistor to amplify the current. Protection diodes for relays: Transistors and ICs (chips) must be protected from the brief high voltage 'spike' produced when the relay coil is switched off. The diagram shows how a signal diode (eg 1N4148) is connected across the relay coil to provide this
86868686 86

protection. Note that the diode is connected 'backwards' so that it will normally not conduct. Conduction only occurs when the relay coil is switched off, at this moment current tries to continue flowing through the coil and it is harmlessly diverted through the diode. Without the diode no current could flow and the coil would produce a damaging high voltage 'spike' in its attempt to keep the current flowing.

Relays

and transistors

compared: Like relays, transistors can be used as an electrically operated switch. For switching small DC currents (< 1A) at low voltage they are usually a better choice than a relay. However transistors cannot switch AC or high voltages (such as mains electricity) and they are not usually a good
87878787 87

choice for switching large currents (> 5A). In these cases a relay will be needed, but note that a low power transistor may still be needed to switch the current for the relay's coil! The main advantages and disadvantages of relays are listed below: Advantages of relays: Relays can switch AC and DC, transistors can only switch DC. Relays can switch high voltages, transistors cannot. Relays are a better choice for switching large currents (> 5A). Relays can switch many contacts at once. Disadvantages of relays: Relays are bulkier than transistors for switching small currents. Relays cannot switch rapidly (except reed relays), transistors can switch many times per second. Relays use more power due to the current flowing through their coil. Relays require more current than many chips can provide, so a low power transistor may be needed to switch the current for the relay's coil.
88888888 88

6.1.2) ULN2003: HIGH-VOLTAGE, HIGH-CURRENT DARLINGTON ARRAYS Featuring continuous load current ratings to 500 mA for each of the drivers, the ULN2003 highvoltage, high-current Darlington arrays is ideally suited for interfacing between low-level logic circuitry and multiple peripheral power loads.

89898989

89

Typical power loads totaling over 260 W (350 mA x 8, 95 V) can be controlled at an appropriate duty cycle depending on ambient temperature and number of drivers turned on simultaneously. Typical loads include relays, solenoids, stepping Motors, magnetic print hammers, multiplexed LED and incandescent displays, and heaters. All devices feature open-collector outputs with integral clamp diodes. The ULN2003 has series input resistors selected for operation directly with 5 V TTL or CMOS. These devices will handle numerous interface needs particularly those beyond the capabilities of standard logic buffers. The ULN2003 has series input resistors for operation directly from 6 V to 15 V CMOS or PMOS logic outputs.The ULN is the standard Darlington arrays. The outputs are capable of sinking 500 mA and will withstand at least 50 V in the off state. Outputs may be paralleled for higher load current capability. The ULN2003 will withstand 95 V in the off state.These Darlington arrays are furnished in 18-pin dual in-line plastic packages (suffix A) or 18-lead smalloutline plastic packages (suffix LW). All devices are pinned with outputs opposite inputs to facilitate ease of circuit board layout. Prefix ULN devices are rated for
90909090 90

operation over the temperature range of -20C to +85C; prefix ULQ devices are rated for operation to -40C. 1. Output Voltage, VCE
2. 3. 4.

Input Voltage, VIN ..............................30 V Continuous Output Current, IC .... 500 mA Continuous Input Current, IIN ....... 25 mA (one Darlington pair) .................. 1.0 W (total package) ..................... See Graph Prefix ULN .............. -20C to + 85C ULQ ............... -40C to +85C

5. Power Dissipation, PD
6. 7.

8. Operating Temperature Range, TA


9. 10. Prefix

11.Storage Temperature Range,


12. TS

................................ -55C to +150C

FEATURES: TTL, DTL, PMOS, or CMOS Compatible Inputs Output Current to 500 mA Output Voltage to 95 V Transient-Protected Outputs
91

91919191

Dual In-Line Package or Wide-Body SmallOutline Package

TSOP 1738:

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

Features:

92929292

92

Photo detector and preamplifier in one package Internal filter for PCM frequency

Improved shielding against electrical field disturbance

TTL and CMOS compatibility

Output active low Low power consumption

High immunity against ambient light Continuous data transmission possible (up to 2400 bps)

93939393

93

Suitable burst length .10 cycles/burst

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.

94949494

94

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
95959595 95

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

Pin

Number 1 Vss 2

Name

Logic

State 0V -

Description

supply Contrast 3 Control of operating 4

Vdd Vee

+5V 0 - Vdd D0 interpreted commands D0 D7 are interpreted as data Write data (from controller to LCD) D7 are as

RS

0 1

R/W
96

0 1

96969696

Read

data

(from

0 6 E 1 From 1 to 0 7 8 9 Data / 10 commands 11 12 13 14 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 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

LCD screen: 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
97979797 97

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

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 R R D D D S W 7 6 Clear display 0 0 0 0 Cursor home 0 0 0 0 Entry mode 0 0 0 0 set Display 0 0 0 0 on/off control Cursor/Displ 0 0 0 0 ay Shift Function set 0 0 Set CGRAM address Set DDRAM address Read BUSY flag 0 0 0 0 0 1 5 0 0 0 0 0 0 0 0 0 0 0 1 0 1 D L D4 D3 D2 D1 0 0 1 D Executio 0 n Time 0 1 1.64mS 1 x 1.64mS I/ S 40uS D

D U B 40uS x x 40uS x x 40uS 40uS 40uS -

D/ R/ C L

0 0 1

N F

0 1 CGRAM address 1 DDRAM address B DDRAM address F


99

99999999

(BF) Write CGRAM

to or 1 0

D D D 7 6 5 D D D

D4 D3 D2 D1

D 0 D 0

40uS

DDRAM Read from CGRAM or 1 1

7 6 5 DDRAM I/D 1 = Increment (by 1) right 0 = Decrement (by 1) S 1 = Display shift on interface 0 = Display shift off interface D 1 = Display on in two lines 0 = Display off in one line U 1 = Cursor on format 5x10 dots
100100100100 10 0

D4 D3 D2 D1

40uS

R/L 1 = Shift 0 = Shift left DL 1 = 8-bit 0 = 4-bit

N 1 = Display 0 = Display

F 1 = Character

0 = Cursor off format 5x7 dots

0 = Character

B 1 = Cursor blink on Display shift 0 = Cursor blink off Cursor shift LCD Connection

D/C

= 0 =

Depending on how many lines are used for connection to the microcontroller, there are 8-bit 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
101101101101 10 1

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
102102102102 10 2

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.

103103103103

10 3

Fig: Procedure on 8-bit initialization. LCD INTERFACING WITH THE MICROCONTROLLER:

104104104104

10 4

105105105105

10 5

CHAPTER SOFTWARE Software: KEIL U VISION2.0

106106106106

10 6

The Keil Software helps us to compile our C code, assemble our assembler source files, link our program

together, create HEX files, and debug our target program. Table 2.1 List of all predefined Vision2 debug functions

107107107107

10 7

9.1 ASSEMBLY LANGUAGE PROGRAMMING: BASIC FORM OF ALP:

The steps to create executable assembly language program outlined follows. 1. First we use an editor to type in a program similar to program. Many excellent editors or word processors are available that can be used to create and/or edit the program. A widely used
108108108108 10 8

an

are as

editor is the MS-DOS EDIT program (or notepad in Windows), which comes with all Microsoft operating systems. Notice that the editor must be able to produce an ASCII file. For many assemblers, the file names follow the usual DOS conventions, but the source file has the extension "ASM "or "SRC ", depending on which assembler you are using. Check your assembler for the convention. The "asm ", extension for the source file is used by an assembler in the next step. 2. The "ASM "source file containing the program code is created in step 1 is fed to an AT89C51 assembler. The assembler converts the instructions into machine code. The assembler will produce an object file and a list file. The extension for the object file is "OBJ "by the extension for the list file is "1ST ". 3. Assemblers require a third step calling linking. The link program takes one or more objects files and produces an absolute object file with the extension "ABS". AT89C51 trainers that have a monitor program use this ABS file. 4. Next the "ABS "file is fed into a program called "OH "(Object to Hex Converter) which creates a file with extension "HEX "that these ready to burn into ROM. This
109109109109 10 9

program comes with all AT 89C51 assemblers. Recent Windows-based assemblers combine steps 2 through 4 into one step. EVALUATION OF KEIL SOFTWARE: 1. Start the Vision Program 2. After the program has started: Select File, New from the program menu Type your assembly file. The following is an example of a toggle program.
org 0H mov A, #0ffH route: mov P1, A acall delay1msec cpl a mov P2, a acall delay1msec sjmp route delay1msec: mov R3, #200 up: mov R2, #250 same: djnz R2, same djnz R3, up ret end

110110110110

11 0

3. Select File, Save from the program menu The first time you save the program a dialog box will popup and allow you to name your file and file type. Save program with filename: xxxxx.asm The File type is mentioned at last (.asm) means assembly language 4. Select Project, New Project from the program menu Give some project name: xxxx.prj 5. Click on the Add button A dialog-box appears, allowing you to add files to the project Change the file type to Assembly. 6. Select your assembly file. Click on the Add button then close the Add dialog box. 7. Click on Save in your Project dialog box. 8. Select Project, Make: Build Project from the program menu This creates the HEX file you need for the 8051 Using the Keil dScope Debugger 1. Select Run, dScope debugger from the program menu
111111111111 11 1

The debug program will start a new session 2. Select File, load CPU driver from the program menu Choose the AT89C51.dll from the drop down list box; you can also select this directly. 3. Select File, load object file from the program menu. Change the file type to HEX Select your hex file, e.g. Toggle. Hex Click OK 4. You should now see the source code of the file typed in earlier 5. Select Peripherals, I/O Ports from the program menu. So that you can see the how output varies on ports. Select Port 0, Port 1, Port 2 and Port 3 6. Click on go to see the real time update of the I/O ports. 7. Click on stop when you are finished. You can also single step through you program or set break points at locations that you want the debugger to stop at. To set a breakpoint, double click on the line. CODE: ORG 0000h
112112112112 11 2

MOV P2,#00H ; TO MAKE PORT2 AS OUTPUT ACALL initLCD ; INITIALIZE LCD ACALL SERIALPORT REPEAT: ACALL IR_RECEIVE ; RECEIVE ADDRESS

ACALL ADDR_COMM IN R0 AND R1

AND COMMAND FROM IR REMOTE AND SAVE THEM

CJNE R1,#01H,TWO ; CHECK THE VALUE IN R1 TO CONTROL THE APPLIANCES MOV A,#'A' ACALL TX MOV DPTR,#DEVICE1_ON ACALL DISPLAY SJMP REPEAT TWO:CJNE R1,#02H,THREE MOV A,#'B'
113113113113 11 3

ACALL TX MOV DPTR,#DEVICE2_ON ACALL DISPLAY SJMP REPEAT THREE:CJNE R1,#03H,TWO MOV A,#'C' ACALL TX MOV DPTR,#DEVICE1_OFF ACALL DISPLAY SJMP REPEAT FOUR:CJNE R1,#04H,THREE MOV A,#'D' ACALL TX MOV DPTR,#DEVICE2_OFF ACALL DISPLAY SJMP REPEAT

DISPLAY:
114114114114

;TO DISPLAY ON LCD


11 4

AGAIN: CLR A MOVC A,@A+DPTR JZ EXIT ACALL DATAWRT INC DPTR SJMP AGAIN EXIT: RET

TX:MOV SBUF,A JNB TI,$ CLR TI RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; initLCD: ACALL DELAY ACALL DELAY
115115115115 11 5

LCD FUNCTIONS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ACALL DELAY MOV A,#30H ACALL COMMD ACALL DELAY MOV A,#30H ACALL COMMD ACALL DELAY MOV A,#30H ACALL COMMD ACALL DELAY MOV A,#20H ACALL COMMD ACALL DELAY MOV A,#02H ACALL COMMD ACALL DELAY
11 6

116116116116

MOV A,#01H

ACALL COMMD ACALL DELAY MOV A,#0CH ACALL COMMD ACALL DELAY MOV A,#80H ACALL COMMD ACALL DELAY RET COMMD: ACALL DELAY

MOV R3,A ANL A,#0F0H MOV P1,A


117117117117

;P1 FOR LCD


11 7

CLR P1.2 SETB P1.3 NOP CLR P1.3 MOV A,R3

;RS=0 COMMAND REG ;ENABLE PIN

ANL A,#0F0H MOV P1,A CLR P1.2 SETB P1.3 NOP CLR P1.3 RET DATAWRT: ACALL DELAY MOV R3,A ANL A,#0F0H MOV P1,A SETB P1.2 SETB P1.3 NOP CLR P1.3
118118118118 11 8

;RS=1 ;enable pin

MOV A,R3 SWAP A ANL A,#0F0H MOV P1,A SETB P1.2 SETB P1.3 NOP CLR P1.3 RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; IR FUNCTIONS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SERIALPORT: MOV TMOD,#20H MOV SCON,#50H MOV TH1,#-3 SETB TR1 RET
119119119119 11 9

IR_RECEIVE: chk: jb p3.2,chk nop chk1: jnb p3.2,chk1

120120120120

12 0

nop chk2: jb p3.2,chk2 acall delay1 RET

ADDR_COMM: MOV R2,#05H GET_ADDR:jnb p3.2,chk4 SETB C MOV A,R0 RLC A MOV R0,A sjmp exit4 chk4: CLR C MOV A,R0 RLC A
121121121121 12 1

MOV R0,A exit4: DJNZ R2,GET_ADDR

GET_COMMD: MOV R2,#06H AGAIN2:jnb p3.2,chk5 SETB C MOV A,R1 RLC A MOV R1,A sjmp exit5 chk5: CLR C RLC A MOV A,R1 MOV R1,A exit5: RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DELAY FUNCTIONS
12 2

DJNZ R2,AGAIN2

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122122122122

DELAY: MOV R4,#0FFH HERE1: MOV R2,#07FH HERE: RET delay1: MOV R4,#20H HERE2: MOV R2,#18H HERE3: DJNZ R2,HERE3 DJNZ R4,HERE2 RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DJNZ R2,HERE DJNZ R4,HERE1

DEVICE1_ON: DB "DEVICE 1 ON",0 DEVICE2_ON: DB "DEVICE 2 ON",0 DEVICE1_OFF: DB "DEVICE 1 OFF",0 DEVICE2_OFF: DB "DEVICE 2 OFF",0 END
123123123123 12 3

RESULTS

124124124124

12 4

125125125125

12 5

CONCLUSION

126126126126

12 6

BIBILIOGRAPHY

127127127127

12 7