Praktek 6 AVR Display Data Pada LCD

Embed Size (px)

Citation preview

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    1/15

    Praktek 6

    Display Data Pada LCD

    Tujuan:

    Mahasiswa mengerti cara membuat program C pada mikrokontroller AVR untuk

    melakukan pemrograman pada modul LCD

    Peralatan yang digunakan:

    modul AVR

    Modul LCD

    Deskripsi/ Dasar Teori:

    Gambar 1. LCD character (tampak isual!

    Gambar ". #iring Diagram LCD $arakter "%&"

    1

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    2/15

    'abel.1. in )ut LCD character

    Pins Description

    1 Ground

    " Vcc

    * Contrast Voltage

    + ,R-, /0nstruction-Register elect

    ,R-#, /Read-#rite LCD Registers

    2 ,3, Clock

    4 5 1+ Data 0-) ins (D%..D4!

    1 Anoda (6! backlight

    12 $atoda (5! backlight

    Gambar *. Rangkaian pengatur kontras tampilan LCD

    "

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    3/15

    Gambar +. etting LCD di Code Vision

    'abel.". Da7tar 0nstruksi LCD Character

    R/S R/W D7 D6 D5 D4 D3 D D! D" #nstruction/Description

    4 5 !4 !3 ! !! !" $ % 7 Pins

    % % % % % % % % % 1 Clear Displa8

    % % % % % % % % 1 9 Return Cursor and LCD to :ome osition

    % % % % % % % 1 0D et Cursor Moe Direction% % % % % % 1 D C ; 3nable Displa8-Cursor

    % % % % % 1 C RL 9 9 Moe Cursor-hi7t Displa8

    % % % % 1 DL < = 9 9 et 0nter7ace Length

    % % % 1 A A A A A A Moe Cursor into CGRAM

    % % 1 A A A A A A A Moe Cursor to Displa8

    % 1 ;= 9 9 9 9 9 9 9 oll the ,;us8 =lag,

    1 % D D D D D D D D#rite a Character to the Displa8 at the CurrentCursor osition

    1 1 D D D D D D D DRead the Character on the Displa8 at the

    Current Cursor osition

    'he bit descriptions 7or the di77erent commands are>

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

    Set Cursor Move Direction ID - Incre!ent the Cursor #ter $ach %&te 'ritten to Dis()a& i# Set

    *

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    4/15

    S - Shi#t Dis()a& hen %&te 'ritten to Dis()a&

    $nab)e Dis()a&/Cursor D - Turn Dis()a& +n,1/+##,0 C - Turn Cursor +n,1/+##,0 % - Cursor %)in +n,1/+##,0

    Move Cursor/Shi#t Dis()a&

    SC - Dis()a& Shi#t +n,1/+##,0 - Direction o# Shi#t ight,1/e#t,0

    Set Inter#ace ength D - Set Data Inter#ace ength ,1/2,0 N - Nu!ber o# Dis()a& ines 1,0/3,1 4 - Character 4ont 5610,1/567,0

    8o)) the "%us& 4)ag" %4 - This bit is set hi)e the CD is (rocessing

    Move Cursor to C9M/Dis()a& - ddress

    ead/'rite SCII to the Dis()a& D - Data

    roses inisialisasi pemrograman LCD dalam mode + 7our bit>

    1. #ait more than 1 msecs a7ter power is applied.

    ". #rite %&%* to LCD and wait msecs 7or the instruction to complete*. #rite %&%* to LCD and wait 12% usecs 7or instruction to complete

    +. #rite %&%* AGA0< to LCD and wait 12% usecs (or poll the ;us8 =lag!

    . et the )perating Characteristics o7 the LCDo #rite %&%" to the LCD to 3nable =our ;it Mode

    &ll 'ollo(ing instruction/Data Writes re)uire t(o ni**le (rites+

    o #rite ,et 0nter7ace Length,

    o #rite %&%1-%&%% to turn o77 the Displa8

    o #rite %&%%-%&%1 to Clear the Displa8

    o #rite ,et Cursor Moe Direction, etting Cursor ;ehaiour ;its

    o #rite ,3nable Displa8-Cursor, ? enable Displa8 and )ptional Cursor

    +

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    5/15

    Gambar . Da7tar $ode $arakter 8ang bisa ditampilkan di LCD karakter

    =ungsi57ungsi 8ang sudah disediakan dalam pustaka (librar8! 7ile LCD.:>

    /lcd/read8(! memeriksa kesiapan LCD untuk melakukan perintahselan@utn8a (memeriksa status bus8 7lag!

    /lcd/write/data(unsigned char data!beri perintah ke LCD

    lcd/write/b8te(unsigned char addr unsigned char data!write a b8te to the

    LCD character generator or displa8 RAM

    unsigned char lcd/read/b8te(unsigned char addr! read a b8te 7rom the

    LCD character generator or displa8 RAM

    lcd/goto&8(unsigned char & unsigned char 8!set the LCD displa8 position

    &B%..* 8B%..*

    lcd/clear(!clear the LCD

    lcd/putchar(char c!write the string str located in RAM to the LCD lcd/puts(char 9str!write the string str located in RAM to the LCD

    lcd/puts7(char 7lash 9str!write the string str located in =LA: to the LCD

    unsigned char lcd/init(unsigned char lcd/columns! initialie the LCD

    controller

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    6/15

    PERCOBAAN 1

    :inc)ude ;!ega13.h>)cd>(ort?061% @8+T:endas!void !ain,voidA 8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@ // Inisia)isasi CD )cd>(utchar,s@ // Ta!(i)an arater s di baris 0 o)o! 0

    )cd>goto6&,50@ // Ee o)o! 5 baris 0 )cd>(utchar,t@ // Ta!(i)an arater t di o)o! 5 baris 0

    )cd>goto6&,F1@ // Ee o)o! F baris 1)cd>(utchar,t@ // Ta!(i)an arater t di o)o! F baris 1

    hi)e,1AG@G

    :asiln8a>

    2

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    7/15

    PERCOBAAN 2

    :inc)ude ;!ega13.h)cd>(ort?061% @8+T:endas!void !ain,voidA 8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@ // Inisia)isasi CD )cd>(utchar,s@ // Ta!(i)an arater s di baris 0 o)o! 0

    )cd>(utchar,06F0@ // Ditu)is datan&a ,)ihat tabe)

    )cd>(utchar, @ // s(asi)cd>(utchar,06C0@ // Ditu)is datan&a ,)ihat tabe))cd>(utchar,H5@ // Ditu)is datan&a ,)ihat tabe)

    hi)e,1AG@G

    4

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    8/15

    PERCOBAAN 3

    :inc)ude ;!ega13.h)cd>(ort?061% @8+T:endas!void !ain,voidA 8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@ // Inisia)isasi CD)cd>(uts#,"$$ET+ INDUSTI"@ // Ta!(i)an arater 1 a)i!at)cd>goto6&,01 @ // Mu)ai o)o! 0 baris 1)cd>(uts#,"8$NS"@ // Ta!(i)an arater 1 a)i!at

    hi)e,1

    AG@G

    PERCOBAAN 4

    :inc)ude ;!ega13.h(ort?061% @8+T:endas!void !ain,voidA 8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@ // Inisia)isasi CD )cd>(uts#,"ha))o"@

    de)a&>!s,1000@

    )cd>c)ear,@)cd>(uts#,"a(a abar.."@

    hi)e,1A

    G@G

    E

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    9/15

    PERCOBAAN 5

    Animasi garis 8ang berputar.

    :inc)ude ;!ega13.h(ort?061% @8+T:endas!void !ain,voidA 8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@ // Inisia)isasi CD )cd>(uts# ,"oading.. "@

    hi)e ,1 A

    )cd>goto6&,100@ )cd>(utchar,-@ de)a&>!s,100@

    )cd>goto6&,100@ )cd>(utchar,@

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    10/15

    de)a&>!s,100@

    )cd>goto6&,100@ )cd>(utchar,/@ de)a&>!s,100@

    G@G

    PERCOBAAN 6

    :inc)ude ;!ega13.h(ort?061% @8+T:endas!void !ain,voidAint a@ 8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@ // Inisia)isasi CD

    hi)e ,1 A

    )cd>(uts# ,"oading.. "@)cd>goto6&,01@

    #or ,a?1@a;?30@aJJ A )cd>(utchar,06##@ de)a&>!s,F00@

    G

    )cd>goto6&,00@

    1%

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    11/15

    )cd>(uts# ,"8rocess Co!()ete. "@ de)a&>!s,3000@ )cd>c)ear,@

    G@G

    PERCOBAAN 7

    Menampilkan angka desimal dari % sampai dan berulang. ( ratusan - * digit !

    :inc)ude ;!ega13.h(ort?061% @8+T:endas!

    ///////////////////////////////void K3%CD,int bi)anganAint ratusan(u)uhansatuan@

    ratusan? bi)angan/100@ // !isa) bi)angan?3F1 // 3F1/100? 3(u)uhan ? ,bi)angan - ,ratusan*100/10@ // ,3F1-,3*100/10 // ,3F1-300/10 ? F1/10 ? Fsatuan ? bi)angan - ,(u)uhan*10 - ,ratusan*100@

    )cd>(utchar,ratusanJ06F0@)cd>(utchar,(u)uhanJ06F0@)cd>(utchar,satuanJ06F0@G

    11

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    12/15

    void !ain,voidAint a@

    8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@

    hi)e ,1 A

    #or,a?0@a;?LLL@aJJ A )cd>goto6&,00@

    K3%CD,a@de)a&>!s,100@

    GG

    G

    PERCOBAAN 8

    Menampilkan angka desimal dari % sampai " dan berulang. ( ribuan - + digit !

    :inc)ude ;!ega13.h(ort?061% @8+T:endas!

    ///////////////////////////////void K3%CD,int bi)anganAint ratusan(u)uhansatuanribuan@

    ribuan?bi)angan/1000@ratusan? ,bi)angan - ,ribuan*1000/100@ // !isa) bi)angan?3F1 // 3F1/100? 3(u)uhan?,bi)angan-,ribuan*1000-,ratusan*100/10@ // ,3F1-,3*100/10 // ,3F1-300/10 ? F1/10 ? Fsatuan ? bi)angan - ,(u)uhan*10 - ,ratusan*100- ,ribuan*1000@

    )cd>(utchar,ribuanJ06F0@)cd>(utchar,ratusanJ06F0@)cd>(utchar,(u)uhanJ06F0@

    1"

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    13/15

    )cd>(utchar,satuanJ06F0@G

    void !ain,voidAint a@

    8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@

    hi)e ,1 A

    #or,a?0@a;?3LLL@aJJ A )cd>goto6&,00@

    K3%CD,a@de)a&>!s,50@

    GG

    G

    PERCOBAAN 9

    Menampilkan tulisan FC);A LCD scroll dari kiri ke kanan.

    :inc)ude ;!ega13.h(ort?061% @8+T:endas!

    /////////////////////////void !ain,voidA

    int ai@#)ash unsigned char *(esan@

    8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@

    // 2? 30J B!)h arater , ? J 30 ,30 B!)h barisn&a CD// 13F25H7L013F25H7L013F25H7L013F25H7L013F25H7

    (esan?" C+% CD "@

    1*

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    14/15

    hi)e ,1 A

    #or,a?0@a;30J@aJJ // 30 J !)h arater A #or,i?0@i;?1L@iJJ A )cd>(utchar,(esanaJiO@ G

    de)a&>!s,100@ )cd>c)ear,@ G GG

    PERCOBAAN 1

    Menampilkan tulisan FC);A LCD scroll dari kiri ke kanan.

    :inc)ude ;!ega13.h(ort?061% @8+T:endas!

    /////////////////////////void !ain,voidA

    int ai@#)ash unsigned char *(esan@

    8+T?0600@ // se!ua bit Badi out(ut DD?0644@

    )cd>init,30@

    // 2? 30J B!)h arater , ? J 30 ,30 B!)h barisn&a CD// 13F25H7L013F25H7L013F25H7L013F25H7L013F25H7

    (esan?" C+% CD "@

    1+

  • 7/23/2019 Praktek 6 AVR Display Data Pada LCD

    15/15

    )cd>goto6&,01@

    // 13F25H7L013F25H7L0 )cd>(uts#,"********************"@

    hi)e ,1 A

    #or,a?0@a;?30J@aJJ A

    )cd>goto6&,00@ #or,i?0@i;?1L@iJJ A )cd>(utchar,(esanaJiO@ G

    de)a&>!s,100@G

    GG

    PERCOBAAN 11

    ;uatlah program untuk menampilkan tulisan

    F'3$