Professional Documents
Culture Documents
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
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.
$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