Anda di halaman 1dari 2

Praktikum Lab. Teknik I - Pebi Yudha K. / Wisnu Budiman W.

http://pebi.comze.com

Input/Output Port pada AT89C51


Resistor
100 Ohm
C2

30pF

C1

30pF

30pF

30pF

X1

U1
19

12MHz

Crystal 12Mhz
R1

18

XTAL1

XTAL2

RST

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7

220

Resistor
220 Ohm

C3
29
30
31

10uF

10uF
R2

Resistor 10k

10k

1
2
3
4
5
6
7
8

PSEN
ALE
EA

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD

39
38
37
36
35
34
33
32
21
22
23
24
25
26
27
28

AT89C51

10
11
12
13
14
15
16
17

AT89C51

Contoh Program
Geser Kiri shl.c
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019

#include <at89x51.h>
void delay(int time_ms);
int main(void)
{
unsigned short int led = 0x01;
for (;;)
{
P0 = ~led;
if (led == 0x80)
led = 0x01;
else
led = led * 2;
delay(300);
}

020
021
022
023
024
025
026
027
028
029
030
031
032
033
034

return 0;
}
void delay(int time_ms)
{
int i, j;
for (i = 0; i < time_ms; i++)
{
for (j = 0; j < 1000; j++) {}
}
return;
}

Geser Kanan shr.c


001 #include <at89x51.h>
002

Praktikum Lab. Teknik I - Pebi Yudha K. / Wisnu Budiman W.


http://pebi.comze.com
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034

void delay(int time_ms);


int main(void)
{
unsigned short int led = 0x80;
for (;;)
{
P0 = ~led;
if (led == 0x01)
led = 0x80;
else
led = led / 2;
delay(300);
}
return 0;
}
void delay(int time_ms)
{
int i, j;
for (i = 0; i < time_ms; i++)
{
for (j = 0; j < 1000; j++) { }
}
return;
}

Penekanan Tombol 1 tombol01.c


001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023

#include <at89x51.h>
void delay(int time_ms);
int main(void)
{
unsigned short int btn;
for (;;)
{
btn = P1;
P0 = btn;
delay(10);
}
return 0;
}
void delay(int time_ms)
{
int i, j;

024
025
027
028
029
030
031 }

for (i = 0; i < time_ms; i++)


{
for (j = 0; j < 1000; j++) { }
}
return;

Penekanan Tombol 2 tombol02.c


001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047

#include <at89x51.h>
void delay(int time_ms);
int main(void)
{
unsigned short int btn, led;
led = 0x01;
for (;;)
{
btn = P1;
if (btn == 0x7f)
{
if (led == 0x80)
led = 0x01;
else
led = led * 2;
}
else if (btn == 0xbf)
{
if (led == 0x01)
led = 0x80;
else
led = led / 2;
}
P0 = ~led;
delay(10);
}
return 0;
}
void delay(int time_ms)
{
int i, j;
for (i = 0; i < time_ms; i++)
{
for (j = 0; j < 1000; j++) { }
}
return;
}