Tutorial Microcontroller MCS-51 ATMEL ISP
 

 

Super MCS51 Trainer

Standart MCS51 Trainer

Standart AVR Trainer

Programmer USBASP

Standart ARM Trainer

 

 

Percobaan Keypad 4x4

1. Percobaan Keypad dengan display LED

Pada percobaan ini keypad terhubung ke PORTB dan display ke LED, setiap penekanan tombol pada keypad maka akan ditunjukkan perubahan kondisi pada LED.

#include <mega8535.h>
#include <delay.h>
#include <stdio.h>

// Declare your global variables here
unsigned char dt, dtkey;
void detek_key(void);
void main(void)
{
while (1)
{
// Place your code here
detek_key();
PORTC=dtkey;
delay_ms(5);
};
}

void detek_key(void) {
PORTB.4=0;
dt=(~PINB & 0x0F);
switch (dt)
{
case 1: dtkey=0x1;
break;
case 2: dtkey=0x4;
break;
case 4: dtkey=0x7;
break;
case 8: dtkey=0xa;
break;
};
PORTB.4=1; PORTB.5=0;
dt=(~PINB & 0x0F);
switch (dt) {
case 1: dtkey=0x2;
break;
case 2: dtkey=0x5;
break;
case 4: dtkey=0x8;
break;
case 8: dtkey=0x0;
break;
};
PORTB.5=1; PORTB.6=0;
dt=(~PINB & 0x0F);
switch (dt) {
case 1: dtkey=0x3;
break;
case 2: dtkey=0x6;
break;
case 4: dtkey=0x9;
break;
case 8: dtkey=0xb;
break;
};
PORTB.6=1; PORTD.7=0;
dt=(~PINB & 0x0F);
switch (dt)
{
case 1: dtkey=0xc;
break;
case 2: dtkey=0xd;
break;
case 4: dtkey=0xe;
break;
case 8: dtkey=0xf;
break;
};
PORTB.7=1;
}

NEXT