minor final

Upload: kamal-patidar

Post on 05-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Minor Final

    1/23

    Introduction

    In todays scenario there is no way to see the inputs that are given to

    the microcontroller. This created a problem for the user to see and to checkwhether the input given is correct or not. To avoid such a problem we made

    Keypad And LCD Interfacing Using Microcontroller . Thisapplication provides a display for the input that are given to microcontroller

    through keypad, by the user.

    This project display the alphabet or numbers as pressed using keypad

    by the user .The display device used here is (2x16)LCD which is interfaced

    with microcontroller along with (4x4) keypad.

    Microcontroller is a microprocessor with integrated along with input

    output ports and memory in a single package.

    Microcontroller has 4 input output Port 0,1,2,3 having 8 pins each.

    LCD is connected to Port 1 and keypad with Port 2.The circuit require a 5

    volt supply which is obtained using a power supply (connected to pin 40 of

    microcontroller) circuit which takes an input of 230 volt AC and a 5 volt DC

    supply is finally obtained in output .

    1

  • 8/2/2019 Minor Final

    2/23

    Circuit diagram

    2

  • 8/2/2019 Minor Final

    3/23

    Power Supply

    Power supply is designed to convert high voltage AC mains electricity

    to a suitable low voltage supply for electronics circuits and other devices. A

    power supply can be broken down into a series of blocks, each of which

    performs a particular function.

    A 5V regulated supply:

    Functions of the blocks is described below:

    Transformer - steps down high voltage AC mains to low voltage AC.

    Rectifier - converts AC to DC, but the DC output is varying.

    Smoothing - smooths the DC from varying greatly to a small ripple.

    Regulator - eliminates ripple by setting DC output to a fixed voltage.

    Dual Supplies

    Some electronic circuits require a power supply with positive and

    negative outputs as well as zero volts (0V). This is called a 'dual supply'

    because it is like two ordinary supplies connected together as shown in the

    diagram.

    Dual supplies have three outputs, for example a 9V supply has +9V, 0V

    and -9V output.

    3

  • 8/2/2019 Minor Final

    4/23

    Transformer

    Transformers convert AC electricity from one voltage to another with

    little loss of power. Transformers work only with AC .

    Step-up transformers increase voltage, step-down transformers reduce

    voltage. Most power supplies use a step-down transformer to reduce thedangerously high mains voltage (230V) to a safer low voltage.

    The input coil is called the primary and the output coil is called the

    secondary. There is no electrical connection between the two coils, instead

    they are linked by an alternating magnetic field created in the soft-iron core

    of the transformer. The two lines in the middle of the circuit symbol

    represent the core.

    Transformers waste very little power so the power out is (almost) equal to

    the power in. As voltage is stepped down current is stepped up.

    The ratio of the number of turns on each coil, called the turns ratio,

    determines the ratio of the voltages. A step-down transformer has a large

    number of turns on its primary (input) coil which is connected to the high

    voltage mains supply, and a small number of turns on its secondary (output)

    coil to give a low output voltage.

    Transformer circuit symbol

    Transformer

    Transformer only

    4

  • 8/2/2019 Minor Final

    5/23

    Bridge rectifier

    A bridge rectifier can be made using four individual diodes, but it is

    also available in special packages containing the four diodes required. It is

    called a full-wave rectifier because it uses all the AC wave (both positive

    and negative sections). 1.4V is used up in the bridge rectifier because eachdiode uses 0.7V when conducting and there are always two diodes

    conducting, as shown in the diagram below. Bridge rectifiers are rated by the

    maximum current they can pass and the maximum reverse voltage they can

    withstand .

    Transformer + Rectifier

    5

  • 8/2/2019 Minor Final

    6/23

    CapacitorSmoothing is performed by a large value electrolytic capacitor

    connected across the DC supply to act as a reservoir, supplying current to

    the output when the varying DC voltage from the rectifier is falling. The

    diagram shows the unsmoothed varying DC (dotted line) and the smoothedDC (solid line). The capacitor charges quickly near the peak of the varying

    DC, and then discharges as it supplies current to the output.

    Smoothing is not perfect due to the capacitor voltage falling a little as it

    discharges, giving a small ripple voltage. A larger capacitor will give less

    ripple

    Transformer + Rectifier + Smoothing

    6

  • 8/2/2019 Minor Final

    7/23

    Regulator

    Voltage regulator ICs are available with fixed (typically 5, 12 and

    15V) or variable output voltages. They are also rated by the maximum

    current they can pass. Negative voltage regulators are available, mainly foruse in dual supplies. Most regulators include some automatic protection

    from excessive current ('overload protection') and overheating ('thermal

    protection').

    Many of the fixed voltage regulator ICs have 3 leads and look like

    power transistors, such as the 7805 +5V 1A regulator shown on the right.

    They include a hole for attaching a heat sink .

    Voltage regulator

    Transformer + Rectifier + Smoothing + Regulator

    7

  • 8/2/2019 Minor Final

    8/23

    LED

    A light-emitting diode, usually called an LED is a semiconductor

    diode that emits incoherent narrow-spectrum light when electrically biased

    in the forward direction of the p-n junction, as in the common LED circuit.

    This effect is a form of electroluminescence.A LED is usually a small area light source, often with extra optics

    added to the chip that shapes its radiation pattern.[2][3] LEDs are often used as

    small indicator lights on electronic devices and increasingly in higher power

    applications such as flashlights and area lighting. The color of the emitted

    light depends on the composition and condition of the semiconducting

    material used, and can be infrared, visible, or ultraviolet. LEDs can also be

    used as a regular household light source.

    8

  • 8/2/2019 Minor Final

    9/23

    LCD

    Liquid Crystal Display also called as LCD is very helpful in providing

    user interface as well as for debugging purpose. The most common type of

    LCD controller is HITACHI 44780 which provides a simple interface

    between the controller & an LCD. These LCD's are very simple to interface

    with the controller .The most commonly used ALPHANUMERIC displays are 1x16

    (Single Line & 16 characters), 2x16 (Double Line & 16 character per line) &

    4x20 ( four lines & Twenty characters per line).

    Here we are using 2x16 alphanumeric display

    The LCD requires 3 control lines (RS, R/W & EN) & 8 data lines. In 8-bit

    mode 8 data lines + 3 control lines i.e. total 11 lines are required.

    When RS is low (0), the data is to be treated as a command. When RS

    is high (1), the data being sent is considered as text data which shouldbe displayed on the screen.

    When R/W is low (0), the information on the data bus is being written

    to the LCD. When RW is high (1), the program is effectively reading

    from the LCD. Most of the times there is no need to read from the

    LCD so this line can directly be connected to Gnd thus saving one

    controller line.

    The EN pin is used to latch the data present on the data pins. A HIGH

    - LOW signal is required to latch the data. The LCD interprets and

    executes our command at the instant the EN line is brought low. Ifyou never bring EN low, your instruction will never be executed.

    9

  • 8/2/2019 Minor Final

    10/23

    Pin Symbol Function

    1 Vss Ground

    2 Vdd Supply Voltage

    3 Vo Contrast Setting

    4 RS Register Select

    5 R/WRead/Write

    Select

    6 EnChip Enable

    Signal

    7-14DB0-

    DB7Data Lines

    15 A/VeeGnd for the

    backlight

    16 K Vcc for backlight

    Display Data Ram (DDRAM) stores the display data. So when we

    have to display a character on LCD we basically write it into DDRAM. Fora 2x16 LCD the DDRAM address for first line is from 80h to 8fh & for

    second line is 0c0h to 0cfh. So if we want to display 'H' on the 7 th position of

    the first line then we will write it at location 87h.

    Two types of data is given to the LCD data to be displayed, command or

    special instruction.

    10

  • 8/2/2019 Minor Final

    11/23

    Data to be Displayed

    LCD data display:

    SETB RS //Telling the LCD that the data which is being

    send is to be displayed

    MOV P1,A //Character to be displayed is in Acc

    SETB EN

    CLR EN //High to Low pulse on EN to latch the data

    CALL DELAY //Delay so that LCD finishes its internal

    operations

    Ret

    Delay is used at the end of the subroutines, this is done to wait until theinstruction is completely executed by the LCD. This will assure that our

    program gives the LCD the time it needs to execute instructions and also

    makes our program compatible with any LCD, regardless of how fast or

    slow it is.

    "*" - Not Used/Ignored. This bit can be either "1" or "0"

    Set Cursor Move Direction:

    ID - Increment the Cursor After Each Byte Written to Display if Set

    S - Shift Display when Byte Written to Display Enable Display/Cursor

    11

  • 8/2/2019 Minor Final

    12/23

    D - Turn Display On(1)/Off(0)

    C - Turn Cursor On(1)/Off(0)

    B - Cursor Blink On(1)/Off(0)

    Move Cursor/Shift Display

    SC - Display Shift On(1)/Off(0)

    RL - Direction of Shift Right(1)/Left(0)

    Set Interface Length

    DL - Set Data Interface Length 8(1)/4(0)

    N - Number of Display Lines 1(0)/2(1)

    F - Character Font 5x10(1)/5x7(0)

    Poll the "Busy Flag" BF - This bit is set while the LCD is processing

    Move Cursor to CGRAM/Display

    A - Address

    Read/Write ASCII to the Display

    D - Data

    Debugging Procedure

    If the above program does not work then follow these steps:-

    1) Check if the supply is correct.

    2)If all connections are correct.

    3) Increase the delay time.

    12

  • 8/2/2019 Minor Final

    13/23

  • 8/2/2019 Minor Final

    14/23

    Switches

    A switch is a mechanical device used to connect and disconnect a

    circuit at will. Switches cover a wide range of types, from subminiature upto industrial plant switching megawatts of power on high voltage

    distribution lines.

    A biased switch is one containing a spring that returns the actuator to

    a certain position. The "on-off" notation can be modified by placing

    parentheses around all positions other than the resting position. For example,

    an (on)-off-(on) switch can be switched on by moving the actuator in either

    direction away from the centre, but returns to the central off position when

    the actuator is released.

    The momentary push-button switch is a type of biased switch. Themost common type is a push-to-make switch, which makes contact when

    the button is pressed and breaks when the button is released.

    14

    http://images.google.co.in/imgres?imgurl=http://www.cybermarket.co.uk/ishop/images/923/786_145.jpg&imgrefurl=http://www.cybermarket.co.uk/shopscr2463.html&h=200&w=200&sz=6&hl=en&start=5&tbnid=pick8ozpkqOdnM:&tbnh=104&tbnw=104&prev=/images%3Fq%3Dpush%2Bto%2Bmake%2Bswitch%26gbv%3D2%26hl%3Den%26sa%3DG
  • 8/2/2019 Minor Final

    15/23

    Keypad Connections with 8051

    Microcontroller

    Circuit shown above is for demonstration and does not include any reset and

    crystal circuit. For practical use you need to have a reset circuit and crystal.

    Introduction

    Keypads are a part of HMI or Human Machine Interface and play really

    important role in a small embedded system where human interaction or

    human input is needed. Matrix keypads are well known for their simple

    architecture and ease of interfacing with any microcontroller.

    15

    http://www.8051projects.net/keypad-interfacing/introduction.phphttp://www.8051projects.net/keypad-interfacing/keypad-8051.gifhttp://www.8051projects.net/keypad-interfacing/introduction.php
  • 8/2/2019 Minor Final

    16/23

    Constructing a Matrix Keypad

    Construction of a keypad is really simple. As per the outline shown in the

    figure below we have four rows and four columns. In between eachoverlapping row and column line there is a key.

    So keeping this outline we can constuct a keypad using simple SPSTSwitches as shown below:

    Now our keypad is ready, all we have to do is connect the rows and columnsto a port of microcontroller and program the controller to read the input.

    16

  • 8/2/2019 Minor Final

    17/23

    Scanning a Matrix Keypad

    There are many methods depending on how you connect your keypad with

    your controller, but the basic logic is same. We make the coloums as i/p and

    we drive the rows making them o/p, this whole procedure of reading thekeyboard is called scanning.

    In order to detect which key is pressed from the matrix, we make row lines

    low one by one and read the columns. Lets say we first make Row1 low

    ,then read the columns. If any of the key in row1 is pressed will make the

    corresponding column as low i.e if second key is pressed in Row1, then

    column2 will give low. So we come to know that key 2 of Row1 is pressed.

    This is how scanning is done.

    So to scan the keypad completely, we need to make rows low one by one

    and read the columns. If any of the button is pressed in a row, it will take the

    corresponding column to a low state which tells us that a key is pressed in

    that row. If button 1 of a row is pressed then Column 1 will become low, if

    button 2 then column2 and so on...

    17

  • 8/2/2019 Minor Final

    18/23

    MicrocontrollerFeatures

    Compatible with MCS-51 Products

    4K Bytes of In-System Reprogrammable Flash Memory

    Endurance: 1,000 Write/Erase Cycles Fully Static Operation: 0 Hz to 24 MHz

    Three-Level Program Memory Lock

    128 x 8-Bit Internal RAM

    32 Programmable I/O Lines

    Two 16-Bit Timer/Counters

    Six Interrupt Sources

    Programmable Serial Channel

    Low Power Idle and Power Down Modes

    Description

    The AT89C51 is a low-power, high-performance CMOS 8-bit

    microcomputer with 4k bytes of Flash Programmable and Erasable Read

    Only Memory (PEROM). The device is manufactured using Atmels high

    density nonvolatile memory technology and is compatible with the industry

    standard MCS-51 instruction set and pinout. The on-chip Flash allows the

    program memory to be reprogrammed in-system or by a conventional

    nonvolatile memory programmer. By combining a versatile 8-bit CPU withFlash on a monolithic chip, the Atmel AT89C51 is a powerful

    microcomputer which provides a highly flexible and cost effective solution

    to many embedded control applications

    The AT89C51 provides the following standard features: 4Kbytes of Flash,

    128 bytes of RAM, 32 I/O lines, two 16-bittimer/counters, a five vector two-

    level interrupt architecture ,a full duplex serial port, on-chip oscillator and

    clock circuitry .In addition, the AT89C51 is designed with static logic for

    operation down to zero frequency and supports two software selectablepower saving modes. The Idle Mode stops the CPU while allowing the

    RAM, timer/counters, serial port and interrupt system to continue

    functioning. The Power Down Mode saves the RAM contents but freezes the

    oscillator disabling all other chip functions until the next hardware reset.

    18

  • 8/2/2019 Minor Final

    19/23

    19

  • 8/2/2019 Minor Final

    20/23

    Pin DescriptionPin configuration of 8051/8031 microcontroller.

    20

  • 8/2/2019 Minor Final

    21/23

    VCC : Supply voltage.

    GND: Ground.

    Port 0

    Port 0 is an 8-bit open drain bidirectional I/O port. As an output port each

    pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins

    can be used as high impedance inputs.

    Port 0 may also be configured to be the multiplexed low order address/data

    bus during accesses to external program and data memory. In this mode P0

    has internal pullups. Port 0 also receives the code bytes during Flash

    programming, and outputs the code bytes during program verification.

    Port 1

    Port 1 is an 8-bit bidirectional I/O port with internal pullups.The Port 1output buffers can sink/source four TTL inputs.When 1s are written to Port 1

    pins they are pulled high by the internal pullups and can be used as inputs.

    As inputs, Port 1 pins that are externally being pulled low will source current

    (IIL) because of the internal pullups. Port 1 also receives the low-order

    address bytes during Flash programming and verification.

    Port 2

    Port 2 is an 8-bit bidirectional I/O port with internal pullups. The Port 2

    output buffers can sink/source four TTL inputs. When 1s are written to Port

    2 pins they are pulled high by the internal pullups and can be used as inputs.

    As inputs, Port 2 pins that are externally being pulled low will source current

    (IIL) because of the internal pullups. Port 2 emits the high-order address

    byte during fetches from external program memory and during accesses to

    external data memory that use 16-bit addresses (MOVX @ DPTR). In this

    application it uses strong internal pull-ups .when emitting 1s. During

    accesses to external data memory that use 8-bit addresses (MOVX @ RI),

    Port 2 emits the contents of the P2 Special Function Register. Port 2 also

    receives the high-order address bits and some control signals during Flash

    programming and verification.

    Port 3

    Port 3 is an 8-bit bidirectional I/O port with internal pullups. The Port 3

    output buffers can sink/source four TTL inputs. When 1s are written to Port

    3 pins they are pulled high by the internal pullups and can be used as inputs.

    As inputs, Port 3 pins that are externally being pulled low will source current

    21

  • 8/2/2019 Minor Final

    22/23

    (IIL) because of the pullups. Various special features of the AT89C51 as

    listed below:

    Port Pin Alternate Functions

    P3.0 RXD (serial input port)

    P3.1 TXD (serial output port)

    P3.2 INT0 (external interrupt 0)

    P3.3 INT1 (external interrupt 1)

    P3.4 T0 (timer 0 external input)

    P3.5 T1 (timer 1 external input)

    P3.6 WR (external data memory write strobe)

    P3.7 RD (external data memory read strobe)

    Port 3 also receives some control signals for Flash programming andverification.

    RST

    Reset input. A high on this pin for two machine cycles while the oscillator is

    running resets the device.

    ALE/PROG

    Address Latch Enable output pulse for latching the low byte of the address

    during accesses to external memory. This pin is also the program pulse input

    (PROG) during Flash programming.

    In normal operation ALE is emitted at a constant rate of 1/6 the oscillator

    frequency, and may be used for external timing or clocking purposes. Note,

    however, that one ALE pulse is skipped during each access to external Data

    Memory.

    If desired, ALE operation can be disabled by setting bit 0 of SFR location

    8EH. With the bit set, ALE is active only during a MOVX or MOVC

    instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-

    disable bit has no effect if the microcontroller is in external execution mode.

    PSEN

    Program Store Enable is the read strobe to external program memory.When

    the AT89C51 is executing code from external program memory, PSEN is

    activated twice each machine cycle, except that two PSEN activations are

    skipped during each access to external data memory.

    22

  • 8/2/2019 Minor Final

    23/23

    EA/V PP

    External Access Enable. EA must be strapped to GND in order to enable the

    device to fetch code from external program memory locations starting at

    0000H up to FFFFH.

    Note, however, that if lock bit 1 is programmed, EA will be internally

    latched on reset.

    EA should be strapped to VCC for internal program executions. This pin also

    receives the 12-volt programming enable voltage (VPP) during Flash

    programming, for parts that require 12-volt VPP.

    XTAL1

    Input to the inverting oscillator amplifier and input to the internal clock

    operating circuit.

    XTAL2Output from the inverting oscillator amplifier.

    23