interfacing lcd with mb90f387s

Upload: mark-villamor

Post on 03-Jun-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Interfacing LCD With MB90F387S

    1/40

    Interfacing Displaytech 204ASeries LCD to MB90F387S

  • 8/12/2019 Interfacing LCD With MB90F387S

    2/40

    About the Displaytech 204A

    Item Contents Unit

    LCD type TN / STN / FSTN ---

    LCD duty 1/16 ---

    LCD bias 1/5 ---

    Viewing direction 6 / 12 oclockModule size (W!H!T) 98 !60 !11.0 MAX (14.0 MAX W/LED BACKLIGHT) mm

    Viewing area (W!H) 76 !25.2 mm

    Number of characters (characters!lines) 20 !4 ---

    Character matrix (W!H) 5 !8 dots

    Character size (W!H) 2.95 !4.75 mm

    Dot size (W!H) 0.55 !0.55 mm

    Dot pitch (W!H) 0.60 !0.60 mm

  • 8/12/2019 Interfacing LCD With MB90F387S

    3/40

    External Dimensions

  • 8/12/2019 Interfacing LCD With MB90F387S

    4/40

    Actual Picture (Reverse Contrast Type)

  • 8/12/2019 Interfacing LCD With MB90F387S

    5/40

    Block Diagram

  • 8/12/2019 Interfacing LCD With MB90F387S

    6/40

    Interface Signals

    Pin NO. Symbol Level Description

    1 VSS 0V Ground

    2 VDD 5.0V Supply voltage for logic

    3 VO --- Input voltage for LCD

    4 RS H/L H : Data signal, L : Instruction signal

    5 R/W H/L H : Read mode, L : Write mode6 E H, H!L Enable signal for KS0076

    7 DB0 H/L Data bit 0

    8 DB1 H/L Data bit 1

    9 DB2 H/L Data bit 2

    10 DB3 H/L Data bit 3

    11 DB4 H/L Data bit 4

    12 DB5 H/L Data bit 513 DB6 H/L Data bit 6

    14 DB7 H/L Data bit 7

    15 A --- Back light anode

    16 K --- Back light cathode

  • 8/12/2019 Interfacing LCD With MB90F387S

    7/40

    Registers

    Instruction Register (IR)

    stores instruction codes such as clear

    display or shift cursor and also storesaddress information for the display dataRAM

    Data Register

    is used for temporarily storing data duringdata transactions with the MCU

  • 8/12/2019 Interfacing LCD With MB90F387S

    8/40

    Registers

    Busy Flag (BF)

    When the busy flag is set at a logical "1", the

    LCD unit is executing an internal operation,and no instruction will be accepted

    Address Counter (AC)

    The address counter generates the address

    for the display data RAM and charactergenerator RAM

  • 8/12/2019 Interfacing LCD With MB90F387S

    9/40

    Registers

    Display Data RAM (DD RAM)

    This 80 x 8 bit RAM stores up to 80 8-bit

    character codes as display data

    AC6 AC5 AC4 AC3 AC2 AC1 AC0

    HEXDigit

    AC

    High-orderBits

    Lower-orderBits

    HEXDigit

    1

    Example: DD RAM address '4E'

    0 0 1 1 1 0

    4 E

  • 8/12/2019 Interfacing LCD With MB90F387S

    10/40

    Registers

    Character Generator ROM (CG ROM)

    This ROM generates a 5 !7 dot-matrix

    character pattern for each of 160 different8-bit character codes

    Character Generator RAM (CG RAM)

    This RAM stores eight arbitrary 5 x 7 dot-

    matrix character patterns, as programmedby the user

  • 8/12/2019 Interfacing LCD With MB90F387S

    11/40

    0000

    HIGH-ORDER4 BIT

    LOW-ORDER 4 BIT

    0010 0011 0100 0101 0110 0111 1010 1011 1100 1101 1110 1111

    xxxx0000

    xxxx0001

    xxxx0010

    xxxx0011

    xxxx0100

    xxx0101

    xxx0110

    xxxx0111

    xxxx1000

    xxxx1001

    xxxx1010

    xxxx1011

    xxxx1100

    xxxx1101

    xxxx1110

    xxxx1111

    CGRAM

    (1)

    (2)

    (3)

    (4)

    (5)

    (6)

    (7)

    (8)

    (1)

    (2)

    (3)

    (4)

    (5)

    (6)

    (7)

    (8)

    Character Codes

  • 8/12/2019 Interfacing LCD With MB90F387S

    12/40

    MCU Interface

    The LCD unit performs either dual 4-bit or single 8-

    bit data transfers, allowing the user to interface with

    either a 4-bit or 8-bit microprocessor

    4-Bit Microprocessor Interface.

    Data lines DB4 - DB7 are used for data transfers.

    Data transactions with the external

    microprocessor take place in two 4-bit data

    transfer operations.

  • 8/12/2019 Interfacing LCD With MB90F387S

    13/40

    MCU Interface

    8-bit Microprocessor Interface

    Each 8-bit piece of data is transferred in a singleoperation using the entire data bus DB0 - DB7.

  • 8/12/2019 Interfacing LCD With MB90F387S

    14/40

  • 8/12/2019 Interfacing LCD With MB90F387S

    15/40

    Initialization byInstruction 8-bit

    Interface

    Power ON

    Wait 15 ms or moreafter VDDreaches 4.5 V

    RS R/W DB7DB6DB5DB4DB3DB2DB1DB0

    0 0 0 0 1 1 * * * *

    Wait 4.1 ms or more

    RS R/W DB7DB6DB5DB4DB3DB2DB1DB0

    0 0 0 0 1 1 * * * *

    Wait 100 s or more

    End of Initialization

    RS R/W DB7DB6DB5DB4DB3DB2DB1DB0

    0 0 0 0 1 1 * * * *

    RS R/W DB7DB6DB5DB4DB3DB2DB1DB0

    0 0 0 0 1 1 N F * *

    0 0 0 0 0 0 1 0 0 0

    0 0 0 0 0 0 0 0 0 1

    0 0 0 0 0 0 0 1 I/D S

    Busy flag can't be checked before execution of thisinstruction

    Function Set (8-Bit Interface)

    Busy flag can't be checked before execution of thisinstruction

    Function Set (8-Bit Interface)

    Busy flag can't be checked before execution of thisinstruction

    Function Set (8-Bit Interface)

    (a) Busy flag can be checked after the following instructionsare completed. If the busy flag is not going to be checked,then a wait time longer than the total execution time ofthese instructions is required (See Table 7.)

    Function Set

    Display Off

    Display Clear

    Entry Mode Set

    8-Bit Interface,Single/Dual LineDisplay, Display Font

    Caution: At this point,the display formatan't be changed.

    -

  • 8/12/2019 Interfacing LCD With MB90F387S

    16/40

    Power ON

    Wait 15 ms or moreafter VDDreaches 4.5 V

    RS R/W DB7DB6DB5DB4

    0 0 0 0 1 1

    Wait 4.1 ms or more

    RS R/W DB7DB6DB5DB4

    0 0 0 0 1 1

    RS R/W DB7DB6DB5DB4

    0 0 0 0 1 1

    RS R/W DB7DB6DB5DB4

    0 0 0 0 1 0

    0 0 0 0 1 0

    0 0 N F * *

    Wait 100 s or more

    End of Initialization

    Busy flag can't be checked before execution of thisinstruction

    Function Set (8-Bit Interface)

    Busy flag can't be checked before execution of thisinstruction

    Function Set (8-Bit Interface)

    Busy flag can't be checked before execution of thisinstruction

    Function Set (8-Bit Interface)

    (a) Busy flag can be checked after the following instructionsare completed. If the busy flag is not going to be checked,then a wait time longer than the total execution time ofthese instructions is required (See Table 7.)

    This instruction signals the LCD unit to begin accepting andsending data in dual 4-bit transfers for all subsequenttransfers for all subsequent transactions. This is the only4-bit instruction recognized by the LCD unit.

    II Function Set

    III Display Off

    IV Display Clear

    V Entry Mode Set

    4-Bit Interface,Single/Dual LineDisplay, Display Font

    0 0 0 0 0 0

    0 0 1 0 0 0

    0 0 0 0 0 O

    0 0 0 0 0 1

    0 0 0 0 0 0

    0 0 0 1 I/D S

    I Function Set (4-Bit Interface)I

    II

    III

    IV

    V

    Caution: At this point,the display formatcan't be changed.

    Initialization byInstruction 4-bit

    Interface

  • 8/12/2019 Interfacing LCD With MB90F387S

    17/40

    Instruction Set

    H

  • 8/12/2019 Interfacing LCD With MB90F387S

    18/40

    tAS

    PWEH

    tDSW

    tcycE

    tAH

    tAH

    VIHVIL

    DB0 - DB7

    tEf

    tHtEr

    VIHVIL

    E

    VILR/W

    VIH

    VILRS

    VALID DATA

    -

    H

    H

    H

    H

    H

    H

    !

    !

    !

    !

    !

    !

    !

    Write Operation Timing Characteristics

  • 8/12/2019 Interfacing LCD With MB90F387S

    19/40

    tAS

    PWEH

    tDDR

    tcycE

    tAH

    tAH

    VOHVOL

    DB0 - DB7

    tEf

    tDHR

    tEr

    VIHVILE

    VIHR/W

    VIHVIL

    RS

    VALID DATA

    I

    I

    I

    I

    I

    -

    !

    !

    !

    !

    !

    !

    !

    Read Operation Timing Characteristics

  • 8/12/2019 Interfacing LCD With MB90F387S

    20/40

  • 8/12/2019 Interfacing LCD With MB90F387S

    21/40

  • 8/12/2019 Interfacing LCD With MB90F387S

    22/40

    LKS Expansion Board

    LCD + Keypad + Stepper Motor

  • 8/12/2019 Interfacing LCD With MB90F387S

    23/40

    Video Demo

  • 8/12/2019 Interfacing LCD With MB90F387S

    24/40

  • 8/12/2019 Interfacing LCD With MB90F387S

    25/40

    Programming

    Step 1: Write a function to sendInstructions to LCD

    Step 2: Write a function to Initialize LCD(initialize once)

    Step 3: Write a function to send Data to

    LCD Step 4: Write a function to display a string

    to LCD

  • 8/12/2019 Interfacing LCD With MB90F387S

    26/40

    Demonstration #1

    Flowchart for instCtrl() - function to sendinstruction to LCD (8-bit)

  • 8/12/2019 Interfacing LCD With MB90F387S

    27/40

    Flowchart for instCtrl()function

  • 8/12/2019 Interfacing LCD With MB90F387S

    28/40

    Sample Code (C)

    void instCtrl(unsigned char inst)

    {

    IO_PDR2.byte = inst; // load 8-bit instruction to 8-bit LCD data lines

    IO_PDR5.bit.P50 = 0; // set RS to 0 (instruction register)

    IO_PDR5.bit.P51 = 0; // set RW to 0 (write mode)

    IO_PDR5.bit.P52 = 1; // set E to 1 (initial state)

    delay(1); // base delay is 16 us

    IO_PDR5.bit.P52 = 0; // set E to 0 (H-L: final state)

    readBF(); // read busy flag;

    }

  • 8/12/2019 Interfacing LCD With MB90F387S

    29/40

    Reading the Busy Flag

  • 8/12/2019 Interfacing LCD With MB90F387S

    30/40

    Sample Code (C)void readBF()

    {

    unsigned char flag;

    IO_DDR2.byte = 0x00; // set direction of LCD data lines to input

    IO_PDR5.bit.P50 = 0; // set RS to 0 (instruction register)

    IO_PDR5.bit.P51 = 1; // set RW to 1 (read mode)

    IO_PDR5.bit.P52 = 1; // set E to 1 (initial state)

    do {

    flag = IO_PDR2.bit.P27; // read bit 7 of Port 2 (busy flag)

    } while (flag);

    IO_PDR5.bit.P52 = 0; // set E to 0 (H-L: final state)

    IO_DDR2.byte = 0xFF; // set direction of LCD data lines back to output

    }

  • 8/12/2019 Interfacing LCD With MB90F387S

    31/40

    Seatwork #1

    Flowchart and code for dataCtrl() -function to send instruction to LCD (8-bit)

    Flowchart and code for initLCD() -function to send initialize the LCD (2-line,Cursor on, blink off)

  • 8/12/2019 Interfacing LCD With MB90F387S

    32/40

    Demonstration #2

    Flowchart for instCtrl() - function to sendinstruction to LCD (4-bit)

  • 8/12/2019 Interfacing LCD With MB90F387S

    33/40

    Flowchart fordataCtrl()

    function 4-bit interface(8-bit transfer)

  • 8/12/2019 Interfacing LCD With MB90F387S

    34/40

    Sample Code (C)void instCtrl(unsigned char inst)

    {

    IO_DDR2.byte = inst>> 4; // transfer the upper4-bit of inst to 4-bit LCD data line

    IO_PDR2.bit.P24 = 0; // set RS to 0 (instruction register)

    IO_PDR5.bit.P52 = 0; // set RW to 0 (write mode)

    IO_PDR5.bit.P53 = 1; // set E to 1 (initial state)

    delay(1); // delay for 16 us

    IO_PDR5.bit.P53 = 0; // set E to 0 (H-L: final state)

    IO_DDR2.byte = inst; // transfer the lower 4-bit of inst to 4-bit LCD data line

    IO_PDR5.bit.P53 = 1; // set E to 1 (initial state)

    delay(1); // delay for 16 us

    IO_PDR5.bit.P53 = 0; // set E to 0 (H-L: final state)

    readBF(); // read busy flag

    }

  • 8/12/2019 Interfacing LCD With MB90F387S

    35/40

    Flowchart for instCtrl()function 4-bit interface

    (4-bit transfer for LCD initializationpurposes)

  • 8/12/2019 Interfacing LCD With MB90F387S

    36/40

    Seatwork #2

    Flowchart and code for dataCtrl() -function to send data to LCD (4-bit)

  • 8/12/2019 Interfacing LCD With MB90F387S

    37/40

    Demonstration #3

    Displaying text to the LCD

    displaying Hello! at the center of the 2nd line

  • 8/12/2019 Interfacing LCD With MB90F387S

    38/40

    Character Display Addresses

    Line 1 (0x80 - 0x93)

    Line 3 (0x94 - 0xA7)

    Line 2 (0xC0 - 0xD3)

    Line 4 (0xD4 - 0xE7)

    Hello!

    Line 1 address continue to Line 3 while Line 2 continues at Line 4.

  • 8/12/2019 Interfacing LCD With MB90F387S

    39/40

    Sample Code (C).

    .

    instCtrl(0xC6); // move cursor to 2nd line 7th column

    dataCtrl(H); // prints H at current cursor position

    // then shifts the cursor to the right*

    dataCtrl(E); // prints E

    dataCtrl(L); // prints L

    dataCtrl(L); // prints L

    dataCtrl(O); // prints O

    dataCtrl(!); // prints !.

    .

    * assuming configuration is cursor shift to right

  • 8/12/2019 Interfacing LCD With MB90F387S

    40/40

    Sources

    Sharp HD44870 LCD Datasheet

    Displaytech 204A Datasheet