You are on page 1of 2

LAPORAN MIKROKONTROLER KEYPAD PROGRAM:

#include <mega128.h> #include <delay.h> #include "lcd.h" /////////// int baca_keypad() { int a,tombol; PORTC= 0xff; tombol=0xff; // jika tdk ada tombol ditekan PORTC.3 = 0; delay_ms(1); a = PINC; // baris 1 if if if if (a==0x77) (a==0xb7) (a==0xd7) (a==0xe7) {tombol=1; goto selesai;} {tombol=2; goto selesai;} {tombol=3; goto selesai;} {tombol=:-0x30; goto selesai;} //baris 1

PORTC.2=0; PORTC.3=1; delay_ms(1); a = PINC; // baris 2 if if if if (a==0x7b) (a==0xbb) (a==0xdb) (a==0xeb) {tombol=4; goto selesai;} {tombol=5; goto selesai;} {tombol=6; goto selesai;} {tombol=x-0x30; goto selesai;}

PORTC.1=0; PORTC.2=1; delay_ms(1); a = PINC; // baris 3 if if if if (a==0x7d) (a==0xbd) (a==0xdd) (a==0xed) {tombol=7; goto selesai;} {tombol=8; goto selesai;} {tombol=9; goto selesai;} {tombol=--0x30; goto selesai;}

PORTC.0=0; PORTC.1=1; delay_ms(1); a = PINC; // baris 4 if (a==0x7e) {tombol=14; goto selesai;} if (a==0xbe) {tombol=0; goto selesai;} if (a==0xde) {tombol==-0x30; goto selesai;} if (a==0xee) tombol=+-0x30; selesai: return(tombol); }

////////////////// void main(void) { // Declare your local variables here int nilai; PORTA=0xff; // semua bit jadi output DDRA=0xff; PORTD=0x00; // out LED DDRD=0xFF; // Port C initialization // d7=In d6=In d5=In d4=In d3=Out d2=Out d1=Out d0=Out PORTC=0x00; DDRC=0x0f; lcd_init(); lcd_cursoroff(); while (1) { nilai= baca_keypad(); PORTD=nilai; if(nilai != 0xff) lcd_putchar(nilai+0x30); delay_ms(100); } }

You might also like