Interface LCD and Keypad

Embed Size (px)

Citation preview

  • 8/19/2019 Interface LCD and Keypad

    1/23

    INTERFACING

    LCD

    DIVISION OF MECHATRONICS

    DEPARTMENT OF PRODUCTION TECHNOLOGY 

    MIT CAMPUS

    ANNA UNIVERSITY - CHENNAI

  • 8/19/2019 Interface LCD and Keypad

    2/23

    Overview LCD display working.

    LCD specs.

    Concepts.

    Algorithm.

    rogramming

    Initiali!ation in atmega"#.

    Display strings.

  • 8/19/2019 Interface LCD and Keypad

    3/23

    Inp$t and o$tp$t de%ices

    Outputs:

    Mtrs ! DC" Stepper" Serv#$

    LEDS$

    LCD$ % se&'e(t$

    I(puts:

    Se(srs$

    Swit)*$

    +e,p.$

  • 8/19/2019 Interface LCD and Keypad

    4/23

    LCD

    LCD &Li'$id Crystal Display( screen is anelectronic display mod$le.

    A /012 LCD means it can display "# charactersper line and there are * s$ch lines.

    LCD each character is displayed in +,- pi,el

    matri,.

    LCD has two registers namely Command andData.

  • 8/19/2019 Interface LCD and Keypad

    5/23

    LCD in con/g$rations

  • 8/19/2019 Interface LCD and Keypad

    6/23

    LCD pin description

    RS !Re&ister Se3e)t#: 0hen R123 this allowthe $ser to send command s$ch as &clearscreen go home 4link c$rsor(. 0hen R12"

    this allow the $ser to send data. E(43e: It $sed to latch the in5ormation to the

    data pins this done 4y send a high to low p$lse&o5 width o5 6+3 ns( so the LCD latches the datapresented on the data pins.

  • 8/19/2019 Interface LCD and Keypad

    7/23

    LCD Initiali!ation &he, %al$e(

  • 8/19/2019 Interface LCD and Keypad

    8/23

    1ending commands and

    data to LCD  The 5ollowing steps sho$ld 4e done to send the

    command and data to the LCD7

    "( Initiali!ed the LCD.

    *( 1ending Commands to the LCD.

    8( 1ending data to the LCD

  • 8/19/2019 Interface LCD and Keypad

    9/23

    Initiali!ing the LCDFor e,ample to initiali!e LCD 9* lines +:- matri,

    ;4it mode< the 5ollowing commands sho$ld 4e$sed7

    ". 3,8; to select the type and mode o5 operation

    *. 3,3E to display the c$rsor 4linking.

    8. 3,3" to clear the LCD display.1ending commands to LCD

     To send commands to the LCD the 5ollowing steps sho$ld 4e done7

    ". R123 R023.

    *.  The command n$m4er sho$ld 4e p$t on the data pins &D3 toD-(.

    8.  A p$lse &high to low( sho$ld 4e sent on the Ena4le pin. A5tereach command a delay o5 &"33$s( sho$ld 4e placed

  • 8/19/2019 Interface LCD and Keypad

    10/23

    1ending data to LCD

     To send data to the LCD the 5ollowing steps sho$ld4e done7 R12" R023.

    ".  The data sho$ld 4e p$t on the data pins &=3 to

    =-(.*. A p$lse &high to low( sho$ld 4e sent on the

    Ena4le pin.

    A5ter each data a delay o5 &"33$s( sho$ld 4eplaced.

  • 8/19/2019 Interface LCD and Keypad

    11/23

    Inter5acing LCD

    Can 4e inter5aced either in ;>4it mode or 6>4itmode.

     In ;>4it mode all data lines are connected.

    In 6>4it mode only 5o$r data lines areconnected.

  • 8/19/2019 Interface LCD and Keypad

    12/23

    5si) ) i(stru)ti( set 6rLCDLCD_Init();   /* Initilize the lcd before displaying any thing on the lcd */  

    LCD_DisplayString("hello, world");   /*Display "hello, world" on first line*/  

    LCD_GoToLineTwo()   /*Go to second line and display "good morning" */  

    LCD_DisplayString("good morning") 

    void LCD_Init() 

    {

     delay_us(5000);

     LCD_CmdWrite(0x38);  // LCD 2lines, *! matri  

    LCD_CmdWrite(0x0E);  // Display #$ c%rsor #$ &lin'ing off  

    LCD_CmdWrite(0x01);  // Clear the LCD 

    LCD_CmdWrite(0x80);  // C%rsor to (irst line (irst )osition

     } 

    LCD i(iti3i7ti(

  • 8/19/2019 Interface LCD and Keypad

    13/23

    void LCD_DataWrite( char  dat) 

    { databus=dat;  // end the data to LCD rs=1;  // elect the Data +egister by p%lling + IG  

    rw=0;  // elect the -rite #peration by p%lling +- L#-  

    en=1;  // end a igh.to.Low )%sle at nable )in 

    delay_us(10); 

    en=0; 

    delay_ms(1); } 

    T write .t t LCD

    void LCD_CmdWrite( char  cmd)

     { 

    databus=cmd;  // end the command to LCD rs=0;  // elect the Command +egister by p%lling + L#-  

    rw=0;  // elect the -rite #peration by p%lling +- L#-  

    en=1;  // end a igh.to.Low )%sle at nable )in 

    delay_us(10);

     en=0; 

    delay_ms(1); } 

    T write )'(. t LCD

  • 8/19/2019 Interface LCD and Keypad

    14/23

    INTERFACING

    ?E@ADDIVISION OF MECHATRONICS

    DEPARTMENT OF PRODUCTION TECHNOLOGY 

    MIT CAMPUS

    ANNA UNIVERSITY - CHENNAI

  • 8/19/2019 Interface LCD and Keypad

    15/23

    Matrix Keyboard Connection to ports

    ?ey4oards are organi!ed in a matri, o5 rows and

    col$mns.

      The C accesses 4oth rows and col$mnsthro$gh ports.

      There5ore with two 8>4it ports an 8,8

    matri, o5 keys can 4e connected.

    I5 all the rows aregro$nded and akeyis pressed one o5 the col$mns willha%e 3 since thekeypressed pro%idesthepath to gro$nd

    I5 no key has4een pressedreading the

    inp$t port willyield "s 5or allcol$mns sincethey are allconnected tohigh &Bcc(

  • 8/19/2019 Interface LCD and Keypad

    16/23

    It is the 5$nction o5 the microcontroller to scanthe key4oard contin$o$sly to detect andidenti5y the key pressed.

     To detect a pressed key the microcontrollergro$nds all rows 4y pro%iding 3 to the o$tp$tlatch then it reads the col$mns.

    I5 the data read 5rom col$mns is D8 D3 2""""

    no key has 4een pressed and the processcontin$es till key press is detected.

    I5 one o5 the col$mn 4its has a !ero this meansthat a key press has occ$rred

    For e,ample i5 D8 D3 2 ""3" this means thata key in the D" col$mn has 4een pressed

    A5ter detecting a key press microcontroller willgo thro$gh the process o5 identi5ying the key

  • 8/19/2019 Interface LCD and Keypad

    17/23

     Task

    Identi5y the row and col$mn o5 the pressed key 5or each o5

    the 5ollowing.

    &a( D8 D3 2 """3 5or the row D8 D3 2 "3"" 5or thecol$mn

    &4( D8 D3 2 ""3" 5or the row D8 D3 2 3""" 5or the

    col$mn

  • 8/19/2019 Interface LCD and Keypad

    18/23

    Algorithm  To make s$re that the preceding key has 4een

    released 3s are o$tp$t to all rows at once and thecol$mns are read and checked repeatedly $ntil allthe col$mns are high.

    0hen all col$mns are 5o$nd to 4e high the programwaits 5or a short amo$nt o5 time 4e5ore it goes to the

    ne,t stage o5 waiting 5or a key to 4e pressed.  To see i5 any key is pressed the col$mns are

    scanned o%er and o%er in an in/nite loop $ntil one o5them has a 3 on it.

    Remem4er that the o$tp$t latches connected torows still ha%e their initial !eros making themgro$nded

    A5ter the key press detection it waits *3 ms 5or the4o$nce and then scans the col$mns again

  • 8/19/2019 Interface LCD and Keypad

    19/23

    &a( it ens$res that the /rst key press detection wasnot an erroneo$s one d$e a spike noise

    &4( the key press. I5 a5ter the *3>ms delay the key isstill pressed it goes 4ack into the loop to detect a realkey press.

     To detect which row key press 4elongs to itgro$nds one row at a time reading the col$mns

    each time. I5 it /nds that all col$mns are high this means that

    the key press cannot 4elong to that row

    •   There5ore it gro$nds the ne,t row andcontin$es $ntil it /nds the row the key press

    4elongs to

    • pon /nding the row that the key press 4elongs toit sets $p the starting address 5or the look>$p ta4leholding the scan codes &or A1CII( 5or that row.

  • 8/19/2019 Interface LCD and Keypad

    20/23

     To identi5y the key press it rotates the col$mn

    4its one 4it at a time into the carry ag andchecks to see i5 it is low.

    • pon /nding the !ero it p$lls o$t the A1CIIcode 5or that key 5rom the look>$p ta4le

    otherwise it increments the pointer to point tothe ne,t element o5 the look>$p ta4le

  • 8/19/2019 Interface LCD and Keypad

    21/23

    Flow chart

    1tart

    Gro$ndall rows

    Allkeysopen

    "

    Read allcol$mns

    "

    Read allcol$mns

    Allkeysdown

    0ait 5orde4o$nce

    Read allcol$mns

    Allkeysdown

    *

    No

     @es

    No

     @es

  • 8/19/2019 Interface LCD and Keypad

    22/23

    *

    Findwhich keyis pressed

    Allkeysdown

    Gro$ndNe,t row

    Get scan code

    5rom ta4le

    Ret$rn

     @es

    No

  • 8/19/2019 Interface LCD and Keypad

    23/23

    T*(8 Yu Fr

     YurAtte(ti(