thesis of major project

Upload: pradeep25061989

Post on 08-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Thesis of Major Project

    1/73

    1

    LOW BUDGET TRAINER KIT BASED ON MICROCONTROLLER 8051

    A thesis submitted to

    Chhattisgarh Swami Vivekanand Technical UniversityBhilai (India)

    For fulfillment of the award of degree

    BACHELOR OF ENGINEERING

    UNDER THE VENERANCE GUIDANCE OF

    Mr. T.V. DIXITBy

    ABHILAV VISHWAKARMA

    PRADEEP KUMAR SHRIVASTAV

    KRISHNA DEO PRASAD

    NIKHIL KUMAR THAKUR

    BACHELOR OF ENGINEERING

    2007-2011

  • 8/7/2019 Thesis of Major Project

    2/73

    2

    DECLARATION BY THE CANDIDATE

    I the undersigned solemnly declare that the report of the thesis work entitled

    Low Budget Trainer kit based on Microcontroller 8051 is based on our own work carried out during the

    course of our study under the supervision of Mr. T. V. Dixit.

    I assert that the statements made and conclusions drawn are an outcome of my research work. I further

    declare that to the best of my knowledge and belief the report does not contain any part of any work

    which has been submitted for the award of PhD degree or any other degree/diploma/certificate in this

    University or any other University of India or abroad.Abhilav Vishwakarma

    Enrollment No. AB7426

    Pradeep Kumar Shrivastava

    Enrollment No

    Krishna Deo Prasad

    Enrollment No

    Nikhil Kumar Thaku

    Enrollment No

  • 8/7/2019 Thesis of Major Project

    3/73

    3

    CERTIFICATE OF APPROVAL

    This is to certify that the project work entitled Development of a low budget trainer kit based on microcontroller

    8051, carried out by Mr. Abhilav Vishwakarma, Mr. Pradeep Kumar Srivastav, Mr. Nikhil Kumar Thakur &

    Mr. Krishna Deo Prasad under my guidance and supervision for the award of the degree in Bachelor of

    Engineering in the discipline Electrical & Electronics Engineering from Bhilai Institute Of Technology Durg ,

    Chhattisgarh Swami Vivekanand Technical University Bhilai (C.G.), India

    To the best of my knowledge and belief, the project work-

    1. Embodies the work of candidates.

    2. Has duly been completed in specified time.

    3. Fulfills the requirement of the B.E. Degree of the university.

    4. It has creditable work for the award of B.E. degree.

    5. Is up to the standard in respect of content and language.

    Signature of HOD Signature of Guide

    INTERNAL EXAMINER EXTERNAL EXAMINER

    DEPATMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING

    BHILAI INSTITUTE OF TECHNOLOGY

    DURG (C.G.), INDIA

  • 8/7/2019 Thesis of Major Project

    4/73

    4

    ACKNOWLEDGEMENT

    This project is the product of ample amount of inspiration, support, guidance, coordination and facilities that were

    extended to us by people at every level. I was Indebted to each one of them.

    I wish to acknowledge my profound sense of gratitude to my project guide, Associate Professor Mr. T.V.

    Dixit(Electrical and Electronics Engineering), for his remarkable guidance and support during the entire course of

    project. It was a matter of great honor and privilege to have him as our project guide.

  • 8/7/2019 Thesis of Major Project

    5/73

    5

    WHY A PROJECT

    A technical student in his education period has to perform various experiments and research work on the subjects

    which are being taught to him in the course of his studies. The organization of all these efforts with a definite

    purpose to deal and stay with the problems longer is called a PROJECT.

    The object of project is to involve technical thinking and inducing the students to make an ordinary analysis of

    situations to search a definite solution.

    By doing a project student displays his spirit of inquiring and developing criticizing ways of problem solving by

    understanding the existing situations, independent thinking and ability to understand the basic facts.

  • 8/7/2019 Thesis of Major Project

    6/73

    6

    CONTENT

    1. Introduction to the project

    2. Microcontroller 8051

    2.1 Special Features

    2.2 The 8051 microcontroller architecture

    2.3 Pin diagram

    2.4 Oscillator circuit

    2.5 Types of memory

    2.6 Special function registers and Programming tips

    3. Serial communication in 8051

    3.1 Setting the serial port mode

    3.2 Baud rate

    3.3 Setting the serial port baud rate

    3.4 Writing the serial port

    3.5 Reading the serial port

    3.6 Working in serial communication mode

    3.6.1 RS 232 Standard

    3.6.2 Pin Outs

    3.6.3 UART (Universal Asynchronous Receiver Transmitter)

    4. In system programming

    5. Circuit diagram

    6. List of Components and ICs

    7. Detailed Specification of each component

    7.1 Microcontroller IC

    7.1.1 General Description

    7.1.2 Features

    7.2 MAX 232 driver/ RS 232 devices

    7.2.1 Cables

  • 8/7/2019 Thesis of Major Project

    7/73

    7

    7.2.2 2 wire and 5 wire RS 232

    7.2.3 Conventions

    7.2.4 Development tools

    7.3 Supply voltage

    7.3.1 General description

    7.3.2 Features

    7.4 DM74LS125A Quad 3 state buffer

    7.4.1 General description

    7.4.2 Connection

    7.4.3 Connection table

    7.5 L293D- Motor driver

    7.5.1 Features

    7.6 ULN2803- 8 darlington array

    7.6.1 Features

    7.6.2 Description

    7.6.3 Pin Diagram

    7.7 ADC 0804- 8 bit A/D converter

    7.7.1 General description

    7.7.2 Features

    7.7.3 Key specification

    7.7.4 Block diagram

    7.8 LM35 Precision centigrade temperature sensor

    7.8.1 General description

    7.8.2 Features

    7.8.3 Pin configuration

    7.9 16*2 LCD display

    7.9.1 Testing

    7.9.2 Library summary

  • 8/7/2019 Thesis of Major Project

    8/73

    8

    7.9.3 The circuit

    8. Interfacing

    8.1 Digital interfacing

    8.1.1 Keyboard interfacing

    8.1.2 LED interfacing

    8.1.3 ADC 0804 interfacing

    8.1.4 LM35 Interfacing and display using 7 segment display

    8.1.5 16*2 LCD interfacing

    8.1.6 RS 232 Interfacing using max 232

    8.1.7 1 wire interface

    8.1.8 Relay interfacing using ULN2803

    8.2 Analog interfacing

    9. Printed Circuit Board

    9.1 Manufacturing process

    9.2 Types of PCBs

    9.2.1 Single sided PCB

    9.2.2 Double sided PCB

    9.3 Design specification

    9.4 PCB layout of our project

    10. Software description

    11. Future Expansion

    12. Bibliography

  • 8/7/2019 Thesis of Major Project

    9/73

  • 8/7/2019 Thesis of Major Project

    10/73

    10

    2. MICROCONTROLLER 8051

    A micro-controller can be compared to a small stand alone computer; it is a very powerful device, which is capable of

    executing a series of pre-programmed tasks and interacting with other hardware devices. Being packed in a tiny integrated

    circuit (IC) whose size and weight is usually negligible, it is becoming the perfect controller for robots or any machines

    requiring some kind of intelligent automation. Any microcontroller contains a memory to store the program to be

    executed, and a number of input/output lines that can be used to interact with other devices, like reading the state of a

    sensor or controlling a motor.

    Nowadays, microcontrollers are so cheap and easily available that it is common to use them instead of simple logic

    circuits like counters for the sole purpose of gaining some design flexibility. Most recent microcontrollers are 'In System

    Programmable', meaning that you can modify the program being executed, without removing the microcontroller from its

    place.

    Today, microcontrollers are an indispensable tool for the robotics hobbyist as well as for the engineer.

    2.1 SPECIAL FEATURES

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

    y 64 KB on chip program memory.

    y 128 bytes on chip data memory(RAM).

    y 4 register banks.

    y 128 user defined software flags.

    y 8-bit data bus

    y 16-bit address bus

    y 32 general purpose registers each of 8 bits

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

    y 3 internal and 2 external interrupts.

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

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

    y 16-bit program counter and data pointer.

    y 1 Microsecond instruction cycle with 12 MHz Crystal.

    y Built in UART (Universal Asynchronous receiver transmitter) for serial communication.

  • 8/7/2019 Thesis of Major Project

    11/73

    11

    2.2 THE 8051 MICROCONTROLLER ARCHITECTURE

    The 8051 is the name of a big family of microcontrollers. The device which we are going to use along this tutorial is the

    'P89V51RD2'which is a typical 8051 microcontroller manufactured by Philips. A simpler architecture can be represented

    as in the figure.

    The figure shows the main features and components that the designer can interact with. You can notice that the 89V51 has

    4 different ports, each one having 8 Input/output lines providing a total of 32 I/O lines. Those ports can be used to output

    DATA and orders to other devices, or to read the state of a sensor, or a switch. Most of the ports of the 89V51 have 'dual

    function' meaning that they can be used for two different functions: the first one is to perform input/output operations and

    the second one is used to implement special features of the microcontroller like counting external pulses, interrupting the

    execution of the program according to external events, performing serial data transfer or connecting the chip to a

    computer to update the software.

  • 8/7/2019 Thesis of Major Project

    12/73

    12

    Each port has 8 pins, and will be treated from the software point of view as an 8-bit variable called 'register', each bit

    being connected to a different Input/output pin.

    Port 0 can also be used to provide the lower 8 bit address and 8 bit data.

    Port 2 provides the upper 8 bit address and when used with port 0, it provides 16 bit address.

    Each pin of port 3 is assigned a special function besides being used as I/O lines. This port plays a very important

    role from communication point of view. It controls transferring and receiving of signals, handle interrupts and

    performs read and write operation.

    You can also notice two different memory types: RAM and EEPROM. Shortly, RAM is used to store variable during

    program execution, while the EEPROM memory is used to store the program itself, that's why it is often referred to as the

    'program memory.

    It is just important to note that the 89V51 incorporates hardware circuits that can be used to prevent the processor from

    executing various repetitive tasks and save processing power for more complex calculations. Those simple tasks can be

    counting the number of external pulses on a pin, or generating precise timing sequences.

    It is clear that the CPU (Central Processing Unit) is the heart of the microcontrollers; it is the CPU that will Read the

    program from the FLASH memory and execute it by interacting with the different peripherals.

  • 8/7/2019 Thesis of Major Project

    13/73

    13

    2.3 PIN DIAGRAM

    Figure shows the pin configuration of the 89V51, where the function of each pin is written next to it, and, if it exists, the

    dual function is written between brackets. The pins are written in the same order as in the block diagram of figure A,

    except for the VCC and GND pins which is usually note at the top and the bottom of any device.

    Note that the pin that has dual function can still be used normally as an input/output pin. Unless your program uses their

    dual functions, all the 32 I/O pins of the microcontroller are configured as input/output pins.

    Pin 31 (External access) always connected to VCC (5 Volts) to enable the micro-controller to use the internal on chipmemory rather than an external one (connecting the pin 31 to ground would indicate to the microcontroller that an

    external memory is to be used instead of the internal one).

  • 8/7/2019 Thesis of Major Project

    14/73

    14

    2.4 OSCILLATOR CIRCUIT

    The 8051 requires the existence of an external oscillator circuit. The oscillator circuit usually runs around 12MHz,

    although the 8051 (depending on which specific model) is capable of running at a maximum of 40MHz. Each machine

    cycle in the 8051 is 12 clock cycles, giving an effective cycle rate at 1MHz (for a 12MHz clock) to 3.33MHz (for the

    maximum 40MHz clock).

    Reset CircuitRESET is an active High input When RESET is set to High,8051 goes back to the power on state.The 8051 is reset by holding the RST high for at least twomachine cycles and then returning it low.

    Power-On Reset

    - Initially charging of capacitor makes RST High

    - When capacitor charges fully it blocks DC.

    Manual reset

    -closing the switch momentarily will make RST High.

    After a reset, the program counter is loaded with 0000H but the content of on-chip RAM is not affected.

  • 8/7/2019 Thesis of Major Project

    15/73

    15

    2.5 TYPES OF MEMORY

    The 8051 has three very general types of memory. To effectively program the 8051 it is necessary to have a basic

    understanding of these memory types. They are: On-Chip Memory, External Code Memory, and External RAM.

    On-Chip Memory refers to any memory (Code, RAM, or other) that physically exists on the microcontroller itself.

    External Code Memory is code (or program) memory that resides off-chip. This is often in the form of an external

    EPROM.

    External RAM is RAM memory that resides off-chip. This is often in the form of standard static RAM or flash RAM.

    Code Memory is the memory that holds the actual 8051 program that is to be run. This memory is limited to 64K: Code

    memory may be found on-chip, either burned into the microcontroller as ROM or EPROM. Code may also be stored

    completely off-chip in an external ROM or, more commonly, an external EPROM. Flash RAM is also another popular

    method of storing a program. Various combinations of these memory types may also be used--that is to say, it is possible

    to have 4K of code memory on-chip and 64k of code memory off-chip in an EPROM.

    When the program is stored on-chip the 64K maximum is often reduced to 4k, 8k, or 16k. This varies depending on the

    version of the chip that is being used. Each version offers specific capabilities and one of the distinguishing factors from

    chip to chip is how much ROM/EPROM space the chip has.

    However, code memory is most commonly implemented as off-chip EPROM. This is especially true in low-cost

    development systems and in systems developed by students.

    Programming Tip: Since code memory is restricted to 64K, 8051 programs are limited to 64K. Some assemblers and

    compilers offer ways to get around this limit when used with specially wired hardware. However, without such special

    compilers and hardware, programs are limited to 64K.

    External RAM as an obvious opposite ofInternalRAM, the 8051 also supports what is called ExternalRAM. As the

    name suggests, External RAM is any random access memory which is found off-chip. Since the memory is off-chip it is

    not as flexible in terms of accessing, and is also slower. For example, to increment an Internal RAM location by 1 requires

    only 1 instruction and 1 instruction cycle. To increment a 1-byte value stored in External RAM requires 4 instructions and

    7 instruction cycles. In this case, external memory is 7 times slower!

    What External RAM loses in speed and flexibility it gains in quantity, while Internal RAM is limited to 128 bytes (256

    bytes with an 8052), the 8051 supports External RAM up to 64KB.

    On-Chip Memory

    On-chip memory is really one of two types: Internal RAM and Special Function Register (SFR) memory.

    The 8051 has a bank of 128 bytes ofInternalRAM. This Internal RAM is found on-chip on the 8051 so it is the fastest

    RAM available, and it is also the most flexible in terms of reading, writing, and modifying its contents. Internal RAM is

    volatile, so when the 8051 is reset this memory is cleared.

    The 128 bytes of internal ram is subdivided into 4 register banks. The first 8 bytes (00h - 07h) are "register bank 0". By

    manipulating certain SFRs, a program may choose to use register banks 1, 2, or 3. These alternative register banks are

    located in internal RAM in addresses 08h through 1Fh. Bit Memory also lives and is part of internal RAM. Bit memory

    actually resides in internal RAM, from addresses 20h through 2Fh.

  • 8/7/2019 Thesis of Major Project

    16/73

    16

    The 80 bytes remaining of Internal RAM, from addresses 30h through 7Fh, may be used by user variables that need to be

    accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating

    stack.

    Register Banks

    The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers are numbered from 0

    through 7 (R0, R1, R2, R3, R4, R5, R6, and R7). These registers are generally used to assist in manipulating values and

    moving data from one memory location to another. For example, to add the value of R4 to the Accumulator, we would

    execute the following instruction:

    ADD A,R4

    Thus if the Accumulator (A) contained the value 6 and R4 contained the value 3, the Accumulator would contain the

    value 9 after this instruction was executed.

    Bit Memory

    The 8051is a communication oriented microcontroller. It gives the user the ability to access a number ofbit variables.

    These variables may be either 1 or 0.

    There are 128 bit variables available to the user, numbered 00h to7Fh. The user may make use of these variables with

    commands such as SETB and CLR.

    Special Function Register (SFR) Memory

    Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor. For

    example, four SFRs permit access to the 8051s 32 input/output lines. Another SFR allows a program to read or write to

    the 8051s serial port. Other SFRs allow the user to set the serial baud rate, control and access timers, and configure the

    8051s interrupt system.

    2.6SPECIAL FUNCTION REGISTERS AND PROGRAMMING TIPS

    What Are SFRs?

    The 8051 is a flexible microcontroller with a relatively large number of modes of operations. Your program may inspect

    and/or change the operating mode of the 8051 by manipulating the values of the 8051's Special Function Registers

    (SFRs).

    SFRs are accessed as if they were normal Internal RAM. The only difference is that Internal RAM is from address 00h

    through 7Fh whereas SFR registers exist in the address range of 80h to 0FFh.

    Each SFR has an address (80h to FFh) and a name. The following chart provides a graphical presentation of the 8051's

    SFRs, their names, and their address.

  • 8/7/2019 Thesis of Major Project

    17/73

    17

    As you can see, although the address range of 80h to 0FFh offers 128 possible addresses, there are only 21 SFRs in a

    standard 8051. All other addresses in the SFR range (80h to 0FFh) are considered invalid. Writing to or reading from

    these registers may produce undefined values or behavior.

    Programming Tip: It is recommended that you not read or write to SFR addresses that have not been assigned to an SFR

    Doing so may provoke undefined behavior and may cause your program to be incompatible with other 8051-derivatives

    that use the given SFR for some other purpose.

    SFR Types

    As mentioned in the chart itself, the SFRs that have a blue background are SFRs related to the I/O ports. The 8051 has

    four I/O ports of 8 bits, for a total of 32 I/O lines. Whether a given I/O line is high or low and the value read from the line

    are controlled by the SFRs in green.

    The SFRs with yellow backgrounds are SFRs which in some way control the operation or the configuration of some

    aspect of the 8051. For example, TCON controls the timers, SCON controls the serial port.

    The remaining SFRs, with green backgrounds, are "other SFRs." These SFRs can be thought of as auxillary SFRs in the

    sense that they don't directly configure the 8051 but obviously the 8051 cannot operate without them. For example, once

    the serial port has been configured using SCON, the program may read or write to the serial port using the SBUF register.

    Programming Tip: The SFRs whose names appear in red in the chart above are SFRs that may be accessed via bit

    operations (i.e., using the SETB and CLRinstructions). The other SFRs cannot be accessed using bit operations. As you

    can see, all SFRs that whose addresses are divisible by 8 can be accessed with bit operations.

    SFR Descriptions: This section will endeavor to quickly overview each of the standard SFRs found in the above SFR

    chart map. This section is to just give you a general idea of what each SFR does.

  • 8/7/2019 Thesis of Major Project

    18/73

    18

    P0 (Port 0, Address 80h, Bit-Addressable): This is input/output port 0. Each bit of this SFR corresponds to one of the

    pins on the microcontroller.

    Programming Tip: While the 8051 has four I/O port (P0, P1, P2, and P3), if your hardware uses external RAM or

    external code memory (i.e., your program is stored in an external ROM or EPROM chip or if you are using external RAM

    chips) you may not use P0 or P2. This is because the 8051 uses ports P0 and P2 to address the external memory. Thus if

    you are using external RAM or code memory you may only use ports P1 and P3 for your own use.

    SP (Stack Pointer, Address 81h): This is the stack pointer of the microcontroller. This SFR indicates where the next

    value to be taken from the stack will be read from an Internal RAM. If you push a value onto the stack, the value will be

    written to the address of SP + 1. This SFR is modified by all instructions which modify the stack, such as PUSH, POP,

    LCALL, RET, RETI, and whenever interrupts are provoked by the microcontroller.

    Programming Tip: The SP SFR, on startup, is initialized to 07h. This means the stack will start at 08h and start

    expanding upward in internal RAM. Since alternate register banks 1, 2, and 3 as well as the user bit variables occupy

    internal RAM from addresses 08h to 2Fh, it is necessary to initialize SP in your program to some other value if you will

    be using the alternate register banks and/or bit memory. It's not a bad idea to initialize SP to 2Fh as the first instruction of

    every one of your programs unless you are 100% sure you will not be using the register banks and bit variables.

    DPL/DPH (Data Pointer Low/High, Addresses 82h/83h): The SFRs DPL and DPH work together to represent a 16-bit

    value called the Data Pointer. The data pointer is used in operations regarding external RAM and some instructions

    involving code memory.

    Programming Tip: DPTR is really DPH and DPL taken together as a 16-bit value. In reality, you almost always have to

    deal with DPTR one byte at a time. For example, to push DPTR onto the stack you must first push DPL and then DPH.

    You can't simply plush DPTR onto the stack. Additionally, there is an instruction to "increment DPTR." When you

    execute this instruction, the two bytes are operated upon as a 16-bit value. However, there is no instruction that

    decrements DPTR. If you wish to decrement the value of DPTR, you must write your own code to do so.

    PCON (Power Control, Addresses 87h): The Power Control SFR is used to control the 8051's power control modes.

    Certain operation modes of the 8051 allow the 8051 to go into a type of "sleep" mode which requires much less power.

    These modes of operation are controlled through PCON. Additionally, one of the bits in PCON is used to double the

    effective baud rate of the 8051's serial port.

    TCON (Timer Control, Addresses 88h, Bit-Addressable): The Timer Control SFR is used to configure and modify the

    way in which the 8051's two timers operate. This SFR controls whether each of the two timers is running or stopped and

    contains a flag to indicate that each timer has overflowed. Additionally, some non-timer related bits are located in the

    TCON SFR. These bits are used to configure the way in which the external interrupts are activated and also contain the

    external interrupt flags which are set when an external interrupt has occurred.

    TMOD (Timer Mode, Addresses 89h): The Timer Mode SFR is used to configure the mode of operation of each of the

    two timers. Using this SFR your program may configure each timer to be a 16-bit timer, an 8-bit auto reload timer, a 13-

    bit timer, or two separate timers. Additionally, you may configure the timers to only count when an external pin is

    activated or to count "events" that are indicated on an external pin.

  • 8/7/2019 Thesis of Major Project

    19/73

    19

    TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Ch): These two SFRs, taken together, represent timer 0. Their exact

    behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is

    configurable is how and when they increment in value.

    TL1/TH1 (Timer 1 Low/High, Addresses 8Bh/8Dh): These two SFRs, taken together, represent timer 1. Their exact

    behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is

    configurable is how and when they increment in value.

    P1 (Port 1, Address 90h, Bit-Addressable): This is input/output port 1. Each bit of this SFR corresponds to one of the

    pins on the microcontroller. For example, bit 0 of port 1 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this

    SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level.

    SCON (Serial Control, Addresses 98h, Bit-Addressable): The Serial Control SFR is used to configure the behavior of

    the 8051's on-board serial port. This SFR controls the baud rate of the serial port, whether the serial port is activated to

    receive data, and also contains flags that are set when a byte is successfully sent or received.

    Programming Tip: To use the 8051's on-board serial port, it is generally necessary to initialize the following SFRs:

    SCON, TCON, and TMOD. This is because SCON controls the serial port. However, in most cases the program will wish

    to use one of the timers to establish the serial port's baud rate. In this case, it is necessary to configure timer 1 by

    initializing TCON and TMOD.

    SBUF (Serial Control, Addresses 99h): The Serial Buffer SFR is used to send and receive data via the on-board serial

    port. Any value written to SBUF will be sent out the serial port's TXD pin. Likewise, any value which the 8051 receives

    via the serial port's RXD pin will be delivered to the user program via SBUF. In other words, SBUF serves as the output

    port when written to and as an input port when read from.

    P2 (Port 2, Address A0h, Bit-Addressable): This is input/output port 2. Each bit of this SFR corresponds to one of the

    pins on the microcontroller. For example, bit 0 of port 2 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this

    SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level.

    Programming Tip: While the 8051 has four I/O port (P0, P1, P2, and P3), if your hardware uses external RAM or

    external code memory (i.e., your program is stored in an external ROM or EPROM chip or if you are using external RAM

    chips) you may not use P0 or P2. This is because the 8051 uses ports P0 and P2 to address the external memory. Thus if

    you are using external RAM or code memory you may only use ports P1 and P3 for your own use.

    IE (Interrupt Enable, Addresses A8h): The Interrupt Enable SFR is used to enable and disable specific interrupts. The

    low 7 bits of the SFR are used to enable/disable the specific interrupts, where as the highest bit is used to enable or disable

    ALL interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of whether an individual interrupt is

    enabled by setting a lower bit.

    P3 (Port 3, Address B0h, Bit-Addressable): This is input/output port 3. Each bit of this SFR corresponds to one of the

    pins on the microcontroller. For example, bit 0 of port 3 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this

    SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level.

  • 8/7/2019 Thesis of Major Project

    20/73

    20

    IP (Interrupt Priority, Addresses B8h, Bit-Addressable): The Interrupt Priority SFR is used to specify the relative

    priority of each interrupt. On the 8051, an interrupt may either be of low (0) priority or high (1) priority. An interrupt may

    only interrupt interrupts of lower priority.

    PSW (Program Status Word, Addresses D0h, Bit-Addressable): The Program Status Word is used to store a number

    of important bits that are set and cleared by 8051 instructions. The PSW SFR contains the carry flag, the auxiliary carry

    flag, the overflow flag, and the parity flag. Additionally, the PSW register contains the register bank select flags which are

    used to select which of the "R" register banks are currently selected.

    Programming Tip: If you write an interrupt handler routine, it is a very good idea to always save the PSW SFR on the

    stack and restore it when your interrupt is complete. Many 8051 instructions modify the bits of PSW. If your interrupt

    routine does not guarantee that PSW is the same upon exit as it was upon entry, your program is bound to behave rather

    erradically and unpredictably--and it will be tricky to debug since the behavior will tend not to make any sense.

    ACC (Accumulator, Addresses E0h, Bit-Addressable): The Accumulator is one of the most-used SFRs on the 8051

    since it is involved in so many instructions. The Accumulator resides as an SFR at E0h, which means the instruction

    MOV A,#20h is really the same as MOV E0h,#20h. However, it is a good idea to use the first method since it only

    requires two bytes whereas the second option requires three bytes.

    B (B Register, Addresses F0h, Bit-Addressable): The "B" register is used in two instructions: the multiply and divide

    operations. The B register is also commonly used by programmers as an auxiliary register to temporarily store values.

  • 8/7/2019 Thesis of Major Project

    21/73

    21

    3. SERIAL COMMUNICATION IN 8051

    When a microprocessor communicates with the outside world, it provides data in byte sized chunks. In some cases, such

    as printers, the information is simply grabbed from the 8 bit data bus and presented to the 8 bit data bus of the printer.

    This can work only if the cable is not too long, since long cables diminish and even distort signals. Furthermore an 8 bit

    data path is expensive. For these reasons, serial communication is used for transferring data between two systems located

    at distance of hundreds of feet to millions of miles apart.

    The fact that serial communication uses a single data line instead of the 8bit data line of parallel communication not

    only makes it cheaperbut also enables two computers located at different cities to communicate over the telephone.

    For SERIAL DATA COMMUNICATION to work the byte of data must be converted to parallel in serial out shift

    register; then it can be transmitted over a single data line. This allows us to have a serial in parallel out shift register at the

    receiving end to pack them into byte.

    Serial data communication uses two methods, asynchronous and synchronous. The synchronous method transfers a block

    of data (characters) at a time, while the asynchronous method transfers a single byte at a time. It is possible to write

    software to use either of these methods, but the method can be tedious and long. For this reason, there are specialICchips

    made by many manufacturers forserial communication of data. These chips are commonly referred to as UART

    (universal asynchronous receiver transmitter) and USART (universalsynchronous- asynchronous receiver transmitter).

    One of the 8051s many powerful features is its integrated UART, otherwise known as a serial port. The fact that the 8051

    has an integrated serial port means that you may very easily read and write values to the serial port. If it were not for the

    integrated serial port, writing a byte to a serial line would be a rather tedious process requiring turning on and off one of

    the I/O lines in rapid succession to properly "clock out" each individual bit, including start bits, stop bits, and parity bits.

    However, we do not have to do this. Instead, we simply need to configure the serial ports operation mode and baud rate.

    Once configured, all we have to do is write to an SFR to write a value to the serial port or read the same SFR to read a

    value from the serial port. The 8051 will automatically let us know when it has finished sending the character we wrote

    and will also let us know whenever it has received a byte so that we can process it. We do not have to worry about

    transmission at the bit level--which saves us quite a bit of coding and processing time.

  • 8/7/2019 Thesis of Major Project

    22/73

    22

    3.1 SETTING THE SERIAL PORT MODE

    The first thing we must do when using the 8051s integrated serial port is, obviously, configure it. This lets us tell the 8051

    how many data bits we want, the baud rate we will be using, and how the baud rate will be determined. First, lets present

    the "Serial Control" (SCON) SFR and define what each bit of the SFR represents:

    Bit Name Bit Address Explanation of Function

    7 SM0 9Fh Serial port mode bit 0

    6 SM1 9Eh Serial port mode bit 1.

    5 SM2 9Dh Multiprocessor Communications Enable (explained later)

    4 REN 9Ch Receiver Enable. This bit must be set in order to receive characters.

    3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3.

    2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3.

    1 TI 99h Transmit Flag. Set when a byte has been completely transmitted.

    0 RI 98h Receive Flag. Set when a byte has been completely received.

    Additionally, it is necessary to define the function of SM0 and SM1 by an additional table:

    SM0 SM1 Serial Mode Explanation Baud Rate

    0 0 0 8-bit Shift Register Oscillator / 12

    0 1 1 8-bit UART Set by Timer 1 (*)

    1 0 2 9-bit UART Oscillator / 64 (*)

    1 1 3 9-bit UART Set by Timer 1 (*)

    (*) Note: The baud rate indicated in this table is doubled if PCON.7 (SMOD) is set.

    The SCON SFR allows us to configure the Serial Port. Thus, well go through each bit and review its function.

    The first four bits (bits 4 through 7) are configuration bits.

    Bits SM0 and SM1 let us set the serial mode to a value between 0 and 3, inclusive. The four modes are defined in the

    chart immediately above. As you can see, selecting the Serial Mode selects the mode of operation (8-bit/9-bit, UART or

    Shift Register) and also determines how the baud rate will be calculated. In modes 0 and 2 the baud rate is fixed based on

    the oscillators frequency. In modes 1 and 3 the baud rate is variable based on how often Timer 1 overflows. Well talkmore about the various Serial Modes in a moment.

    The next bit, SM2, is a flag for "Multiprocessor communication." Generally, whenever a byte has been received the 8051

    will set the "RI" (Receive Interrupt) flag. This lets the program know that a byte has been received and that it needs to be

    processed. However, when SM2 is set the "RI" flag will only be triggered if the 9th bit received was a "1". That is to say,

    if SM2 is set and a byte is received whose 9th bit is clear, the RI flag will never be set. This can be useful in certain

  • 8/7/2019 Thesis of Major Project

    23/73

    23

    advanced serial applications. For now it is safe to say that you will almost always want to clear this bit so that the flag is

    set upon reception ofany character.

    The next bit, REN, is "Receiver Enable." This bit is very straightforward: If you want to receive data via the serial port,

    set this bit. You will almost always want to set this bit.

    The last four bits (bits 0 through 3) are operational bits. They are used when actually sending and receiving data--they are

    not used to configure the serial port.

    The TB8 bit is used in modes 2 and 3. In modes 2 and 3, a total of nine data bits are transmitted. The first 8 data bits are

    the 8 bits of the main value, and the ninth bit is taken from TB8. If TB8 is set and a value is written to the serial port, the

    datas bits will be written to the serial line followed by a "set" ninth bit. If TB8 is clear the ninth bit will be "clear."

    The RB8 also operates in modes 2 and 3 and functions essentially the same way as TB8, but on the reception side. When a

    byte is received in modes 2 or 3, a total of nine bits are received. In this case, the first eight bits received are the data of

    the serial byte received and the value of the ninth bit received will be placed in RB8.

    TI means "Transmit Interrupt." When a program writes a value to the serial port, a certain amount of time will pass before

    the individual bits of the byte are "clocked out" the serial port. If the program were to write another byte to the serial port

    before the first byte was completely output, the data being sent would be garbled. Thus, the 8051 lets the program know

    that it has "clocked out" the last byte by setting the TI bit. When the TI bit is set, the program may assume that the serial

    port is "free" and ready to send the next byte.

    Finally, the RI bit means "Receive Interrupt." It functions similarly to the "TI" bit, but it indicates that a byte has been

    received. That is to say, whenever the 8051 has received a complete byte it will trigger the RI bit to let the program know

    that it needs to read the value quickly, before another byte is read.

    3.2 BAUD RATE

    The rate of data transfer in serial communication is stated in bps (bits per second). Another widely used terminology for

    bps is BAUDRATE. However, the baud and bps rates are not necessarily equal. This is due to the fact that baud rate is the

    modern terminology and is defined as the number of signal changes per second. In modems a single change of signal,

    sometimes transfers several bits of data. As far as conductor wire is concerned, the baud rate and bps are the same.

    3.3 SETTING THE SERIAL PORT BAUD RATE

    Once the Serial Port Mode has been configured, as explained above, the program must configure the serial ports baud rate

    This only applies to Serial Port modes 1 and 3. The Baud Rate is determined based on the oscillators frequency when in

    mode 0 and 2. In mode 0, the baud rate is always the oscillator frequency divided by 12. This means if your crystal is

    11.059Mhz, mode 0 baud rate will always be 921,583 baud. In mode 2 the baud rate is always the oscillator frequency

    divided by 64, so a 11.059Mhz crystal speed will yield a baud rate of 172,797.

    In modes 1 and 3, the baud rate is determined by how frequently timer 1 overflows. The more frequently timer 1

    overflows, the higher the baud rate. There are many ways one can cause timer 1 to overflow at a rate that determines a

  • 8/7/2019 Thesis of Major Project

    24/73

    24

    baud rate, but the most common method is to put timer 1 in 8-bit auto-reload mode (timer mode 2) and set a reload value

    (TH1) that causes Timer 1 to overflow at a frequency appropriate to generate a baud rate.

    To determine the value that must be placed in TH1 to generate a given baud rate, we may use the following equation

    (assuming PCON.7 is clear).

    TH1 = 256 - ((Crystal / 384) / Baud)

    If PCON.7 is set then the baud rate is effectively doubled, thus the equation becomes:

    TH1 = 256 - ((Crystal / 192) / Baud)

    Here we are able to calculate a nice, even TH1 value. Therefore, to obtain 19,200 baud with an 11.059MHz crystal we

    must:

    1. Configure Serial Port mode 1 or 3.

    2. Configure Timer 1 to timer mode 2 (8-bit auto-reload).

    3. Set TH1 to 253 to reflect the correct frequency for 19,200 baud.

    4. Set PCON.7 (SMOD) to double the baud rate.

    3.4 WRITING THE SERIAL PORT

    Once the Serial Port has been properly configured as explained above, the serial port is ready to be used to send data and

    receive data. If you thought that configuring the serial port was simple, using the serial port will be a breeze.

    To write a byte to the serial port one must simply write the value to the SBUF (99h) SFR. For example, if you wanted to

    send the letter "A" to the serial port, it could be accomplished as easily as:

    MOV SBUF,#A

    Upon execution of the above instruction the 8051 will begin transmitting the character via the serial port. Obviously

    transmission is not instantaneous--it takes a measureable amount of time to transmit. And since the 8051 does not have a

    serial output buffer we need to be sure that a character is completely transmitted before we try to transmit the next

    character.

    The 8051 lets us know when it is done transmitting a character by setting the TI bit in SCON. When this bit is set we

    know that the last character has been transmitted and that we may send the next character, if any. Consider the following

    code segment:

    CLR TI; be sure the bit is initially clear

    MOV SBUF, #A; Send the letter A to the serial port

    JNB TI, $; Pause until the TI bit is set.

    The above three instructions will successfully transmit a character and wait for the TI bit to be set before continuing. The

    last instruction says "Jump if the TI bit is not set to $"--$, in most assemblers, means "the same address of the current

    instruction." Thus the 8051 will pause on the JNB instruction until the TI bit is set by the 8051 upon successful

    transmission of the character.

  • 8/7/2019 Thesis of Major Project

    25/73

    25

    3.5 READING THE SERIAL PORT

    Reading data received by the serial port is equally easy. To read a byte from the serial port one just needs to read the value

    stored in the SBUF (99h) SFR after the 8051 has automatically set the RI flag in SCON.

    For example, if your program wants to wait for a character to be received and subsequently read it into the Accumulator,

    the following code segment may be used:

    JNB RI, $; Wait for the 8051 to set the RI flag

    MOV A, SBUF; Read the character from the serial port

    The first line of the above code segment waits for the 8051 to set the RI flag; again, the 8051 sets the RI flag

    automatically when it receives a character via the serial port. So as long as the bit is not set the program repeats the "JNB"

    instruction continuously.

    Once the RI bit is set upon character reception the above condition automatically fails and program flow falls through to

    the "MOV" instruction which reads the value.

    Programming Tip: If you write a program that utilizes new SFRs that are specific to a given derivative chip and not

    included in the above SFR list, your program will not run properly on a standard 8051 where that SFR does not exist.

    Thus, only use non-standard SFRs if you are sure that your program will only have to run on that specific microcontroller.

    Likewise, if you write code that uses non-standard SFRs and subsequently share it with a third-party, be sure to let that

    party know that your code is using non-standard SFRs to save them the headache of realizing that due to strange behavior

    at run-time.

  • 8/7/2019 Thesis of Major Project

    26/73

    26

    3.6 WORKING IN SERIAL COMMUNICATION MODE

    When proper connection between PC and microcontroller is established, the following signal transitions takes place

    between PC and microcontroller-

    y Devices undergo POST.

    y Then PC sets DTR (data terminal ready) while modem sets DSR (data set ready).

    y For transmitting data pc sends RTS (request to send) high and if modem is free it sends CTS (clear to send).

    y Then PC starts transmitting bit by bit. At end modem sends DCD (data carrier detects).

    3.6.1 RS 232 STANDARD

    In telecommunications, 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 electricalcharacteristics and timing of signals, the meaning of signals, and the physical size and pin out of connectors. The current

    version of the standard is TIA-232-FInterface Between Data TerminalEquipment andData Circuit-Terminating

    EquipmentEmploying SerialBinary Data Interchange, issued in 1997.

  • 8/7/2019 Thesis of Major Project

    27/73

    27

    3.6.2 PINOUTS

    The following table lists commonly-used RS-232 signals and pin assignments.

    Signal Origin DB-25

    pinName Typical purpose Abbreviation DTE DCE

    Data Terminal

    ReadyOOB control signal: Tells DCE that DTE is ready to be connected. DTR 20

    Data Carrier

    Detect

    OOB control signal: Tells DTE that DCE is connected to

    telephone line.DCD 8

    Data Set ReadyOOB control signal: Tells DTE that DCE is ready to receive

    commands or data.DSR 6

    Ring IndicatorOOB control signal: Tells DTE that DCE has detected a ring

    signal on the telephone line.RI 22

    Request To Send

    OOB control signal: Tells DCE to prepare to accept data from

    DTE. RTS 4

    Clear To SendOOB control signal: Acknowledges RTS and allows DTE to

    transmit.CTS 5

    Transmitted Data Data signal: Carries data from DTE to DCE. TxD 2

    Received Data Data signal: Carries data from DCE to DTE. RxD 3

    Common Ground GND common 7

    Protective Ground PG common 1

    The signals are named from the standpoint of the DTE. The ground signal is a common return for the other connections.

    The DB-25 connector includes a second "protective ground" on pin 1. Connecting this to pin 7 (signal reference ground) is

    a common practice but not essential.

    3.6.3 UART

    A universal asynchronous receiver/transmitter (usually abbreviated UART) is a type of "asynchronous

    receiver/transmitter", a piece of computer hardware that translates data between parallel and serial forms. UARTs are

    commonly used in conjunction with communication standards such as EIA RS-232, RS-422 or RS-485. The universal

    designation indicates that the data format and transmission speeds are configurable and that the actual electric signaling

    levels and methods (such as differential signaling etc) typically are handled by a special driver circuit external to the

    UART.

    A UART is usually an individual (or part of an) integrated circuit used for serial communications over a computer or

    peripheral device serial port. UARTs are now commonly included in microcontrollers. A dual UART, orDUART,

    combines two UARTs into a single chip. Many modern ICs now come with a UART that can also communicate

    synchronously; these devices are called USARTs (universal synchronous/asynchronous receiver/transmitter).

  • 8/7/2019 Thesis of Major Project

    28/73

    28

    4. IN SYSTEM PROGRAMMING

    The IC used is a product of Philips p89lv51rd2. Philips P89LV51RD2 microcontroller has an on-chip Flash program

    memory with ISP

    (In-System Programming), which allows the microcontroller to be programmed without removing the microcontroller

    from the board and also the microcontroller, which previously programmed can be reprogrammed without removal from

    the board.

    The microcontroller must be powered up in a special ISP mode to perform the ISP operation. The ISP mode allows the

    microcontroller to communicate with a host device such as PC through a serial port. The host sends command and data to

    the microcontroller. The commands can be erase, read, and write.

    After the completion of the ISP operation, the microcontroller is reconfigured and has to be reset or power cycled so the

    microcontroller will operate normally.

    The ISP programming for the device can be done using Windows application software, which uses an Intel Hex file as

    input to program it.

    5. CIRCUIT DIAGRAM

    The circuit diagram is shown on the next page.

  • 8/7/2019 Thesis of Major Project

    29/73

  • 8/7/2019 Thesis of Major Project

    30/73

    30

    6. LIST OF ICs AND COMPONENTS USED

    S. No. COMPONENTS

    1. Microcontroller IC p89v51rd2

    2. Max 232 driver/ RS 232 device

    3. Supply Voltage 7805, 7812 (78XX)

    4. DM74LS125A quad 3 state buffer

    5. L293D motor driver

    6. ULN 2803- 8 darlington array

    7. ADC 0804- 1 bit A/D converter

    8. LM35 Precision Centigrade temperature Sensor

    9. 16*2 LCD display and Keyboard

    10. USB to DB 9 Converter

    7. DETAILED SPECIFICATION OF EACH COMPONENT

    7.1MICROCONTROLLER IC

    7.1.1 GENERAL DESCRIPTION

    The P89V51RD2 is an 80C51 microcontroller with 64 kB Flash and 1024 bytes of data RAM. A key feature of the

    P89LV51RD2 is its X2 mode option. The design engineer can choose to run the application with the conventional 80C51

    clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per machine cycle) to achieve twice the

    throughput at the same clock frequency. Another way to benefit from this feature is to keep the same performance by

    reducing the clock frequency by half, thus dramatically reducing the EMI.

    The Flash program memory supports both parallel programming and in serial In-System Programming (ISP). Parallel

    programming mode offers gang-programming at high speed, reducing programming costs and time to market. ISP allows

    a device to be reprogrammed in the end product under software control. The capability to field/update the application

    firmware makes a wide range of applications possible.

    The P89LV51RD2 is also In-Application Programmable (IAP), allowing the Flash program memory to be reconfigured

    even while the application is running.

  • 8/7/2019 Thesis of Major Project

    31/73

    31

    7.1.2 FEATURES

    y 80C51 Central Processing Unit.

    y 3 V Operating voltage from 0 MHz to 33 MHz.

    y 64 kB of on-chip Flash program memory with ISP (In-System Programming) and IAP (In-Application

    Programming).

    y Supports 12-clock (default) or 6-clock mode selection via software or ISP.

    y SPI (Serial Peripheral Interface) and enhanced UART.

    y PCA (Programmable Counter Array) with PWM and Capture/Compare functions.

    y Four 8-bit I/O ports with three high-current Port 1 pins (16 mA each).

    y Three 16-bit timers/counters.

    y Programmable Watchdog timer (WDT).

    y Eight interrupt sources with four priority levels.

    y Second DPTR register.

    y Low EMI mode (ALE inhibit).

    y TTL- and CMOS-compatible logic levels.

    y Brown-out detection.

    y Low power mode.

    y Power-down mode with external interrupt wake-up.

    y Idle mode

    y

    DIP40, PLCC44 and TQFP44 packages

    7.2MAX 232 DRIVER/ RS 232 DEVICES

    RS-232 devices may be classified as Data Terminal Equipment (DTE) or Data Communication Equipment (DCE); this

    defines at each device which wires will be sending and receiving each signal. The standard recommended but did not

    make mandatory the D-subminiature 25 pin connector. In general and according to the standard, terminals and computers

    have male connectors with DTE pin functions, and modems have female connectors with DCE pin functions. Otherdevices may have any combination of connector gender and pin definitions. Many terminals were manufactured with

    female terminals but were sold with a cable with male connectors at each end; the terminal with its cable satisfied the

    recommendations in the standard.

    Presence of a 25 pin D-sub connector does not necessarily indicate an RS-232-C compliant interface. For example, on the

    original IBM PC, a male D-sub was an RS-232-C DTE port (with a non-standard current loop interface on reserved pins),

  • 8/7/2019 Thesis of Major Project

    32/73

    32

    but the female D-sub connector was used for a parallel Centronics printer port. Some personal computers put non-standard

    voltages or signals on some pins of their serial ports.

    The standard specifies 20 different signal connections. Since most devices use only a few signals, smaller connectors can

    often be used.

    The following table lists commonly-used RS-232 signals and pin assignments. [7] For variations see Serial port.

    Signal Origin DB-25

    pinName Typical purpose Abbreviation DTE DCE

    Data Terminal

    ReadyOOB control signal: Tells DCE that DTE is ready to be connected. DTR 20

    Data Carrier

    Detect

    OOB control signal: Tells DTE that DCE is connected to

    telephone line.DCD 8

    Data Set ReadyOOB control signal: Tells DTE that DCE is ready to receive

    commands or data.DSR 6

    Ring IndicatorOOB control signal: Tells DTE that DCE has detected a ring

    signal on the telephone line.RI 22

    Request To SendOOB control signal: Tells DCE to prepare to accept data from

    DTE.RTS 4

    Clear To SendOOB control signal: Acknowledges RTS and allows DTE to

    transmit.CTS 5

    Transmitted Data Data signal: Carries data from DTE to DCE. TxD 2

    Received Data Data signal: Carries data from DCE to DTE. RxD 3

    Common Ground GND common 7

    Protective Ground PG common 1

    The signals are named from the standpoint of the DTE. The ground signal is a common return for the other connections.

    The DB-25 connector includes a second "protective ground" on pin 1. Connecting this to pin 7 (signal reference ground) is

    a common practice but not essential.

    Data can be sent over a secondary channel (when implemented by the DTE and DCE devices), which is equivalent to the

    primary channel. Pin assignments are described in following table:

    Signal Pin

    Common Ground 7

    Secondary Transmitted Data (STD) 14

    Secondary Received Data (SRD) 16

  • 8/7/2019 Thesis of Major Project

    33/73

    33

    Secondary Request To Send (SRTS) 19

    Secondary Clear To Send (SCTS) 13

    Secondary Carrier Detect (SDCD) 12

    7.2.1 CABLES

    The standard does not define a maximum cable length but instead defines the maximum capacitance that a compliantdrive circuit must tolerate. A widely-used rule-of-thumb indicates that cables more than 50 feet (15 meters) long will have

    too much capacitance, unless special cables are used. By using low-capacitance cables, full speed communication can be

    maintained over larger distances up to about 1,000 feet. For longer distances, other signal standards are better suited to

    maintain high speed.

    Since the standard definitions are not always correctly applied, it is often necessary to consult documentation, test

    connections with a breakout box, or use trial and error to find a cable that works when interconnecting two devices.

    Connecting a fully-standard-compliant DCE device and DTE device would use a cable that connects identical pin

    numbers in each connector (a so-called "straight cable"). "Gender changers" are available to solve gender mismatches

    between cables and connectors. Connecting devices with different types of connectors requires a cable that connects the

    corresponding pins according to the table above. Cables with 9 pins on one end and 25 on the other are common.

    Manufacturers of equipment with 8P8C connectors usually provide a cable with either a DB-25 or DE-9 connector (or

    sometimes interchangeable connectors so they can work with multiple devices). Poor-quality cables can cause false

    signals by crosstalk between data and control lines (such as Ring Indicator). If a given cable will not allow a data

    connection, especially if a Gender changer is in use, a Null modem may be necessary.

    7.2.2 3 WIRE AND 5 WIRE RS 232

    A minimal 3-wire RS-232 connection consisting only of transmits data, receives data and ground, and is commonly

    used when the full facilities of RS-232 are not required. Even a two-wire connection (data and ground) can be used if the

    data flow is one way (for example, a digital postal scale that periodically sends a weight reading, or a GPS receiver that

    periodically sends position, if no configuration via RS-232 is necessary). When only hardware flow control is required in

    addition to two-way data, the RTS and CTS lines are added in a 5-wire version.

    7.2.3 CONVENTIONS

    For functional communication through a serial port interface, conventions of bit rate, character framing, communications

    protocol, character encoding, data compression, and error detection, not defined in RS 232, must be agreed to by both

    sending and receiving equipment. This implementation used an 8250 UART using asynchronous start-stop character

    formatting with 7 or 8 data bits per frame, usually ASCII character coding, and data rates programmable between 75 bits

    per second and 115,200 bits per second. Data rates above 20,000 bits per second are out of the scope of the standard,

    although higher data rates are sometimes used by commercially manufactured equipment.

  • 8/7/2019 Thesis of Major Project

    34/73

    34

    7.2.4 DEVELOPMENT TOOLS MAX 232

    7.3 SUPPLY VOLTAGES

    To get a constant DC supply LM 78XX series voltage regulators are used.

    7.3.1 GENERAL DESCRIPTION

    The LM78XX series of three terminal regulators is available with several fixed output voltages making them useful in a

    wide range of applications. One of these is local on card regulation, eliminating the distribution problems associated with

    single point regulation. The voltages available allow these regulators to be used in logic systems, instrumentation, Hi Fi,

    and other solid state electronic equipment. Although designed primarily as fixed voltage regulators these devices can be

    used with external components to obtain adjustable

    voltages and currents. The LM78XX series is available in an aluminum To-3 package which will allow over 1.0A load

    current if adequate heat

    sinking is provided. Current limiting is included to limit the peak output current to a safe value. Safe area protection for

    the output transistor is provided to limit internal power dissipation. If internal power dissipation becomes too high for the

    heat sinking provided, the thermal shutdown circuit takes over preventing the IC from overheating. Considerable effort

    was expanded to make the LM78XX series of regulators easy to use and minimize the number of external components. It

    is not necessary to bypass the output, although this does improve transient response. Input bypassing is needed only if the

    regulator is located far from the

    filter capacitor of the power supply.

    For output voltage other than 5V, 12V and 15V the LM117 series provides an output voltage range from 1.2V to 57V.

  • 8/7/2019 Thesis of Major Project

    35/73

    35

    7.3.2 FEATURES

    y Output current in excess of 1A.

    y Internal thermal overload protection.

    y No external components required.

    y Output transistor safe area protection.

    y Internal short circuit current limit.

    y Available in the aluminum TO-3 package.

    7.3.3 VOLTAGES RANGE USED

    LM7805C 5V

    LM7812C 12V

    7.4 74LS125 QUAD 3 STATE BUFFER

    7.4.1 GENERAL DESCRIPTION

    This device contains four independent gates each of which performs a non-inverting buffer function. The outputs have the

    3-STATE feature. When enabled, the outputs exhibit the low impedance characteristics of a standard LS output with

    additional drive capability to permit the driving of bus lines without external resistors. When disabled, both the output

    transistors are turned off presenting a high-impedance state to the bus line. Thus the output will act neither as a significant

    load nor as a driver. To minimize the possibility that two outputs will attempt to take a common bus to opposite logic

    levels, the disable time is shorter than the

    enable time of the outputs.

  • 8/7/2019 Thesis of Major Project

    36/73

    36

    7.4.2 CONNECTION

    7.4.3 FUNCTION TABLE

    Y=A

    INPUTS OUTPUTS

    A C Y

    L L L

    H L H

    X H Hi-X

    H = HIGH Logic Level

    L = LOW Logic Level

    X = Either LOW or HIGH Logic Level

    Hi-Z = 3-STATE (Outputs are disabled)

    7.5 L293D MOTOR DRIVER

    Step 1: Installing the IC

    The L293D is a 16-pin chip with a little notch cut out of the front of it (that last bit is for you non-experts). Orient the chip

    so its notch matches the notch in the shape of the chip on the PCB. Carefully drop the chip into the gold-plated (pretty

    uptown, eh?) pads, and solder it into place from the other side. To avoid any nasty punctures, clip off any excess pins that

    poke through the pads on the solder side.

    Step 2: The 1k Resistor

  • 8/7/2019 Thesis of Major Project

    37/73

    37

    The 1k resistor (brown / black /red / gold) is inserted in about the only position it can fit into - position R1. Snug it up

    close to the circuit board, bend the leads over, and solder it into place from the other side. When done, clip off the excess

    leads.

    Step 3: LED Installation

    This is one of the really cool things about the secret driver board the LED indicators. You have the option to mount

    them upside-UP or upside-DOWN. We recommend upside-DOWN, so you can easily see them from either side.The tiny

    LEDs in your kit have a lens that can be poked into the hole of the PCB which can easily been seen if you use the driver

    board on a breadboard, or in a transparent servo case (like the Solarbotics GM4 motor). Dont worry - youll still see the

    LED light up from the other side too! Upside-down or upside-up, just as long as the lead near the painted bar on the LED

    (the cathode) goes into the square pad hole, and matches the bar printed on the PCB! If they arent installed properly, they

    arent going to light up!

    Step 4: Wiring & Installation

    Your kit comes with a set of five (5, for those who cant read five) conductor ribbon cable. Youll have to split the ends

    apart, and strip off about 1.5mm (1/16) from each end. Try to arrange your ribbon cable like the one below, as splaying

    them apart will make it easier to solder each end to the driver board. For easier soldering, pre-tin the ends of each wire.

    Starting with the red wire on the side nearest the pad marked , start soldering them into place, one per pad. Well be

    using the wire colors for different functions. If possible, solder the wires down on top of the pad not through. The metal

    motor case underneath can (and will!) short out leads that poke through the PCB. If you have to use the holes, When done,

    drop the wired PCB into the servo, on top of the motor tabs. Solder the motor tabs to the PCB, and youre ready to close it

    up!trim the excess lead off flush with the bottom of the PCB. If you want to use your motor driver on a breadboard, skip

    ahead to Option 3.

    When done, drop the wired PCB into the servo, on top of the motor tabs. Solder the motor tabs to the PCB, and youre

    ready to close it up!

    Step 5: Closing it up

    No rocket science here - simply put the servo bottom plate back in place, insert the corner screws, and tighten them down.

    Be careful to fold over a few of the edge ribbon wires, as itll be too wide to fit the slot that originally fit three. Or hey - be

    a rebel and use a knife (or other favourite tool of destruction) and widen the slot so all five wires lay flat.

  • 8/7/2019 Thesis of Major Project

    38/73

    38

    7.5.1 FEATURES

    L293D motor driver- for applications where space is tight, and power needs are great! Sneak this module inside a servo

    for more power and flexibility for your robot designs.

    Its Powerful: Configured with LED direction indicators, able to deliver 1.2 A of current (2.4A surge) and 36 volts supply

    power, this module has more than enough ability to turn your hobby servo or gear motor into a real workhorse!

    Its Breadboard Friendly: And if a stealthy install doesntinterest you, add seven pins to the option pads, and youhave a

    power driver module you can use on a breadboard.The Secret L293D motor driver is a perfect match forthe Solarbotics

    GM4 gear motor. With the transparentmotor case, you can monitor the drivers indicator LEDs!

    7.6 ULN2803

    7.6.1 FEATURES

    .EIGHT DARLINGTONS WITH COMMON EMITTERS

    .OUTPUT CURRENT TO 500 Ma

    .OUTPUT VOLTAGE TO 50 V

    .INTEGRAL SUPPRESSION DIODES VERSIONS FOR ALL POPULAR LOGIC FAMILIES

    .OUTPUT CAN BE PARALLELED INPUTS PINNED OPPOSITE OUTPUTS TO SIMPLIFY BOARD LAYOUT

    7.6.2DESCRIPTION

    The ULN2801A-ULN2805A each contain eight darlington transistors with common emitters and integral suppression

    diodes for inductive loads. Each darlington features a peak load current rating of 600mA (500mA continuous) and can

    withstand at least 50V in the off state. Outputs may be paralleled for higher current capability. Five versions are available

    to simplify interfacing to standard logic families: the ULN2801A is designed for general purpose applications with a

    current limit resistor ; the ULN2802A has a 10.5kW input resistor and zener for 14-25V PMOS ; the ULN2803A has a

    2.7kW input resistor for 5V TTL and CMOS ; the ULN2804A has a 10.5kW input resistor for 6-15V CMOS and the

    ULN2805A is designed to sink a minimum of 350mA for standard and Schottky TTL where higher output current is

    required. All types are supplied in a 18-lead plastic DIP with a copper lead from and feature the convenient input

    opposite- output pin out to simplify board layout.

  • 8/7/2019 Thesis of Major Project

    39/73

    39

    7.6.3 PIN DIAGRAM

    7.7 ADC 0804- 8-Bit P Compatible A/D Converters

    7.7.1 GENERAL DESCRIPTION

    Analog to digital converters find huge application as an intermediate device to convert the signals from analog to digita

    form. These digital signals are used for further processing by the digital processors. Various sensors like temperature,

    pressure, force etc. convert the physical characteristics into electrical signals that are analog in nature.

    ADC0804 is a very commonly used 8-bit analog to digital convertor. It is a single channel IC, i.e., it can take only one

    analog signal as input. The digital outputs vary from 0 to a maximum of 255. The step size can be adjusted by setting the

    reference voltage at pin9. When this pin is not connected, the default reference voltage is the operating voltage, i.e., Vcc

    The step size at 5V is 19.53mV (5V/255), i.e., for every 19.53mV rise in the analog input, the output varies by 1 unit. To

    set a particular voltage level as the reference value, this pin is connected to half the voltage. For example, to set a

    reference of 4V (Vref), pin9 is connected to 2V (Vref/2), thereby reducing the step size to 15.62mV (4V/255).

    ADC0804 needs a clock to operate. The time taken to convert the analog value to digital value is dependent on this clock

    source. An external clock can be given at the Clock IN pin. ADC 0804 also has an inbuilt clock which can be used in

  • 8/7/2019 Thesis of Major Project

    40/73

    40

    absence of external clock. A suitable RC circuit is connected between the Clock IN and Clock R pins to use the internal

    clock.

    7.7.2 FEATURES

    Compatible with 8080 P derivatives-no interfacing logic needed - access time - 135 ns

    Easy interface to all microprocessors, or operates "stand alone"

    Differential analog voltage inputs

    Logic inputs and outputs meet both MOS and TTL voltage level specifications

    Works with 2.5V (LM336) voltage reference

    On-chip clock generator

    0V to 5V analog input voltage range with single 5V supply

    No zero adjust required

    0.3[Prime] standard width 20-pin DIP package

    20-pin molded chip carrier or small outline package

    Operates ratiometrically or with 5 VDC, 2.5 VDC, or analog span adjusted voltage reference

    7.7.3 KEY SPECIFICATION

    Key Specification

    Resolution 8 bits

    Total error LSB, LSB and 1 LSB

    Conversion time 100 s

  • 8/7/2019 Thesis of Major Project

    41/73

    41

    7.7.4 BLOCK DIAGRAM AND PIN CONNECTIONS.

    7.8 LM35 PRECISION CENTIGRADE TEMPERATURE SENSOR

    7.8.1 GENERAL DESCRIPTION

    The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the

    Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin,

    as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The

    LM35 does not require any external calibration or trimming to provide typical accuracies of C at room temperature

    and C over a full -55 to +150C temperature range. Low cost is assured by trimming and calibration at the wafer

    level. The LM35's low output impedance, linear output, and precise inherent calibration make interfacing to readout or

  • 8/7/2019 Thesis of Major Project

    42/73

    42

    control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws

    only 60 A from its supply, it has very low self-heating, less than 0.1C in still air. The LM35 is rated to operate over a -

    55 to +150C temperature range, while the LM35C is rated for a -40 to +110C range (-10 with improved accuracy).

    The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D

    are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface mount small

    outline package and a plastic TO-220 package.

    7.8.2 FEATURES

    Calibrated directly in Celsius (Centigrade)

    Linear + 10.0 mV/C scale factor

    0.5C accuracy guaranteeable (at +25C)

    Rated for full -55 to +150C range

    Suitable for remote applications

    Low cost due to wafer-level trimming

    Operates from 4 to 30 volts

    Less than 60 A current drain

    Low self-heating, 0.08C in still air

    Nonlinearity only C typical

    Low impedance output, 0.1 Ohm for 1 mA load

    7.8.3 PIN

  • 8/7/2019 Thesis of Major Project

    43/73

    43

    7.9 16*2 LCD DISPLAY

    An LCD is a small low cost display. It is easy to interface with a micro-controller because of an embedded controller (the

    black blob on the back of the board).

    This controller is standard across many displays (HD 44780) which means many micro-controllers (including the

    Arduino) have libraries that make displaying messages as easy as a single line of code.

    7.9.1 TESTING

    Testing your LCD with an Arduino is really simple. Wire up your display using the schematic or breadboard layout sheet.

    Then open the Arduino IDE and open the example program.

    File > Sketchbook > Examples > Library-LiquidCrystal > HelloWorld

    Upload to your board and watch as "hello, world!" is shown on your display. If no message is displayed the contrast may

    need to be adjusted. To do this turn the potentiometer.

    7.9.2 LIBRARY SUMMARY

    Liquid Crystal(rs, rw, enable, d4, d5, d6, d7) - create a new

    Liquid Crystal object using a 4 bit data bus

    Liquid Crystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) - create

    a new Liquid Crystal object using an 8 bit data bus

    clear() - Clears the display and moves the cursor to upper left corner

    home() - Moves the cursor to the upper left corner

    set Cursor (col, row) - moves the cursor to column and row write (data) - writes the char data to the display

    print (data) - prints a string to the display

  • 8/7/2019 Thesis of Major Project

    44/73

    44

    7.9.3 THE CIRCUIT

  • 8/7/2019 Thesis of Major Project

    45/73

    45

    8 INTERFACING

    TYPES OF MICRO CONTROLLER INTERFACING

    1. Digital

    2. Analog

    1. Types of Digital Interfacing

    a. On/ Off

    b. Parallel

    c. Serial

    c. Types of serial Interfacing

    a). Asynchronous

    b). Synchronous

    a). Types of Asynchronous Interfacing

    i. 1 wire

    ii. RS232/RS485

    iii. Ethernet

    b). Types of Synchronous Interfacing

    i. 2 wire (I2C)

    ii. 4 wire (micro wire)

    2. Types of Analog Interfacing

    a. Voltage Interfacing

    b. Current Interfacing

    8.1DIGITAL INTERFACING

    Digital Inputs/Outputs

    On/OFF control and monitoring.

    Digital Input Example: Reading the status of buttons or switches (Keypad Interface)

    1 2 3 A

    4 Advantages * 0 # D

  • 8/7/2019 Thesis of Major Project

    46/73

    46

    Simplest interface.

    Lowest-cost to implement (built into the microcontroller).

    High speed.

    Low programming overhead.

    Disadvantages

    Only on/off control/monitoring.

    Short distance, few feet maximum.

    Single device control/monitoring.

    8.1.1 KEYBOARD INTERFACING

    The key board here we are interfacing is a matrix keyboard. This key board is designed with a particular rows and

    columns. These rows and columns are connected to the microcontroller through its ports of the micro controller 8051. We

    normally use 8*8 matrix key board. So only two ports of 8051 can be easily connected to the rows and columns of the key

    board.

    Whenever a key is pressed, a row and a column gets shorted through that pressed key and all the other keys are left

    open. When a key is pressed only a bit in the port goes high. Which indicates microcontroller that the key is pressed. By

    this high on the bit key in the corresponding column is identified.

    Once we are sure that one of key in the key board is pressed next our aim is to identify that key. To do this we

    firstly check for particular row and then we check the corresponding column the key board.

    To check the row of the pressed key in the keyboard, one of the row is made high by making one of bit in the output

    port of 8051 high . This is done until the row is found out. Once we get the row next out job is to find out the column of

    the pressed key. The column is detected by contents in the input ports with the help of a counter. The content of the inpu

    port is rotated with carry until the carry bit is set.

    The contents of the counter is then compared and displayed in the display. This display is designed using a seven

    segment display and a BCD to seven segment decoder IC 7447.

    The BCD equivalent number of counter is sent through output part of 8051 displays the number of pressed key.

  • 8/7/2019 Thesis of Major Project

    47/73

    47

    INTERFACING OF KEYBOARD TO 8051.

    Keyboard is organized in a matrix of rows and columns asshown in the figure. The microcontroller accessesboth rows

    and columns through the port.

    1. The 8051 has 4 I/O ports P0 to P3 each with 8 I/O pins, P0.0 to P0.7,P1.0 to P1.7, P2.0 to P2.7, P3.0 to

    P3.7. The one of the port P1 (it understood that P1 means P1.0 to P1.7) as an I/P port for microcontroller

    8051, port P0 as an O/P port of microcontroller 8051 and port P2 is used for displaying the number of

    pressed key.

    2. Make all rows of port P0 high so that it gives high signal when key is pressed.

    3. See if any key is pressed by scanning the port P1 by checking all columns for non zero condition.

    4. If any key is pressed, to identify which key is pressed make one row high at a time.

    5. Initiate a counter to hold the count so that each key is counted.

    6. Check port P1 for nonzero condition. If any nonzero number is there in [accumulator], start column

    scanning by following step 9.

    7. Otherwise make next row high in port P1.

    8. Add a count of 08h to the counter to move to the next row by repeating steps from step 6.

    9. If any key pressed is found, the [accumulator] content is rotated right through the carry until carry bit

    sets, while doing this increment the count in the counter till carry is found.

    10. Move the content in the counter to display in data field or to memory location

    11. To repeat the procedures go to step 2.

    Program to interface matrix keyboard to microcontroller8051

    Start of main program:

    to check that whether any key is pressed

    start: mov a,#00h

    mov p1,a ;making all rows of port p1 zero

    mov a,#0fh

    mov p1,a ;making all rows of port p1 high

  • 8/7/2019 Thesis of Major Project

    48/73

    48

    press: mov a,p2

    jz press ;check until any key is pressed

    after making sure that any key is pressed

    mov a,#01h ;make one row high at a time

    mov r4,a

    mov r3,#00h ;initiating counter

    next: mov a,r4

    mov p1,a ;making one row high at a time

    mov a,p2 ;taking input from port A

    jnz colscan ;after getting the row jump to check

    column

    mov a,r4

    rl a ;rotate left to check next row

    mov r4,a

    mov a,r3

    add a,#08h ;increment counter by 08 count

    mov r3,a

    sjmp next ;jump to check next row

    after identifying the row to check the colomn following steps are followed

    colscan: mov r5,#00h

    in: rrc a ;rotate right with carry until get the carry

    jc out ;jump on getting carry

    inc r3 ;increment one count

    jmp in

    out: mov a,r3

    da a ;decimal adjust the contents of counter

    before display

    mov p2,a

    jmp start ;repeat for check next key.

  • 8/7/2019 Thesis of Major Project

    49/73

    49

    8.1.2 LED INTERFACING (Digital Output Interfacing)

    When learning microcontroller the first program that everyone tries is Turning ON a LED or Flashing a LED.

    Here I will be explaining how to interface a LED to a Microcontroller & a sample code for LED flashing.

    The adjoining figure shows how to interface the LED to 8051 microcontroller. As you can see the Anode is connected

    through a resistor to Vcc & the Cathode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED

    is OFF & when the Port Pin is LOW the LED is turned ON.

    You may ask why we cant connect Anode to the Port Pin and cathode to the Ground. The answer is simple,

    8051 has an internal pull-up resistor of 10k. So now when the port Pin is HIGH the Anode is positive with respect to theCathode so the LED should turn ON right? But the internal pull-up resistor comes in series with the resistor thus limiting

    the current flowing through the LED. This current is not sufficient enough to Turn ON the LED.

    Flashing LED ALGORITHM

    1. Start.

    2. Turn ON LED.

    3. Turn OFF LED.

    4. GO TO 2.We now want to flash a LED. It works by turning ON a LED & then turning it OFF & then looping back to START.

    However the operating speed of microcontroller is very high so the flashing frequency will also be very fast to be detected

    by human eye.

    Modified Flashing LED ALGORITHM

    1. Start.

    2. Turn ON LED.

  • 8/7/2019 Thesis of Major Project

    50/73

    50

    3. Wait for some time (delay).

    4. Turn OFF LED.

    5. Wait for some time (delay).

    6. Go To 2.

    You can see in the modified algorithm that after turning ON the LED the controller waits for the delay period & then turns

    OFF the led & again waits for the delay period & then goes back to the start.

    PROGRAM 1

    1. ORG 0000h

    2. loop:

    3. CLR P2.0 //Turn ON LED

    4. CALL DELAY

    5. SETB P2.0 //Turn OFF LED

    6. CALL DELAY

    7. JMP loop

    In the above program LED is connected to P2.0. The above program can also be written as follows.

    PROGRAM 2

    1. ORG 0000h

    2. loop:

    3. CPL P2.0 //Compliment Port Pin

    4. CALL DELAY

    5. JMP loop

    The only drawback of the second program is that the LED's ON time will be equal to LED's OFF time. Whereas in the

    first program if different delay routines are called the LED's ON time can be different than that of LED's OFF time.

    8.1.3 INTERFACING ANALOG TO DIGITAL CONVERTERS (ADC 0804)

  • 8/7/2019 Thesis of Major Project

    51/73

    51

    As shown in the typica circuit, ADC0804 can be interfaced with any microcontroller. You need a minimum of 11 pins to

    interface ADC0804, eight for data pins and 3 for control pins. As shown in the typical circuit the chip select pin can be

    made low if you are not using the microcontroller port for any other peripheral (multiplexing).

    There is a universal rule to find out how to use an IC. All you need is the datasheet of the IC you are working with and

    take a look at the timing diagram of the IC which shows how to send the data, which signal to assert and at what time the

    signal should be made high or low etc.

    Note:Keep this in mind that whenever you are working with an ICand you want to know how to communicate with that

    IC, then simply look into the timing diagram of thatICfrom its datasheet. It gives you complete information that you need

    regarding the communication ofIC.

    The above timing diagrams are from ADC0804 datasheet. The first diagram (FIGURE 10A) shows how to start a

    conversion. Also you can see which signals are to be asserted and at what time to start a conversion. So looking into the

    timingdiagram FIGURE 10A. We note down the steps or say the order in which signals are to be asserted to start a

    conversion of ADC. As we have decided to make Chipselect pin as low so we need not to bother about the CS signal in

  • 8/7/2019 Thesis of Major Project

    52/73

    52

    the timing diagram. Below steps are for starting an ADC conversion. I am also including CS signal to give you a clear

    picture. While programming we will not use this signal.

    1. Make chip select (CS) signal low.

    2. Make write (WR) signal low.

    3. Make chip select (CS) high.

    4. Wait for INTR pin to go low (means conversion ends).

    Once the conversion in ADC is done, the data is available in the output latch of the ADC. Looking at the FIGURE 10B

    which shows the timing diagram of how to read the converted value from the output latch of the ADC. Data of the new

    conversion is only available for reading after ADC0804 made INTR pin low or say when the conversion is over. Below

    are the steps to read output from the ADC0804.

    1. Make chip select (CS) pin low.

    2. Make read (RD) signal low.

    3. Read the data from port where ADC is connected.

    4. Make read (RD) signal high.

    5. Make chip select (CS) high.

    8051 Assembly Programming for ADC 0804

    rd equ P1.0 ;ReadsignalP1.0

    wr equ P1.1 ;Write signalP1.1

    cs equ P1.2 ;Chip SelectP1.2

    intr equ P1.3 ;INTRsignalP1.3

    adc_port equ P2 ;ADCdata pinsP2

    adc_val equ 30H ;ADC read value stored here

    org 0H

    start: ;Start ofProgram

    acall conv ;StartADCconversion

    acall read ;Read converted value

    mov P3,adc_val ;Move the value to Port3

    sjmp start ;Do it again

    conv: ;Start ofConversion

    clr cs ;Make CS low

    clr wr ;Make WR Low

  • 8/7/2019 Thesis of Major Project

    53/73

    53

    nop

    setb wr ;Make WR High

    setb cs ;Make CS high

    wait:

    jb intr,wait ;Wait forINTRsignal

    ret ;Conversion done

    read: ;ReadADCvalue

    clr cs ;Make CS Low

    clr rd ;Make RD Low

    mov a,adc_port ;Read the converted value

    mov adc_val,a ;Store it in local variable

    setb rd ;Make RD High

    setb cs ;Make CS High

    ret ;Reading done

  • 8/7/2019 Thesis of Major Project

    54/73

  • 8/7/2019 Thesis of Major Project

    55/73

    55

    mov SEVENSEGMENT, #0 ;clear seven segment display

    setb K1 ;select display 2

    clr K2

    Mov SEVENSEGMENT,A ;7seg

    ret

    ;======================================================================

    ; Lookup Table

    ; Decoder to Seven Segment

    ;======================================================================

    Decoder7Segment:

    DB 00111111b,00000110b,01011011b,01001111b,01100110b

    DB 01101101b,01111101b,00000111b,01111111b,01101111b

    ;======================================================================

    ; Lookup Table

    ; Temperature = DataADC*100/255

    ;======================================================================

    Ones:

    db 0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9,9

    db 0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9

    db 9,0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8

    db 9,9,0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8

    db 8,9,9,0,0,0,1,1,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,9,9,9,0,0,1,1,1,2,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9,9,0

    Tens:

    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

    db 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3

    db 3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5

    db 5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7

    db 7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,0

    end

  • 8/7/2019 Thesis of Major Project

    56/73

    56

    8.1.5 INTERFACING OF 16*2 LCD DISPLAY

    Description.

    This is the first interfacing example for the Parallel Port. We will start with something simple. This

    example doesn't use the Bi-directional feature found on newer ports, thus it should work with most, if no

    all Parallel Ports. It however doesn't show the use of the Status Port as an input. So what are we

    interfacing? A 16 Character x 2 Line LCD Module to the Parallel Port. These LCD Modules are very

    common these days, and are quite simple to work with, as all the l