logo

Select Sidearea

Populate the sidearea with useful widgets. Itโ€™s simple to add images, categories, latest post, social media icon links, tag clouds, and more.
[email protected]
+1234567890
 

7.2. Percobaan scan data keypad 4×4 dan mengeluarkan ke LCD

Pada percobaan ini, akan dilakukan scan data keypad dan mengeluarkan data ke LCD Karakter.
Untuk melakukan percobaan ini lakukan beberapa langkah sebagai berikut:
4. Pasang jumper EN_LCD
5. Buka jumper pada EN_DAC, apabila sedang terpasang
6. Hubungkan modul Microcontroller Trainer dengan power supply +5V
7. Hubungkan modul Microcontroller Trainer dengan rangkaian programmer
8. Buka Program M-IDE Studio for MCS-51, sebagai editor dan compiler program
9. Ketik program berikut ini:(download file prog72a.asm)

           col4 bit P2.0
           col3 bit P2.1
           col2 bit P2.2
           col1 bit P2.3
           row1 bit P2.4 
           row2 bit P2.5
           row3 bit P2.6
           row4 bit P2.7
           ;
           keydata equ 70h
           keybounc equ 71h
           keyport equ P2
           org 0h
           mov P2,#11111111b
           call Init_LCD
start: call keypad4x4 ;calling subroutine keypad4x4
           Mov A,keydata ;A = keydata 
           Cjne A,#0FFh,WrLCD;
           sjmp start ;LOOPING FOREVER PART 1
           ;
WrLCD: Mov R1,#80h ;Pick DDRAM 1st row and 1st col
           call write_inst
           Mov R1,#30h
           Add A,R1
           Mov R1,A
           call write_data ;write data
           Sjmp start ;LOOPING FOREVER PART 2;
           ;
           Init_lcd:
           mov r1,#00000001b ;Display clear
           call write_inst ;
           mov r1,#00111000b ;Function set, Data 8 bit,2 line font 5x7
           call write_inst ;
           mov r1,#00001100b ;Display on, cursor off,cursor blink off
           call write_inst
           mov r1,#00000110b ;Entry mode, Set increment
           call write_inst
           ret
           ;
Write_inst:
           clr P3.6 ; P3.6 = RS =0 
           mov P0,R1 ; P0 = D7 s/d D0 = R1
           setb P3.7 ; P3.7 =EN = 1 
           call delay ; call delay time
           clr P3.7 ; P3.7 =EN = 0
           ret
           ;
Write_data:
           setb P3.6 ; P3.6 = RS =1
           mov P0,R1 ; P0 = D7 s/d D0 = R1
           setb P3.7 ; P3.7 =EN = 1
           call delay ; call delay time
           call delay ; call delay time
           clr p3.7 ; P3.7 =EN = 0
           ret
           ;
           ;====================================
           ; subroutine scan keypad 4x4
           ;====================================
Keypad4x4:
           mov keybounc,#50 ;keybounc = 50 
           mov keyport,#0FFh ;keyport=P2= FF
           clr col4 ;col4 = 0
           ;
           keyCOR: jb row4,keyMEN ; Key COR
           djnz keybounc,KeyCOR
           mov keydata,#0Ah ;Data Output
           ret 
           ;
           keyMEN: jb row3,keyUpA ; Key MEN
           djnz keybounc,keyMEN
           mov keydata,#0bh ;Data Output
           ret
keyUpA:            
           jb row2,keyDnA ; Key Up Arrow
           djnz keybounc,keyUpA
           mov keydata,#0ch ;Data Output
           ret
           ;
keyDnA: 
           jb row1,key3 ; Key Down Arrow
           djnz keybounc,keyDnA
           mov keydata,#0dh ;Data Output
           ret
;==========================================
key3: setb col4
           clr col3
           jb row4,key6
           djnz keybounc,key3 ; Key 3
           mov keydata,#03h ;Data Output
           ret 
           ;
key6: jb row3,key9
           djnz keybounc,key6 ; Key 6
           mov keydata,#06h ;Data Output
           ret
           ;
key9: jb row2,keyENT
           djnz keybounc,key9 ; Key 9
           mov keydata,#09h ;Data Output
           ret
           ;
keyENT: jb row1,key2
           djnz keybounc,keyENT ; Key ENT
           mov keydata,#0eh ;Data Output
           ret
           ;============================================
key2: setb col3
           clr col2
           jb row4,key5
           djnz keybounc,key2
           mov keydata,#02h ;Data Output
           ret 
           ;
key5: jb row3,key8
           djnz keybounc,key5
           mov keydata,#05h ; Data Output
           ret 
           ;
key8: jb row2,key0
           djnz keybounc,key8
           mov keydata,#08h ;Data Output
           ret
           ;
key0: jb row1,key1
           djnz keybounc,key0
           mov keydata,#00h ;Data Output
           ret
;==============================================
key1: setb col2
           clr col1
           jb row4,key4
           djnz keybounc,key1
           mov keydata,#01h ;Data Output
           ret 
           ;
key4: jb row3,key7
           djnz keybounc,key4
           mov keydata,#04h ;Data Output
           ret
           ;
key7: jb row2,keyCAN
           djnz keybounc,key7
           mov keydata,#07h ;Data Output
           ret
           ;
keyCAN: jb row1,Nokey
           djnz keybounc,keyCAN
           mov keydata,#0Fh ;Data Output
           ret
           ;
Nokey: mov keydata,#0FFh 
           ret
;================================
;The end of Keypad 4x4 subroutine
;================================
delay: mov R0,#0
delay1: mov R2,#50
           djnz R2,$
           djnz R0,delay1
           ret
           ;
           end

5. Simpanlah program yang anda ketik dan beri nama : prog72a.asm
6. Pada program MIDE tersebut pilih Build /F9 atau untuk melakukan kompilasi program dari *.asm ke *.hex.
7. Lakukan pemrograman mikrokontroller dengan menggunakan Program ISP Software ( Lihat Petunjuk Penggunaan)
8. Lakukan pengamatan pada LCD
9. Lakukan modifikasi pada program tersebut untuk menampilkan data keypad ke lokasi DDRAM LCD:

No
Lokasi Display LCD Karakter Data Keypad
1
Baris 2 Kolom 2
2
Baris 2 Kolom 16

10. Lakukan modifikasi pada rangkaian tersebut untuk menampilan data keypad ke display 7 segmen sesuai dengan percobaan 3.