Berikut programnya:
Org 0h
nop
Mulai: MOV A,P3
CEK: CJNE A,#0FEH,CEK1 ;cek tombol1 (P3.0)
CALL LED_kanan_kiri
SJMP MULAI
CEK1: CJNE A,#0FDH,CEK2 ;cek tombol2 (P3.1)
CALL LED_jalan_dua
SJMP MULAI
CEK2: CJNE A,#0FBH,MULAI ;cek tombol3 (P3.2)
CALL LED_jalan_satu_satu
SJMP MULAI
LED_kanan_kiri:
clr P1.3
clr P1.4
call delay
clr P1.2
clr P1.5
call delay
clr P1.1
clr P1.6
call delay
clr P1.0
clr P1.7
call delay
call delay
call delay
setb P1.0
setb P1.7
call delay
setb P1.1
setb P1.6
call delay
setb P1.2
setb P1.5
call delay
setb P1.3
setb P1.4
call delay
call delay
mov R5,#2
ret
LED_jalan_dua:
Mov R2,#6
Mov A,#11111100B ; Masukkan data 111111100B ke Accumulator
loop1: Mov P1,A ; keluarkan isi Accumulator ke Port 1
RL A ; panggil sub routine Delay
call Delay ; Rotate Accumulator left
DJNZ R2,loop1 ; --<- b7-b6-b5-b4-b3-b2-b1-b0 <-----
MOV R2,#6 ; |-------------->-------------------|
loop2: Mov P1,A ; keluarkan isi Accumulator ke Port 1
RR A
call Delay
DJNZ R2,loop2
djnz R5,LED_jalan_dua
MOV A,#0FFH
MOV P1,A
ret
LED_jalan_satu_satu:
mov dptr,#LED_satu
mov R4,#36
next1: clr A
Movc A,@A+DPTR
cpl A
Mov P1,A
inc dptr
call Delay
djnz R4,next1
call delay
call delay
call delay
mov dptr,#LED_satu
mov R4,#36
next2: mov A,R4
Movc A,@A+DPTR
cpl A
Mov P1,A
call Delay
djnz R4,next2
mov P1,#0FFh
call delay
call delay
call delay
MOV R5,#2
ret
;---------------------------------
; sub routine delay
;---------------------------------
Delay: DJNZ R3,delay ; R3=R3-1 bila <> 0 ke label delay
Djnz R1,Delay ; R1=R1-1 bila <> 0 ke label delay
Ret ; Kembali ke alamat setelah perintah
; 'call Delay'
;-----------------------------------------------------
LED_SATU:
DB 01h,02H,04H,08H,10H,20H,40H,80H
DB 81h,82h,84h,88h,90h,0B0h,0C0h
DB 0C1h,0C2h,0C4h,0C8h,0D0h,0E0h
DB 0E1h,0E2h,0E4h,0E8h,0F0h
DB 0F1h,0F2h,0F4h,0F8h
DB 0F9h,0FBh,0FCh
DB 0FDH,0FEh
DB 0FFh
End
Selamat Mencoba!
kox error gan programnya..
BalasHapus