You are on page 1of 6

Programming Microcontroller AT89C51

Microcontroller has a function as microprocessor. The different is simplicity of microcontroller that


can stand alone with out any component such ADC and external memory. Microcontroller is a kind
of integrated circuit that be packed as common IC. The main different is the ability to run the
instruction code that is loaded at it's memory. On the other hand, microcontroller is completed with
Arithmetic Logic Unit that can run arithmetic operations. With out a program that was loaded in it's
memory, microcontroller can do nothing.
Microcontroller AT89C51

Microcontroller AT89C51 is a product of Atmel Corp, that belong to MCS51


microcontroller family. This microcontroller has a same architecture with
microcontroller 8031, product of Intel Corp. The specification of microcontroller
AT89C51 are stated below:
- 8 bit data line
- 4K Byte of flash memory
- Maximum clock frequency is 24MHz
- 128 Byte internal Memory
- Four I/O port
- Dual 16 bit timer/counter
Registers of AT89C51

Microcontroller AT89C51 has some registers, registers that explain in this tutorial
are:
- Accumulator
- R0 - R7
Example of Simple Program
Here are two simple listing program in assembly language, The used assembler is asm51.exe

Figure 1. At89c51 Application Circuit for running led and seven segment display.

- Running Led

Figure 2. A photograph of Running Led Circuit.


$mod51
org 00h
jmp mulai
;program dimulai di sini
mulai:
mov r1, #05h
loop:
dec r1
mov a, #01h
mov p1, a

call tunda
kiri:
rl a
mov p1, a
call tunda
cjne a, #80h, kiri
kanan:
rr a
mov p1, a
call tunda
cjne a, #01h, kanan
cjne r1, #00h, loop
ljmp mulai
;
tunda:
mov r4, #02h
ulang:
dec r4
mov r3, #0ffh
tunda1:
dec r3
mov r2, #0ffh
tunda2:
dec r2
cjne r2, #00h, tunda2
cjne r3, #00h, tunda1
cjne r4, #00h, ulang
ret
end
The registers that are used above are r1 to r4, and accumulator too. The port that is used to light
on eight LEDs is P1.

- Displaying a Number Using Seven Segment Display

Figure 3. A Photograph of Seven Segment Displaying Circuit.

$mod51
org 00h
jmp mulai
mulai:
mov r6, #00h
mov a, #00h

ulang:
mov r6, p2
mov p1, r6
lcall tampil1
mov p2, #01000000b
lcall tunda
lcall tampil2
mov p2, #10000000b
lcall tunda
jmp ulang
tampil1:mov a, #00h
clr c
mov b, #10
mov a, r6
div ab
cjne a, #00h, ke_1
ljmp nol1
ke_1:
cjne a, #01h, ke_2
ljmp siji
ke_2:
cjne a, #02h, ke_3
ljmp loro
ke_3:
cjne a, #03h, ke_4
ljmp telu
ke_4:
cjne a, #04h, ke_5
ljmp papat
ke_5:
cjne a, #05h, ke_6
ljmp lima
ke_6:
cjne a, #06h, ke_7
ljmp enem
ke_7:
cjne a, #07h, ke_8
ljmp pitu
ke_8:
cjne a, #08h, ke_9
ljmp wolu
ke_9:
cjne a, #09h, keluar
ljmp sanga
keluar: ret
tampil2:mov a, #00h
clr c
mov a, b
cjne a, #00h, ke_12
ljmp nol
ke_12: cjne a, #01h, ke_22
ljmp siji
ke_22:
cjne a, #02h, ke_32
ljmp loro
ke_32:
cjne a, #03h, ke_42
acall telu

ke_42:
cjne a, #04h, ke_52
ljmp papat
ke_52:
cjne a, #05h, ke_62
ljmp lima
ke_62:
cjne a, #06h, ke_72
ljmp enem
ke_72:
cjne a, #07h, ke_82
ljmp pitu
ke_82:
cjne a, #08h, ke_92
ljmp wolu
ke_92:
cjne a, #09h, keluar2
ljmp sanga
keluar2:ret
;
a
; f
b
;
g
; e
c
;
d
;0gfedcba
nol1:
mov p0, #00h
ret
nol: mov p0, #00111111b
ret
siji: mov p0, #00000110b
ret
loro:
mov p0, #01011011b
ret
telu:
mov p0, #01001111b
ret
papat:
mov p0, #01100110b
ret
lima:
mov p0, #01101101b
ret
enem:
mov p0, #01111101b
ret
pitu:
mov p0, #00000111b
ret
wolu:
mov p0, #01111111b
ret
sanga:
mov p0, #01101111b
ret
tunda: mov r5, #255
kurang: dec r5
cjne r5, #00h, kurang
ret
end
The listing program above, has a function to display two binary datum that saved in r6. The used
display are two seven segment common cathode LED. Datum at a segment to g are attached from
P0.0 -P0.6. For sweeping digit once and second we use P2.7 and p2.8

You might also like