final report home automation - all

Upload: chamkaur-singh-mehal

Post on 14-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Final Report Home Automation - ALL

    1/80

    CHAPTER I

    INTRODUCTION

    Some of the main devices used in embedded products are Microprocessors

    and Microcontrollers, Microprocessors are commonly referred to as general

    purpose processors as they simply accept the inputs, process it and give the

    output. In contrast, a microcontroller not only accepts the data as inputs but also

    manipulates it, interfaces the data with various devices, controls the data and thus

    finally gives the result. As everyone in this competitive world prefers to make the

    things easy and simple to handle, this project sets an example to great extent.

    Today is the trend of Wireless technology. Nowadays, we are seeing that

    everything has gone wireless. In this case, it becomes necessary to make a System

    by which we can control appliances in our home by sending SMS to GSM

    Modem. For example, if we send certain message to GSM Modem, then Fan of

    particular room will get switched on and if we again send a message, then Fan

    can be switched off. This means that basically we are controlling our home

    appliances with the movement of our fingers that become messages. This project

    we can mainly use in Homes, Agricultural Farms. The fact that we are using the

    GSM technology to control devices is one of the new technologies in the

    embedded field to make the communication between Microcontroller and mobile.

    This project is a remote home automation with MODEM connected to it, so if the

    user wants to control some appliances, he or she will send the messages in SMS

    format, the MODEM in the automation system will receive the message and

    update the display according to the message and turn off or on the particular

    device that we want to access. For every message received from the user mobile,

    Microcontroller will work accordingly.

    GSM based Home Automation System implements the emerging

    applications of the GSM technology. Using GSM networks, a control system has

    been proposed that will act as an embedded system which can monitor and1

  • 7/30/2019 Final Report Home Automation - ALL

    2/80

    control appliances and other devices locally using built-in input and output

    peripherals.

    GSM (Global System for Mobile Communications): It is a cellular

    communication standard.

    SMS (Short Message Service): It is a service available on most digital mobile

    phones that permit the sending of short messages (also known as text messaging

    service), that can be used to perform specific operations that we want to perform

    by interfacing the GSM Modem with Microcontroller.

    2

  • 7/30/2019 Final Report Home Automation - ALL

    3/80

    CHAPTER-II

    LITERATURE SURVEY

    2.1 MOTIVATION:

    In present digitalized world, the exploit of GSM and SMS is popular.

    Today the Electronics world is changing so fast then we have to get in sync with

    the world so that we can learn new technologies that are real fascinating. So, we

    have taken first step in this to design GSM based Home Automation System. By

    sitting in another room, you can operate Lights and Fans of another room by

    sending messages to the GSM Modem.

    From the past many years we are seeing the Automation is being done

    using various Sensors. So we were thinking that if somehow we can use Wireless

    technique instead of sensors, so we come to the conclusion to design this Project

    which will eliminate the work of Sensors with less manual operation. If you have

    gone to Market and forgot to switch off the Fan, then you can just do the same by

    sending message to the number that has been put in the GSM Modem.

    2.2 BACKGROUND:

    Market research analysts are predicting that the wireless technologies will

    eventually become more widespread than the various wired solutions. The

    wireless communications present the ideal solution for the home network .This

    increasing demand of getting wireless can be seen not only in the field

    communication but also in the transferring information and data. The cell phones

    which are the best example of wireless data and voice transfer can be used for

    many other purposes that can replace the traditional system. One simple way of

    using this wireless communication is to use a simple cell phone for sending

    messages. The GSM modem used at the receiver end is used to receive the3

  • 7/30/2019 Final Report Home Automation - ALL

    4/80

    messages and LCD to display them. As we are using mobile for sending

    messages, its easy to handle and operate. As it's a wireless transmission the

    system has very less errors and maintenance. Also, we are dealing with digital

    signals, so loss of data and factors like Noise are negligible.

    2.3 AIM:

    To design and implement a GSM based Wireless Home Automation

    System using 8051 Microcontroller coded in Embedded C Language.

    2.4 REQUIREMENT ANALYSIS:

    2.4.1 Hardware requirements

    The components those are required for Wireless Home AutomationSystem project is given below.

    1. Microcontroller (AT89S52).

    2. MAX 232.

    3. DB9 or RS232 connector.

    4. Power Supply.

    5. LCD Display (16x2).

    6. GSM Modem.

    7. SIM.

    4

  • 7/30/2019 Final Report Home Automation - ALL

    5/80

    2.4.2 Software requirements

    1. KEIL Vision 4 IDE C51 Embedded Cross Compiler.

    2. Proteus 7.8 Simulator.

    3. 8051 ISP Programmer

    2.5 SCOPE:

    The scope of this project is to introduce a new technology for home

    automation system using GSM. A user can send a message from anywhere in theworld. Multilingual display can be another added variation of the project.

    Graphical display can also be considered as a long term but achievable and

    targetable output. Also, we can extend this project to make it more fascinating for

    systems like Home and Industrial Security system. It can also be used in Military

    applications for remote bomb triggering, launch missiles etc.

    2.6 ADVANTAGES:

    Accessible everywhere.

    Low cost, reliable and high accuracy.

    Not much manual effort.

    Give feedback response to the sender.

    Saves Time, Energy and finally Environment friendly.

    5

  • 7/30/2019 Final Report Home Automation - ALL

    6/80

    CHAPTER - III

    DESIGN METHODOLOGY

    3.1 HARDWARE SYSTEM DESIGN:

    3.1. 1 Block Level Design

    The block diagram of GSM based message display system is given below

    Fig 3.1: Functional block diagram of Wireless Home Automation.

    6

  • 7/30/2019 Final Report Home Automation - ALL

    7/80

    3.1.2 Selection Of Hardware:

    The hardware selected must be such a way that:

    Low cost

    Low power consumption, small, fast

    Continually reacts to changes in the systems environment

    Must compute certain results in real-time without delay

    Simple design

    Easy maintainability and interoperability

    Bug-free/Correctness, safety, many more.

    3.1.3 Design Considerations Of Microcontroller

    WHY AT89S52?

    The system requirements and control specifications clearly rule out the

    use of 16, 32 bit microcontrollers.

    It contains non-volatile 64KB Flash program memory that is bothparallel programmable and serial In-System and In-Application

    Programmable.

    In-System Programming (ISP) allows the user to download new code

    while the microcontroller sits in the application.

    Its ROM is double of the ROM of 8051 i.e. 8KB and its RAM is 256

    bytes. It has 3 timers and a Serial port that allows Serial Communication.

    3.1.3 Microcontroller 8051

    The 8051 is an 8 bit microcontroller originally developed by Intel in 1980.

    It is one of the most popular microcontrollers in the world for its high

    performance, rich instruction set and low cost. This device is a Single-Chip 8-Bit

    Microcontroller manufactured in an advanced CMOS process and is a derivative

    7

  • 7/30/2019 Final Report Home Automation - ALL

    8/80

    of the 8051 microcontroller family. The instruction set is 100% compatible with

    the 8051 instruction set. Three criteria in choosing the microcontrollers are as

    follows:

    1. Meeting the computing needs of the task at hand efficiently and cost

    effectively.

    2. Availability of software development tools such as compliers,

    assemblers, and debuggers.

    3. Wide availability and reliable sources of the microcontroller.

    Some of the features that have made the 8051 popular are:

    64 KB on chip program memory.

    128 bytes on chip data memory (RAM).

    4 register banks.

    128 user defined software flags.

    Four 8-bit data bus

    16-bit address bus

    32 general purpose registers each of 8 bits

    16 bit timers (usually 2, but may have more, or less).

    3 internal and 2 external interrupts.

    Bit as well as byte addressable RAM area of 16 bytes.

    Four 8-bit ports, (short models have two 8-bit ports).

    16-bit program counter and data pointer.

    8

  • 7/30/2019 Final Report Home Automation - ALL

    9/80

    1 Microsecond instruction cycle with 12 MHz Crystal.

    8051 models may also have a number of special, model-specific features,

    such as UARTs, ADC, Op Amps, etc...

    3.1.3.1 Pin Description of AT89S52

    Fig 3.1: 40 Pin Description of 8051.

    9

  • 7/30/2019 Final Report Home Automation - ALL

    10/80

    3.1.3.2 Internal architecture of AT89S52

    The AT89S52 contains a non-volatile 64KB Flash program memory that is

    both parallel programmable and serial In-System Programmable. In-System

    Programming (ISP) allows the user to download new code while the

    microcontroller sits in the application.

    8051 is the first controller developed by Intel. It is 8-bit microcontroller

    meaning it can process 8 bits of data at a given time because it has only 8 data

    lines.Nowadays, there are many variant of 8051 manufactured by various

    Electronics companies but the basic structure of all the variant of 8051 is similar

    to that of 8051 that was developed by the Intel. The variants of 8051 are

    AT89C51, AT89C52, AT89S51, AT89S52 etc. These are manufactured by

    Atmel. In the same way, some other companies like Motorola, Microchip, and

    Dallas Semiconductors etc also manufacture the microcontrollers that are variants

    of 8051. These companies have permission that they can change the memory

    specifications but the basic structure should remain same as Intels 8051 and it

    must have 40 pins. Intel has the first copyright of 8051; if any company wants to

    change the design of controller then at first it needs the permission from Intel.

    10

  • 7/30/2019 Final Report Home Automation - ALL

    11/80

    The internal architecture of AT89S52 microcontroller:

    Fig 3.2: Internal architecture of AT89S52.

    11

  • 7/30/2019 Final Report Home Automation - ALL

    12/80

    3.1.3.2.1 I/O ports:

    All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which

    can be configured as inputs or outputs. Accordingly, in total of 32 input/output

    pins enabling the microcontroller to be connected to peripheral devices are

    available for use.Pin configuration, i.e. whether it is to be configured as an input(1) or an output (0), depends on its logic state. In order to configure a

    microcontroller pin as an input, it is necessary to apply logic zero (0) to

    appropriate I/O port bit. In this case, voltage level on appropriate pin will be 0.

    The 4I/O ports of 8051 are designated as port 0, port 1, port 2, and port 3.

    All these I/O ports have different functions and conditions while connecting to

    external peripherals.

    3.1.3.2.1.a Port 0 (P0)-

    The P0 port is characterized by two functions. If external memory is used

    then the lower address byte (addresses A0-A7) is applied on it. Otherwise, all bits

    of this port are configured as inputs/outputs. The other function is expressed

    when it is configured as an output. Unlike other ports consisting of pins with

    built-in pull-up resistor connected by its end to 5 V power supply; pins of this

    port have this resistor left out. If any pin of this port is configured as an input then

    it acts as if it floats. Such an input has unlimited input resistance and

    undetermined potential. When the pin is configured as an output, it acts as an

    open drain. By applying logic 0 to a port bit, the appropriate pin will be

    connected to ground (0V). By applying logic 1, the external output will keep on

    floating. In order to apply logic 1 (5V) on this output pin, it is necessary to built

    in an external pull-up resistor.

    12

  • 7/30/2019 Final Report Home Automation - ALL

    13/80

    3.1.3.2.1.b Port 1 (P1)-

    P1 is a true I/O port, because it doesn't have any alternative functions as is

    the case with P0, but can be configured as general I/O only. It has a pull-up

    resistor built-in and is completely compatible with TTL circuits.

    3.1.3.2.1.c Port 2 (P2)-

    P2 acts similarly to P0 when external memory is used. Pins of this port

    occupy addresses intended for external memory chip. This time it is about the

    higher address byte with addresses A8-A15. When no memory is added, this port

    can be used as a general input/output port showing features similar to P1.

    3.1.3.2.1. d Port 3 (P3)-

    All port pins can be used as general I/O, but they also have an alternative

    function. In order to use these alternative functions, a logic one (1) must be

    applied to appropriate bit of the P3 register. In terms of hardware, this port is

    similar to P0, with the difference that its pins have a pull-up resistor built-in.

    3.1.3.2.2 Interrupts controls:

    There are 7 kinds of interrupt controllers that 8051 handles. They are as

    follows.

    1. INT0 external interrupt.

    2. INT1 external interrupt.

    3. Timer 0

    4. Timer 1

    5. Reset.

    6. Transmitted interrupt (TXD).

    13

  • 7/30/2019 Final Report Home Automation - ALL

    14/80

    7. Received interrupt (RXD).

    There are two types of external hardware interrupts. Pin 12 (P3.2) and pin 13

    (P3.3) of the 8051, designated as INT0 and INT1, are used as external hardware

    interrupts. Upon the activation of these pins, the 8051 gets interrupted in

    whatever it is doing and jumps to the vector table to perform the interrupt service

    routines (ISR).

    Timer 0 and timer 1 interrupts can be used in pooling method. In this method,

    we have to wait until the TF is raised. The problem with this method is that the

    microcontroller is tied down the controller. If the timer interrupt in the IE registeris enabled, whenever the timer rolls over, TF is raised, and the microcontroller is

    interrupted in whatever it is doing, and jumps to the interrupts vector table to

    service the ISR.

    Reset pin is an input pin and is active high (normally low). Upon applying

    a high pulse to this pin, the microcontroller will reset and terminate all activities.

    This is often referred to as power-on reset. In order for RESET input to be

    effective, it must have a minimum duration of two machine cycles. In other

    words, the high pulse must be high for a minimum of two machine cycles before

    it is allowed to go low. TXD and RXD are serial communication interrupts.

    3.1.3.2.3 Bus Controls

    The main bus controllers available in 8051 are ALE, EA, RST and PSEN.

    ALE (Address Latch Enable):

    It is output pulse for latching the low byte of the address during an access

    to external memory. In normal operation, ALE is emitted twice every machine

    cycle, and can be used for external timing or clocking. Note that one ALE pulse is

    skipped during each access to external data memory. ALE can be disabled by

    14

  • 7/30/2019 Final Report Home Automation - ALL

    15/80

    setting SFR auxiliary.0. With this bit set, ALE will be active only during a

    MOVX instruction.

    EA (External Access Enable/Programming Supply Voltage):

    EA must be externally held low to enable the device to fetch code from

    external program memory locations. If EA is held high, the device executes from

    internal program memory. The value on the EA pin is latched when RST is

    released and any subsequent changes have no effect. This pin also receives the

    programming supply voltage (VPP) during Flash programming.

    RST (Reset):

    A high on this pin for two machine cycles while the oscillator is running

    resets the device. An internal resistor to VSS permits a power-on reset using only

    an external capacitor to VCC.

    PSEN (Program Store Enable):This is the pin to read strobe to external program memory. When executing

    code from the external program memory, PSEN is activated twice each machine

    cycle, except that two PSEN activations are skipped during each access to

    external data memory. PSEN is not activated during fetches from internal

    program memory.

    3.1.3.2.4 Memory organization

    The 8051 has two types of memory and these are Program Memory and

    Data Memory. Program Memory (ROM) is used to permanently save the program

    being executed, while Data Memory (RAM) is used for temporarily storing data

    and intermediate results created and used during the operation of the

    microcontroller. Depending on the model in use (we are still talking about the

    15

  • 7/30/2019 Final Report Home Automation - ALL

    16/80

    8051 microcontroller family in general) at most a few Kb of ROM and 128 or 256

    bytes of RAM is used. All 8051 microcontrollers have a 16-bit addressing bus

    and are capable of addressing 64 kb memory. It is neither a mistake nor a big

    ambition of engineers who were working on basic core development. It is a

    matter of smart memory organization which makes these microcontrollers a real

    programmers goody.

    3.1.3.2.5 Registers in 8051

    In the CPU, registers are used to store information temporarily. Thatinformation could be a byte of data to be processed, or an address pointing to the

    data to be fetched. The vast majority of 8051 registers are 8- bit registers. In the

    8051 there is only one data type: 8 bits. With an 8-bit data type, any data larger

    than 8 bits must be broken into 8- bit chunks before it is processed. The most

    widely used registers of the 8051 are A(Accumulator), B, and SPF (special

    function registers) and PSW (Program Status Word).

    A register is a general-purpose register used for storing intermediate results

    obtained during operation. Prior to executing an instruction upon any number or

    operand it is necessary to store it in the accumulator first. All results obtained

    from arithmetical operations performed by the ALU are stored in the

    accumulator. Data to be moved from one register to another must go through the

    accumulator. In other words, the A register is the most commonly used register

    and it is impossible to imagine a microcontroller without it. More than half

    instructions used by the 8051 microcontroller use somehow the accumulator.

    Multiplication and division can be performed only upon numbers stored in the A

    and B registers. All other instructions in the program can use this register as a

    spare accumulator (A).

    16

  • 7/30/2019 Final Report Home Automation - ALL

    17/80

    3.1.3.2.5.a R Registers (R0-R7)

    This is a common name for 8 general-purpose registers (R0, R1, R2 ...R7).

    Even though they are not true SFRs, they deserve to be discussed here because of

    their purpose. They occupy 4 banks within RAM. Similar to the accumulator,

    they are used for temporary storing variables and intermediate results during

    operation. Which one of these banks is to be active depends on two bits of the

    PSW Register. Active bank is a bank the registers of which are currently used.

    3.1.3.2.5.bSFR (Special Function Registers)

    Special Function Registers (SFRs) are a sort of control table used for

    running and monitoring the operation of the microcontroller. Each of these

    registers as well as each bit they include, has its name, address in the scope of

    RAM and precisely defined purpose such as timer control, interrupt control, serial

    communication control etc. Even though there are 128 memory locations

    intended to be occupied by them, the basic core, shared by all types of 8051

    microcontrollers, has only 21 such registers.

    3.1.3.2.5.c PROGRAM STATUS WORD (PSW):

    CY: Carry out from accumulator MSB of ALU operand

    AC: Auxiliary carry for BCD operations

    FO: General purpose

    RS1 & RS0: For register banks selection ( RB0-RB3)

    OV: Overflow flag

    17

  • 7/30/2019 Final Report Home Automation - ALL

    18/80

    P: Parity of accumulator set by hardware to 1 if it contains odd no of 1s.

    Carry flag:

    Carry flag is set whenever there is carry out from the MSB. This flag is

    after 8bit ADD/SUB operation. It can also be set to 1 or 0 directly using SETB C

    or CLR C.

    Auxiliary carry:

    If there is a carry from D3 to D4 position during Add/Sub

    operation, this bit will set. Otherwise, it is cleared. This flag is used for BCD

    operations.

    Parity flag reflects the number of 1s in A. If A contains an odd

    number of 1s, then P=1. Therefore P=0, if A has an even number of 1s.

    Overflow flag:

    This flag is set whenever the result of a signed number operation is too

    large to be accommodated in 7 bits, causing the higher order bit to overflow into

    the sign bit.

    3.1.3.2.6 Oscillator:

    The microcontroller used in this project, P89C51RD2FN requires a baud

    rate of 9600. To acquire this baud rate, an 11.0592 MHz crystal must be

    connected between 19th and 20th pins of controller. The determination of machine

    cycle frequency and Baud rate is as follows.

    MCF = (XTL freq / 12)

    = (11.0592 * 10^6) / 12 = 921.6 KHz

    Baud rate = MCF/32 = (921.6 10^3) / 32 = 28800 Hz

    Where MCF = Machine Cycle Frequency, XTL = Crystal18

  • 7/30/2019 Final Report Home Automation - ALL

    19/80

    To synchronize with timer1 (TH1) to set the baud rate as 9600 we need to

    set those register value as -3 (decimal) or FD (Hexadecimal) so as to divide the

    baud rate i.e.. 28800Hz should be dividing with the decimal value of TH1 to get

    9600 value.

    Fig 3.3: Oscillator Connections

    C1, C2 = 33pF.

    3.1.3.3 Features:

    80C51 Central Processing Unit

    Speed up to 20MHz with 6-clock cycles per machine cycle

    (40MHz equivalent performance), up to 33MHz with 12 clocks per

    machine cycle

    Four interrupt priority levels

    8-Bit program status word

    8 bit stack pointer

    Two 16 bit timer/counter T0 & T1

    Control registers TCON, TMOD and SCON, PCON and IP & IE

    oscillator & clock circuits.

    19

  • 7/30/2019 Final Report Home Automation - ALL

    20/80

    3.1.4 SERIAL COMMUNICATION

    3.1.4.1 Introduction

    In order to connect microcontroller to a modem or a pc to modem a serial

    port is used. Serial is a very common protocol for device communication that is

    standard on almost every PC. Most computers include two RS-232 based serial

    ports. Serial is also a common communication protocol that is used by many

    devices for instrumentation; numerous GPIB-compatible devices also come with

    an RS232 port. Furthermore, serial communication can be used for data

    acquisition in conjunction with a remote sampling device.

    Typically, serial is used to transmit ASCII data. Communication is

    completed using 3 transmission lines. (1) Ground, (2) Transmit and (3) Receive.

    Since serial is asynchronous, the port is able to transmit data on one line while

    receiving data on another. Other lines are available for handshaking, but are not

    required. The important serial characteristics are baud rate, data bits, stop bits,

    and parity. For two ports to communicate, these parameters much match.

    Serial communication is a popular means of transmitting data between a

    computer and a peripheral device such as a programmable instrument or even

    another one bit at a time, over a single communication line to a receiver. You can

    use this method when data transfer rates are low or you must transfer data over

    long distances. Serial communication is popular because most computers have

    one or more serial ports, so no extra hardware is needed other than a cable to

    connect the instrument to the computer or two computers together.

    Any device you connect to the serial port will need the serial transmission

    converted back to parallel so that it can be used. In serial communication, the data

    will be sent from one system to another in bit by bit notation. Serial Ports come in

    two sizes, there are the D-Type 25 pin connector and the D-Type 9 Pin

    connector both of which are male on the back of the PC, and thus you will require

    20

  • 7/30/2019 Final Report Home Automation - ALL

    21/80

    a female connector on your device. The RS-232 and RS-485 come under serial

    communication.

    3.1.4.2 Baud Rate:

    It is a speed measurement for communication. It indicates the number of

    bit transfers per second. For example, 300 baud is 300 bits per second. When a

    clock cycle is referred it means the baud rate. For example, if the protocol calls

    for a 4800 baud rate, then the clock is running at 4800Hz. This means that the

    serial port is sampling the data line at 4800Hz. Common baud rates for telephone

    lines are 12200, 28800 and 33600. Baud rates greater than these are possible, but

    these rates reduce the distance by which devices can be separated.

    3.1.5 HARDWARE DESIGN OF LCD

    The LCD (Liquid Crystal Display) used to display the output to the user in the

    form of GUI (Graphic User Interface) and a mono chromatic display. LCD used

    in this project is JHD162A series. There are 16 pins in all. They are numbered

    from left to right 1 to 16 (if you are reading from the backside). LCD shown

    above is marked to indicate which the 1st pin was and which the 16th was.

    In our project, we use a JHD162A LCD Display which has 2 rows and 16

    characters. It contains internal 1 byte latch. It has a better contrast and a wider

    viewing angle. These displays contain two internal byte-wide registers, one for

    command and second for characters to be displayed. There are three control

    signals called R/W, RS and EN. Select By making RS signal 0 you can send

    different commands to display. These commands are used to initialize LCD, to

    display pattern, to shift cursor or screen etc. You can see the markings right next

    to 1st and 16th pins. The 16x2 LCD with connections is as given below.

    21

  • 7/30/2019 Final Report Home Automation - ALL

    22/80

    Fig 3.4: Pin configuration of LCD

    3.1.5.1 LCD screen:-

    LCD screen consists of two lines with 16 characters each. Each character

    consists of 5x7 matrixes. Contrast on display depends on the power supply

    voltage and whether messages are displayed in one or two lines. For that reason,

    variable voltage 0-VDD is applied on pin marked as VEE. Trimmer potentiometer is

    usually used for that purpose. Some versions of displays have built in backlight

    (blue or green diodes). When used during operating, a resistor for current

    limitation should be used.

    The main control pins on JHD162A are data lines, read or write and enable.

    LCD is finding wide spread use replacing LEDs because of the following reasons:

    1. The ability to display numbers, characters and graphics. This is in contrast

    to LEDs, which are limited to numbers and a few characters.

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

    3. Ease of programming for characters and graphics.22

  • 7/30/2019 Final Report Home Automation - ALL

    23/80

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

    Fig 3.5: 16x2 LCD Display

    3.1.5.1.a Data lines (D0-D7):

    The data lines are connected to the parallel port of the microcontroller.

    These 8 lines are responsible for data and commands transfer depends upon RSpin. If RS = 0, then Command Register gets selected otherwise Data Register.

    3.1.5.1.b Read and write:

    Generally, we always use the LCD to show things on the screen. However,

    in some rare cases, we may need to read from the LCD what it is displaying. In

    such cases, the R/W pin is used. However, this function is beyond the scope of

    post and will not be explained. For all practical purposes, the R/W pin has to be

    permanently connected to GND.

    3.1.5.1.c Enable Pin:

    The enable pin has a very simple function. It is just the clock input for the

    LCD. The instruction or the character data at the data pins (D0-D7) is processed

    by the LCD on the falling edge of this pin. The Enable pin should be normally

    23

  • 7/30/2019 Final Report Home Automation - ALL

    24/80

    held at Vcc by a pull up resistor. When a momentary button switch is pressed, the

    Pin goes low and back to high again when you leave the switch. Your instruction

    or character will be executed on the falling edge of the pulse. (i.e. the moment the

    switch closes).

    3.1.5.1.d Register Select (RS) pin:

    The LCD has basically two operating modes:Instruction mode and

    Character Mode. Depending on the status of this pin, the data on the 8 data pins

    (D0-D7) is treated as either an instruction or as character data. You have to

    activate the command mode if you want to give an Instruction to the LCD. To set

    the LCD in Instruction mode, you set the 4th pin of the LCD (R/S) to GND. To

    put it in character mode, you connect it to Vcc.

    24

  • 7/30/2019 Final Report Home Automation - ALL

    25/80

    To start with LCD the user should initialize it first which should be programmed

    with its LCD commands. The LCD commands are given:

    25

  • 7/30/2019 Final Report Home Automation - ALL

    26/80

    CODE COMMANDS TO THE LCD

    1 Clear display screen

    2 Return home

    4 Shift cursor to left

    5 Shift display right

    6 Shift cursor to right

    7 Shift display left

    8 Display off, cursor off

    A Display off, cursor on

    C Display on, cursor off

    E Display on, cursor blinking

    F Display off, cursor blinking

    10 Shift cursor position to left

    14 Shift cursor position to right

    18 Shift entire display left

    1c Shift entire display right

    80 Force cursor to begin in 1st row

    C0 Force cursor to begin in 2nd row

    26

  • 7/30/2019 Final Report Home Automation - ALL

    27/80

    3.1.6 GSM MODULE:

    GSM/GPRS module is used to establish communication between a

    computer and a GSM-GPRS system. Global System for Mobile communication

    (GSM) is an architecture used for mobile communication in most of the countries.

    Global Packet Radio Service (GPRS) is an extension of GSM that enables higher

    data transmission rate. GSM/GPRS module consists of a GSM/GPRS modem

    assembled together with power supply circuit and communication interfaces (like

    RS-232, USB, etc) for computer. The MODEM is the soul of such modules.

    Fig 3.9: GSM/GPRS Module

    3.1.6.1 Wireless MODEMs:

    Wireless MODEMs are the MODEM devices that generate, transmit or

    decode data from a cellular network, for establishing communication between the

    cellular network and the computer. These are manufactured for specific cellular

    network (GSM/UMTS/CDMA) or specific cellular data standard

    (GSM/UMTS/GPRS/EDGE/HSDPA) or technology (GPS/SIM). Wireless

    27

  • 7/30/2019 Final Report Home Automation - ALL

    28/80

    MODEMs like other MODEM devices use serial communication to interface with

    and need Hayes compatible AT commands for communication with the computer

    (any microprocessor or microcontroller system).

    3.1.6.2 GSM/GPRS MODEM

    GSM/GPRS MODEM is a class of wireless MODEM devices that are

    designed for communication of a computer with the GSM and GPRS network. It

    requires a SIM (Subscriber Identity Module) card just like mobile phones to

    activate communication with the network. Also they have IMEI (International

    Mobile Equipment Identity) number similar to mobile phones for their

    identification. A GSM/GPRS MODEM can perform the following operations:

    1. Receive, send or delete SMS messages in a SIM.

    2. Read, add, search phonebook entries of the SIM.

    3. Make, Receive, or reject a voice call.

    The MODEM needs AT commands, for interacting with processor or

    controller, which are communicated through serial communication. These

    commands are sent by the controller/processor. The MODEM sends back a result

    after it receives a command. Different AT commands supported by the MODEM

    can be sent by the processor/controller/computer to interact with the GSM and

    GPRS cellular network.

    3.1.6.3 GSM/GPRS Module

    A GSM/GPRS module assembles a GSM/GPRS modem with standard

    communication interfaces like RS-232 (Serial Port), USB etc., so that it can be

    easily interfaced with a computer or a microprocessor / microcontroller based

    28

    http://www.engineersgarage.com/tutorials/at-commands
  • 7/30/2019 Final Report Home Automation - ALL

    29/80

    system. The power supply circuit is also built in the module that can be activated

    by using a suitable adaptor.

    Fig 3.11: GSM module

    3.1.6.4 Mobile Station (Cell phones and SIM)

    A mobile phone and Subscriber Identity Module (SIM) together form a

    mobile station. It is the user equipment that communicates with the mobile

    network. A mobile phone comprises of Mobile Termination, Terminal Equipment

    and Terminal Adapter.

    29

  • 7/30/2019 Final Report Home Automation - ALL

    30/80

    Mobile Termination is interfaced with the GSM mobile network and is

    controlled by a baseband processor. It handles access to SIM, speech encoding

    and decoding, signaling and other network related tasks. The Terminal Equipment

    is an application processor that deals with handling operations related to keypad,

    screen, phone memory and other hardware and software services embedded into

    the handset. The Terminal Adapter establishes communication between the

    Terminal Equipment and the Mobile Termination using AT commands. The

    communication with the network in a GSM/GPRS mobile is carried out by the

    baseband processor.

    3.1.6.5 Applications of GSM/GPRS module

    The GSM/GPRS module demonstrates the use of AT commands. They can

    feature all the functionalities of a mobile phone through computer like makingand receiving calls, SMS, MMS etc. These are mainly employed for computer

    based SMS and MMS services.

    3.1.6.6 AT Commands

    AT commands are used to control MODEMs. AT is the abbreviation for

    Attention. These commands come from Hayes commands that were used by the

    Hayes smart modems. The Hayes commands started with AT to indicate the

    attention from the MODEM. The dial up and wireless MODEMs (devices that

    involve machine to machine communication) need AT commands to interact with

    a computer. These include the Hayes command set as a subset, along with other

    extended AT commands.

    30

  • 7/30/2019 Final Report Home Automation - ALL

    31/80

    AT commands with a GSM/GPRS MODEM or mobile phone can be used to

    access following information and services:

    1. Information pertaining to mobile device or MODEM and SIM card.

    2. SMS services.

    3. MMS services.

    4. Fax services.

    5. Data and Voice link over mobile network.

    The Hayes subset commands are called the basic commands and the commands

    specific to a GSM network are called extended AT commands.

    3.1.6.7 Command, Information response and Result Codes:

    The AT commands are sent by the computer to the MODEM/ mobile phone. The

    MODEM sends back an Information Response i.e. the information requested by

    or pertaining to the action initiated by the AT command. This is followed by aResult Code. The result code tells about the successful execution of that

    command.

    31

  • 7/30/2019 Final Report Home Automation - ALL

    32/80

    There are also unsolicited Result Codes that are returned automatically by the

    MODEM to notify the occurrence of an event. For example the reception of a

    SMS will force MODEM to return an unsolicited result code.

    3.1.6.8 AT Commands Syntax

    Case Sensitivity -

    The AT commands are generally used in uppercase letters. However some

    MODEMs and mobile phones allow both uppercase and small case letters.

    Single Command -

    The AT commands include a prefix AT which indicates the beginning of the

    command to MODEM; and a carriage return which indicates the end of the

    command.

    Fig 3.12: AT Commands Syntax

    However string AT itself is not the part of the command. For example in ATD,

    D is the command name not ATD.

    32

  • 7/30/2019 Final Report Home Automation - ALL

    33/80

    The extended AT commands have a + in the command name.

    For example: AT+CGMI

    Command Line -

    Multiple AT commands can be sent to MODEM in a single command line. The

    commands in a line are separated by a semi-colon (;).

    For example: AT+CGMI; +CBS

    String in Command Line -

    Strings in a command line are enclosed in double quotes.

    For example: AT+CGML=ALL

    Information Response and Result Code

    The Information Response and Result Codes, returned by the MODEM, have a

    carriage return and line feed in the beginning as well as at the end.

    For example:

    33

  • 7/30/2019 Final Report Home Automation - ALL

    34/80

    OK

    ERROR

    Sequence of Execution -

    In the command line, the command appearing first is executed first. The

    execution then follows for second appeared command and so on. The execution

    of commands in a command line takes place in sequential manner.

    If an error occurs in the execution of a command, an error result code is returned

    by the MODEM and the execution of the command line is terminated irrespective

    of presence of other commands next in the command line.

    Types of commands:

    There are four types of AT commands:

    1) Test commands2) Read commands

    3) Set commands

    4) Execution commands

    For more details, see AT Commands.

    Different Result Codes:

    RESULT CODE DESCRIPTION

    OK Successful Execution of a command

    ERROR Execution of a command failed

    +CMS ERROR Message service failure, is returned with an error code

    Unsolicited Result Codes

    +CDS Notify receipt of SMS status report of a new message tocomputer

    34

  • 7/30/2019 Final Report Home Automation - ALL

    35/80

    +CDSI Notify receipt of SMS status report of a new message and its

    location in memory to computer

    +CMT Notify forwarding of a new SMS to computer

    +CMTI Notify receipt of SMS status report of a new message and its

    location in memory to computer

    Fig 3.10 Commands used in GSM

    3.1.6.9 Interfacing MODEM/Mobile phone with Windows platform

    The Windows (XP and lower versions) comes with an application called

    HyperTerminal for data communication through serial port of the computer. The

    interfacing of the GSM/GPRS module with the serial port of the computer

    involves following steps:

    1) Connect RS-232 port of GSM module with the serial port of the computer.

    Insert a SIM card in the module.

    2) Open HyperTerminal from Start -> All Programs -> Accessories ->

    Communications -> HyperTerminal.

    3) Enter a name for the connection and press OK.

    4) Now select the communication port (COM) at which GSM module is

    connected.

    5) Create a new connection set on HyperTerminal. Set parameters, like baud

    rate as 9600, handshaking mode as none, parity bit as none, stop bit as 1 and data

    bit as 8.

    3.1.7 MAX 232:

    35

    http://www.engineersgarage.com/tutorials/at-commands
  • 7/30/2019 Final Report Home Automation - ALL

    36/80

    Max232 IC is a specialized circuit which makes standard voltages as

    required by RS232 standards. This IC provides best noise rejection and very

    reliable against discharges and short circuits. MAX232 IC chips are commonly

    referred to as line drivers.

    To ensure data transfer between PC and microcontroller, the baud rate and

    voltage levels of Microcontroller and PC should be the same. The voltage levels

    of microcontroller are logic1 and logic 0 i.e., logic 1 is +5V and logic 0 is 0V.

    But for PC, RS232 voltage levels are considered and they are: logic 1 is taken as

    -3V to -25V and logic 0 as +3V to +25V. So, in order to equal these voltage

    levels, MAX232 IC is used. Thus this IC converts RS232 voltage levels to

    microcontroller voltage levels and vice versa.

    3.1.7.1 Pin Configuration:

    Fig 3.9: Pin diagram of MAX 232 IC

    36

  • 7/30/2019 Final Report Home Automation - ALL

    37/80

    3.1.8 RS 232(Female Port)

    RS-232 is the component which is used to connect system (pc) to

    microcontroller.

    RS-232 (Recommended Standard 232) is the traditional name for a series

    of standards for serial binary single-ended data and control signals connecting

    between a DTE (Data Terminal Equipment) and a DCE (Data Circuit-

    terminating Equipment). It is commonly used in computer serial ports. The

    standard defines the electrical characteristics and timing of signals, the meaning

    of signals, and the physical size and pin out of connectors.

    RS232 is limited to point-to-point connections between PC serial ports and

    devices. RS 232 hardware can be used for serial communication up to distances

    of 50 feet.

    3.1.8.1 Voltage levels:

    The RS-232 standard defines the voltage levels that correspond to logical

    one and logical zero levels for the data transmission and the control signal lines.For data transmission lines (TxD, RxD and their secondary channel

    equivalents) logic one is defined as a negative voltage, the signal condition is

    called marking, and has the functional significance. Logic zero is positive and the

    signal condition is termed spacing.

    Table 3.4: indicating voltage levels for DB 9 connector

    Logic level Voltage level

    1 -10V

    0 10V

    37

  • 7/30/2019 Final Report Home Automation - ALL

    38/80

    3.1.8.2 PIN CONFIGURATION

    Fig 3.10: DB9 Connector with pin out

    3.1.8.3 DB9 INTERFACING WITH MICROCONTROLLER USING MAX

    232:

    Fig 3.11:DB9 interfacing with microcontroller using MAX 232

    3.1.9 Serial port connector:

    The microcontroller is connected to the pc via a serial communication

    port. The serial communication port is a combination of a female port and a male

    38

  • 7/30/2019 Final Report Home Automation - ALL

    39/80

    port. The male port is connected to the DB-9 connector connected to the

    microcontroller while the female port is connected to the serial port of the pc.

    Fig 3.12: serial port connector

    3.1.10 Resistors:

    A resistor is a two-terminal passive electronic component that implements

    electrical resistance as a circuit element. When a voltage V is applied across the

    terminals of a resistor, a current I will flow through the resistor in direct

    proportion to that voltage. This constant of proportionality is called conductance,

    G. The reciprocal of the conductance is known as the resistance R, since, with a

    given voltage V, a larger value of R further "resists" the flow of current I as givenby Ohm's law:

    Fig 3.19: Resistors

    39

  • 7/30/2019 Final Report Home Automation - ALL

    40/80

    Practical resistors can be made of various compounds and films, as well as

    resistance wire (wire made of a high-resistivity alloy, such as nickel-chrome).

    Resistors are also implemented within integrated circuits, particularly analog

    devices, and can also be integrated into hybrid and printed circuits.

    3.1.11 Capacitors:

    A capacitor (formerly known as condenser) is a device for storing electric

    charge. Capacitors used as parts of electrical systems, for example, consist of

    metal foils separated by a layer of insulating film.

    A capacitor is a passive electronic component consisting of a pair of

    conductors separated by a dielectric (insulator). When there is a potential

    difference (voltage) across the conductors, a static electric field develops across

    the dielectric, causing positive charge to collect on one plate and negative charge

    on the other plate. Energy is stored in the electrostatic field. An ideal capacitor is

    characterized by a single constant value, capacitance, measured in farads. This is

    the ratio of the electric charge on each conductor to the potential difference

    between them.

    Fig 3.20: Capacitors

    Capacitors are widely used in electronic circuits for blocking direct current

    while allowing alternating current to pass, in filter networks, for smoothing the

    40

  • 7/30/2019 Final Report Home Automation - ALL

    41/80

    output of power supplies, in the resonant circuits that tune radios to particular

    frequencies and for many other purposes.

    C = Q/V

    3.1.12 Crystal oscillator:

    A crystal oscillator is an electronic oscillator circuit that uses the

    mechanical resonance of a vibrating crystal of piezoelectric material to create an

    electrical signal with a very precise frequency. This frequency is commonly used

    to keep track of time (as in quartz wristwatches), to provide a stable clock signal

    for digital integrated circuits, and to stabilize frequencies for radio transmitters

    and receivers. Most common type of piezoelectric resonator used is the Quartz

    Crystal, so oscillator circuits designed around them became known as "Crystal

    Oscillators."

    Fig 3.21: Crystal Oscillator

    Quartz crystals are manufactured for frequencies from a few tens of

    kilohertz to tens of megahertz. More than two billion (2109) crystals are

    manufactured annually. Most are used for consumer devices such as

    wristwatches, clocks, radios, computers, and cell phones. Quartz crystals are also

    found inside test and measurement equipment, such as counters, signal

    generators, and oscilloscopes.

    3.1.13 Power supply:

    41

  • 7/30/2019 Final Report Home Automation - ALL

    42/80

    In Power supply section, we use Step down transformer that steps down

    voltage from 220V to 0-12V. This supply is regulated by using 7805 which

    converts it into 5V constant supply. Then we can use this +5V supply as Vcc

    anywhere in our hardware.

    Parts:

    Transformer: It steps down 220V to 0-12V supply voltage.

    Full Bridge Rectifier : With diodes we can convert input 0-12V AC

    signal into DC signal. This circuit works as Rectifier.

    Capacitors : Capacitors are used for removing AC ripples so that the

    output will be purely DC.

    IC 7805 : This IC converts fluctuating or non-accurate input supply to

    Regulated and constant +5V.

    Fig 3.22 : Power Supply

    42

  • 7/30/2019 Final Report Home Automation - ALL

    43/80

    3.2 SOFTWARE DESIGN:

    3.2.1 Liquid Crystal Display

    3.2.1.1 Initializing the LCD

    Before you using the LCD, the program must initialize and configure it.

    This is accomplished by sending a number of initialization instructions to the

    LCD.

    The first instruction to send is the no of data for the LCD i.e., with an 8-

    bit or 4-bit data bus. The other thing need to specify is display matrix; in theselected LCD it is a 5x7 dot character font. These two options are selected by

    sending the command 38H to the LCD as a command. The command can give to

    the LCD by invoking the pre defined function call cmnd with passing parameters

    value of 38H, the syntax for the same can be given like cmnd (0x38).

    3.2.1.2 Writing command to the Display

    The function for commands to display on LCD is given below:

    void cmnd (unsigned char value)

    {

    P0 = value;

    Rs = 0;

    Rw = 0;

    En = 1;

    delay(1);

    en = 0;

    }

    43

  • 7/30/2019 Final Report Home Automation - ALL

    44/80

    We can call this function in the program like this:

    cmnd(0x38);

    cmnd(0x80);

    cmnd(0xC0);

    3.2.2 Flowchart for the Project

    Fig 3.25 Flow chart of GSM based Wireless Home Automation

    44

  • 7/30/2019 Final Report Home Automation - ALL

    45/80

    CHAPTER IV

    IMPLEMENTATION

    4.1 HARDWARE IMPLEMENTATION

    4.1.1 Schematic of GSM based Wireless Home Automation System

    Fig 4.1: Schematic of GSM based wireless home automation system

    45

  • 7/30/2019 Final Report Home Automation - ALL

    46/80

    4.1.2 Connections of AT89S52

    The pin configuration of AT89S52:-

    Fig 4.2: Pin diagram of AT89S52

    In this project the microcontroller is connected to MAX232, LCD, and GSM and

    Devices to be controlled.

    The connections of microcontroller are given briefly below:

    The reset pin is connected to the 9 th pin (RST) of AT89S52, as it is used

    for set reset the program.

    While the 10pin is connected to the 12th pin of MAX232.

    46

  • 7/30/2019 Final Report Home Automation - ALL

    47/80

    11th pin of controller is connected to the 11th pin of MAX232.

    The crystal oscillator which gives a frequency of 11.0592 MHz for the

    required Baud rate of 9600Hz to the microcontroller. This crystaloscillator is connected in between 18th (XALT 1) and 19th (XALT 2)

    pins of AT89S52 controller.

    The 20th pin of controller is Grounded.

    The pins from 32nd to 39th (Port 0) are used for the connections for data

    lines of LCD.

    Address Latch Enable pin (30th pin) of controller is connected to the

    ground hence no connections need not to be given to this pin.

    External Access pin (31st pin) must be connected to high i.e. VCC.

    4.1.3 Pin connections of LCD

    The 1st and 2nd pins of JHD162A LCD are connected to Ground and

    high voltage VCC respectively.

    3rd pin of LCD is connected to the centre pin of the Potentiometer or

    variable resistor so as to adjust the contrast of LCD.

    The 4th (RS) and 6th (EN) pins are connected to 1st (P1.0) and 2nd (P1.1)

    pins of the microcontroller respectively.

    The 5th pin (R/W) pin is connected to Ground as we have to write data

    on LCD.

    The 7th to 14th pins are data pins and are connected to the 39 th (P0.0) to

    32nd (P0.7) pins of the microcontroller respectively.

    47

  • 7/30/2019 Final Report Home Automation - ALL

    48/80

    The 15th and 16th pins are used for backlight purpose. 15th pin is

    connected to VCC and 16th pin to Ground.

    Fig 4.3: Connection of LCD with AT89S52.

    4.1.4 MAX232, DB9 AND GSM CONNECTION:

    MAX232 and DB9 connector plays a key role in program dumping and

    communication between project kits to the PC host.

    48

  • 7/30/2019 Final Report Home Automation - ALL

    49/80

    Capacitor C10 of capacitance 1Uf is connected across 1 st and 3rd pins of

    MAX232 and C9 of capacitance 1Uf is connected in between 4 th and 5th

    pins.

    Charge pump capacitors are required for the MAX232 to work it as voltage

    level shifter. The charge pump capacitors used here are C7 and C8 whose

    capacitance is 1Uf. C7 is connected between 6th pin and ground, while C8

    is connected across 2nd pin of MAX232 and Vcc.

    12th and 11th pins of MAX232 are connected to the 10 th and 11th pins of

    AT89S52 controller respectively. These acts as a transmitter and receiver

    for the data flow.

    To connect the MAX232 to the PC host we require a medium named as

    DB9 connector. The 2nd and 3rd pin of the DB9 connector should be

    connected to the 14th and 13th pins of MAX232 respectively. While the 5th

    pin is grounded.

    The GSM module is connected to the controller through the connections

    between the DB9 connectors already mounted on the controller and GSM

    modules.

    49

  • 7/30/2019 Final Report Home Automation - ALL

    50/80

    CHAPTER-V

    SOFTWARE IMPLEMENTATION

    5.1 JHD162A LCD INTERFACING

    5.1.1 Initializing the LCD

    The first instruction to send is the number of data for the LCD i.e., with an

    8-bit or 4-bit data bus. The other thing need to specify is display matrix; in the

    selected LCD it is a 5x7 dot character font. These two options are selected by

    sending the command 38H to the LCD as a command. The command can give to

    the LCD by invoking the pre defined function call cmnd with passing parameters

    value of 38H, the syntax for the same can be given like cmnd (0x38).

    5.1.2 The initialization sequence code can be given as follows:

    cmnd (0x38); // 2 lines and 5x7 matrix

    cmnd (0x01); // display on, cursor blinking

    cmnd (0x0E); //clear display screen

    cmnd (0x80); // force cursor to begging of 1st line

    5.1.3 Displaying the data into the LCD

    50

  • 7/30/2019 Final Report Home Automation - ALL

    51/80

    void show(unsigned char value)

    {

    P0 = value;

    Rs = 1;

    Rw = 0;

    En = 1;

    delay(1);

    en = 0;

    }

    5.1.4 Reading data to LCD

    void string(unsigned char *s)

    {

    While(*s != \0)

    {

    show(*s);

    s++;

    }

    }

    To use this function in main() is as follows:

    void main()

    {

    cmnd(0x80);

    string(System Instaling);

    }

    51

  • 7/30/2019 Final Report Home Automation - ALL

    52/80

    CHAPTER VI

    DEBUGGING TECHNIQUES

    6.1 Keil vision Debugger

    6.1.1 Introduction to Keil IDE

    Keil is a compiler that has 3 windows, project window, edit

    window, and build or command window Schematic. Today, Keil Software

    provides a broad range of development tools for the embedded systems

    marketplace. Their products include ANSIC compilers, macro assemblers,

    debuggers, linkers, library managers, and real-time operating systems.

    . It was then that Keil Software implemented the first C compiler designed

    from the ground-up specifically for the 89C51 microcontroller.

    6.1.2 Features

    1. Nine basic data types, including 32-bit IEEE floating-point.

    2. Flexible variable allocation with bit, data, bdata, idata, xdata, and pdata

    memory types.

    3. Interrupt functions may be written in C.

    4. Full use of the 8051 registers banks.

    5. Complete symbol and type information for source-level debugging.

    6. Bit-addressable data objects.

    7. Built-in interface for the RTX51 real-time kernel.

    8. Support for dual data pointers on Atmel, AMD, Cypress, Dallas

    semiconductor, Infineon, Philips, and Transcend microcontrollers.

    9. Support for Phillips 8xC510,8xC71,and 8xC752 limited instructionsets.

    52

  • 7/30/2019 Final Report Home Automation - ALL

    53/80

    The Keil 8051 Development Tools are designed to solve the complex

    problems facing embedded software developers.

    When starting a new project, simply select the microcontroller you use from

    the Device Database and the vision IDE sets all compiler, assembler, linker,

    and memory options for you.

    Numerous example programs are included to help you get started with most

    popular embedded 8051 devices.

    The Keil Vision Debugger accurately simulates on-chip peripherals (CAN,

    UART, SPI, Interrupts, I/O Ports, A/D Convertor, D/A convertor, and PWM

    Modules) of your 8051 device. Simulation helps you understand hardware

    configurations and avoids time wasted on setup problems. Additionally, with

    simulation, you can write and test applications before target hardware is

    available.

    When you are ready to begin testing your software application with target

    hardware, use the MON51, MONADI, or FlashMON51 Target Monitors, the

    ISD51 In-system Debugger, or the ULINK USB-JTAG Adapter to download

    and test program code on your target system.

    6.1.3 Steps to follow while writing a program in keil:

    1.Install Keil Micro Vision in your PC, Then after Click on that Keil Visionicon. After opening the window go to toolbar and select Project Tab then close

    previous project.

    2. Next select New Project from Project Tab.

    3. Then it will open Create New Project window. Select the path where you

    want to save project and edit project name.

    53

  • 7/30/2019 Final Report Home Automation - ALL

    54/80

    4. Next it opens Select Device for Target window, it shows list of companies

    and here you can select the device manufacturer company.

    5. For an example, for your project purpose you can select the chip as

    89c51rd2xx from Philips Group. Next Click OK Button, it appears empty

    window here you can observe left side a small window i.e., Project Window.

    Next create a new file.

    6. From the Main tool bar Menu select File Tab and go to New, then it will

    open a window, there you can edit the program.

    7. Here you can edit the program as which language will you prefer either

    Assembly or C.

    8. After editing the program save the file with extension as .c or .asm, if you

    write a program in Assembly Language save as .asm or if you write a

    program in C Language save as .c in the selected path.

    9. Then after saving the file, compile the program. For compilation go to project

    window select source group and right click on that and go to Add files to

    Group.

    10. Here it will ask which file has to add. For an example here you can add

    test.c as you saved before

    11. After adding the file, again go to Project Window and right click on your c

    file then select Build target for compilation. If there is any Errors or

    Warnings in your program you can check in Output Window that is shown

    bottom of the Keil window.

    12. Here in this step you can observe the output window for errors and warnings

    13. If you make any mistake in your program you can check in this slide for

    which error and where the error is by clicking on that error

    54

  • 7/30/2019 Final Report Home Automation - ALL

    55/80

    14. After compilation then next go to Debug Session. In Tool Bar menu, go to

    Debug tab and select Start/Stop Debug Session.

    15. Write a program for LEDs Blinking. LEDs are connected to PORT-1. You

    can observe the output in that port.

    16. To see the Ports and other Peripheral Features go to main toolbar menu and

    select peripherals.

    17. In this slide see the selected port i.e., PORT-1.

    18. Start to trace the program in sequence manner i.e., step by step execution and

    observe the output in port window

    19. After completion of Debug Session Create a .Hex file for Burning the

    Processor. Here to create a Hex file goes to project window and right click on

    Target next select Option for Target.

    20. It appears one window; here in target tab modify the crystal frequency as

    you connected to your microcontroller.

    21. Next go to Output tab. In that Output tab click on Create HEX File and

    then click OK.

    22. Finally Once again compile your program. The Created Hex File will appear

    in your path folder.

    55

  • 7/30/2019 Final Report Home Automation - ALL

    56/80

    APPENDICES

    KEIL MICRO VISION IDE

    Keil is a compiler that has 3 windows, project window, edit window, and build or

    command window Schematic. Today, Keil Software provides a broad range of

    development tools for the embedded systems marketplace. Their products include

    ANSIC compilers, macro assemblers, debuggers, linkers, library managers, and

    real-time operating systems.

    Steps to follow while writing a program in keil:

    1. Click on the Keil Vision Icon on Desktop.

    2. The following figure will appear.

    3. Click on the Project menu from the title bar.

    4. Then Click on New Project.

    56

  • 7/30/2019 Final Report Home Automation - ALL

    57/80

    5. Save the Project by typing suitable project name with no extension in

    your own folder.

    6. Then Click on Save button above.

    7. Select the component for your project. i.e. Atmel

    8. Click on the + Symbol beside of Atmel.

    57

  • 7/30/2019 Final Report Home Automation - ALL

    58/80

    9. Select AT89S52 as shown below.

    10. Then Click on OK.

    11. The Following figure will appear.

    58

  • 7/30/2019 Final Report Home Automation - ALL

    59/80

    12. Then Click either YES or NOmostly YES.

    13. Now your project is ready to USE.

    14. Now double click on the Target1, you would get another option Source

    group 1 as shown in next page.

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

    59

  • 7/30/2019 Final Report Home Automation - ALL

    60/80

    16. The next screen will be as shown in next page, and just maximize it by

    double clicking on its blue boarder.

    17. Now start writing program in either in EMBEDDED C or ASM.

    60

  • 7/30/2019 Final Report Home Automation - ALL

    61/80

    18. For a program written in Assembly, then save it with extension . asm

    and for EMBEDDED C based program save it with extension .C

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

    Source.

    61

  • 7/30/2019 Final Report Home Automation - ALL

    62/80

    20. Now you will get another window, on which by default EMBEDDED

    C files will appear.

    21. Now select as per your file extension given while saving the file

    22. Click only one time on option ADD.

    23. Now Press function key F7 to compile. Any error will appear if so

    happen.

    24. Now click on the Peripherals from menu bar, and check your required

    port as shown in figure below.

    62

  • 7/30/2019 Final Report Home Automation - ALL

    63/80

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

    26. Now keep Pressing function key F11 slowly and observe.

    27. You are running your program successfully.

    63

  • 7/30/2019 Final Report Home Automation - ALL

    64/80

    SETUP OF HYPERTERMINAL

    Go to:

    1. Start Menu>> Programs >> Accessories >> Communications >> Hyper

    Terminal

    After that HyperTerminal window will open. If it prompt for checking of default

    program as shown in fig, then say yes to it.

    2. Click Yes

    3. Type Connection Name as 8051 (or as per your Choice)

    64

  • 7/30/2019 Final Report Home Automation - ALL

    65/80

    4. Select COM PORT (1, 2, 3 etc) whichever is available. (NOTE: Very Less

    USB- TO Serial Converters as Reliable)

    So use Standard Serial Port

    65

  • 7/30/2019 Final Report Home Automation - ALL

    66/80

    5. Do Port Setting as Given Below.

    66

  • 7/30/2019 Final Report Home Automation - ALL

    67/80

    Then Click Apply and OK.

    6. Now you See Bottom Left side It shows Connected.

    7. Now burn the Hex File (Given) and Switch on the Circuit after Connecting

    Specified Serial Port .You will see output as Follows:

    67

  • 7/30/2019 Final Report Home Automation - ALL

    68/80

    If everything works fine you will see Hello World on the screen. Otherwise check

    your setup.

    68

  • 7/30/2019 Final Report Home Automation - ALL

    69/80

    GSM BASED HOME AUTOMATION SYSTEM

    /* Program used for Home automation */

    #include

    sbit rs = P1^0;

    sbit e = P1^1;

    sbit Green = P2^0;

    sbit Blue = P2^1;

    sbit Yellow = P2^2;

    sbit Red = P2^3;

    void delay(int time)

    {

    int i, j;for(i = 0; i > time; i++)

    for(j = 0; j < 1275; j++);

    }

    void cmnd(unsigned char g)

    {

    P0 = g;

    rs = 0;

    e = 1;

    delay(1);

    e = 0;

    }

    void show (unsigned char g)

    69

  • 7/30/2019 Final Report Home Automation - ALL

    70/80

    {

    P0 = g;

    rs = 0;

    e = 1;

    delay(1);

    e = 0;

    }

    void init ()

    {

    cmnd (0x38);

    cmnd (0x01);

    cmnd (0x0C);

    cmnd (0x80);

    }

    void string (unsigned char *s)

    {

    while (*s != '\0')

    {

    show (*s);

    s++;

    }

    }

    void serial_init()

    {

    TMOD = 0x20;

    SCON = 0x50;

    TH1 = 0xFD;

    70

  • 7/30/2019 Final Report Home Automation - ALL

    71/80

    TL1 = 0xFD;

    TR1 = 1;

    }

    void sendbyte(unsigned char y)

    {

    SBUF = y;

    while(TI == 0);

    TI = 0;

    }

    void receivebyte()

    {

    unsigned char c;

    while(RI == 0);

    RI = 0;

    c = SBUF;

    }

    void sendstring(unsigned char *str)

    {

    while(*str != '\0')

    {

    sendbyte(*str++);

    }

    }

    void Getline();

    void Send_sms();

    char Gps;

    71

  • 7/30/2019 Final Report Home Automation - ALL

    72/80

    unsigned char Num[10];

    unsigned char Disp[16];

    unsigned char Inmsg[100];

    void main()

    {

    P2 = 0xFF; //switch off all loads

    init();

    serial_init();

    string(SYSTEM INSTALING);

    init();

    string("Initializing");

    cmnd(0xC0);

    string("Modem plz wait..");

    delay(50);

    sendstring("AT");

    cmnd(0x01);

    string("AT OK");

    delay(50);

    sendstring("ATE0");

    cmnd(0x01);

    string("ECHO OK");

    delay(50);

    sendstring("AT+CREG?");

    delay(50);

    sendstring("AT+CNMI=2,0,2,0,0");

    72

  • 7/30/2019 Final Report Home Automation - ALL

    73/80

    cmnd(0x01);

    string("PHASE OK");

    delay(50);

    sendstring("AT+CMGF=1");

    cmnd(0x01);

    string("TEXT OK"); //change to Text mode

    delay(50);

    sendstring("AT+CMGD=1,4");

    delay(50); //Delete all sms

    cmnd(0x01);

    string("Waiting for SMS.");

    while(1)

    {

    sendstring("AT+CMGR=1"); //Read for message

    Getline();

    if (!Inmsg) //got new message

    {

    Num = ",";

    Gps = Instr(Inmsg , Num);

    Gps = Gps + 5;

    Num = Mid(Inmsg , Gps , 10); //extract the sender number

    Getline(); //get the message

    Inmsg = Lcase(inmsg);

    cmnd(0x01);

    string("1 Msg Received");

    cmnd(0xC0);

    73

  • 7/30/2019 Final Report Home Automation - ALL

    74/80

    string("from:");

    cmnd(0xC5);

    string(Num);

    delay(50);

    if (Inmsg = "Green on")

    {

    Green = 0;

    Inmsg = "Green LED ON";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    else if (Inmsg = "Green off")

    {

    Green = 1;

    Inmsg = "Green LED OFF";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    else if (Inmsg = "Blue on")

    {

    Blue = 0;

    Inmsg = "Blue LED ON";

    cmnd(0x01);

    string(Inmsg);

    74

  • 7/30/2019 Final Report Home Automation - ALL

    75/80

    Send_sms();

    }

    else if (Inmsg = "Blue off")

    {

    Blue = 1;

    Inmsg = "Blue LED OFF";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    else if (Inmsg = "Yellow on")

    {

    Yellow = 0;

    Inmsg = "Yellow LED ON";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    else if (Inmsg = "Yellow off")

    {

    Yellow = 1;

    Inmsg = "Yellow LED OFF";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    else if (Inmsg = "Red on")

    75

  • 7/30/2019 Final Report Home Automation - ALL

    76/80

    {

    Red = 0;

    Inmsg = "Red LED ON";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    else if (Inmsg = "Red off")

    {

    Red = 1;

    Inmsg = "Red LED OFF";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    else

    {

    Inmsg = "Invalid Command";

    cmnd(0x01);

    string(Inmsg);

    Send_sms();

    }

    }

    delay(25);

    sendstring("AT+CMGD=1,4"); //delete all sms

    delay(50);

    76

  • 7/30/2019 Final Report Home Automation - ALL

    77/80

    cmnd(0x01);

    string("Waiting for SMS.");

    delay(50);

    }

    }

    void Send_sms()

    {

    If (Num != "")

    {

    sendstring("AT+CMGS="); //send sms

    delay(50);

    sendstring(Inmsg);

    delay(50);

    }

    }

    void Getline()

    {

    Inmsg = "";

    while(1)

    {

    Gps = Inkey()

    If (Gps > 0)

    {

    switch(Gps)

    {

    Case 13 : If (Inmsg != "")

    break;

    77

  • 7/30/2019 Final Report Home Automation - ALL

    78/80

    Case 10 : If (Inmsg != "")

    break;

    Case else

    Inmsg = Inmsg + Chr(gps);

    }

    }

    }

    }

    78

  • 7/30/2019 Final Report Home Automation - ALL

    79/80

    REFERENCES

    Muhammad Ali Mazidi, 8051 micro controller and embedded systems, PHI

    Prentice hall India, Eastern Economy Edition, www.phindia.com.

    U.S. Shah, 8051Microcontroller and Embedded Systems.

    www.8051projects.info

    www.8051projects.net

    www.openstudy.com

    www.engineersgarage.com

    Wikipedia : http://en.wikipedia.org

    www.google.co.in

    Special Thanks to Mr. Narinder Kumar (Embex Technologies), Mr. Vinay

    Rathi (ZCC Networking Solution) and Ms. Vasu Nahoria (Infowiz) for their

    tremendous support and reference.

    79

  • 7/30/2019 Final Report Home Automation - ALL

    80/80

    http://www.phindia.com/http://www.8051projects.info/http://www.8051projects.net/http://www.openstudy.com/http://www.engineersgarage.com/http://en.wikipedia.org/wiki/Levelshttp://www.google.co.in/