Program Assembly Jam / Clock
Part 1
second equ 30h
secondTens equ 31h
secondOnes equ 32h
counter20 equ 33h
;
Org 00h
sjmp Start
Org 0bh
Ljmp Interrupt_Timer0
;
Start: mov P3,#11111111b
mov second,#0
call InitTimer
;
Forever:
call ClockDisplay
sjmp Forever
;
Interrupt_Timer0:
mov tl0,#0b0h
mov th0,#03ch
djnz Counter20, EndInterrupt
mov Counter20,#20
call DoClock
EndInterrupt:
reti;
DoClock:
inc second
mov A,second
cjne A,#60,Update
mov second,#0
Update: mov A,second
mov B,#10
DIV AB
mov SecondTens,A
mov SecondOnes,B
ret
;
ClockDisplay:
Setb P2.7
Mov DPTR,#Decoder7Segmen
mov A,secondOnes
Movc A,@A+DPTR
Mov P0,A
Clr P2.7
call delay
;
Setb P2.7
Mov DPTR,#Decoder7Segmen
mov A,secondTens
Movc A,@A+DPTR
Mov P0,A
Clr P2.6
call delay
ret
;
InitTimer:
mov TMOD,#00000001b
mov tl0,#0b0h
mov th0,#03ch
setb ET0 ;Enable Timer 0 Interrupt
setb EA ;Master Interrupt Enable
setb TR0 ;Clock start running
ret
;
;=============================================
;subroutine delay created to rise delay time
;=============================================
delay: mov R1,#255
del1: mov R2,#255
del2: djnz R2,del2
djnz R1,del1
ret
;========================================
; L O O K U P T A B L E
; Decode to Seven Segmen -> g f e d c b a
;========================================
Decoder7Segmen:
DB 11000000b,11111001b,10100100b,10110000b,10011001b
DB 10010010b,10000010b,11111000b,10000000b,10010000b;
End
Part 2
Counter20 equ 70h
detik equ 71h
menit equ 72h
jam equ 73h
DetikSatuan equ 74h
DetikPuluhan equ 75h
MenitSatuan equ 76h
MenitPuluhan equ 77h
JamSatuan equ 78h
JamPuluhan equ 79h
titik equ 7Ah
hitungan equ 7Bh
cacahan equ 7Ch
Org 0h
sjmp Start
Org 0bh
Ljmp Interrupt_Timer0
;================================
;set tampilan awal
;================================
Start:
; mov P3,#11111111b
; mov p2,#11111111b
mov detik,#0
mov menit,#0
mov jam,#0
; mov titik,#0
call InitTimer
;=================================
;Program utama
;=================================
Forever:
call ClockDisplay
sjmp Forever
;=================================
;aktifkan timer
;=================================
InitTimer:
mov TMOD,#00000001b
mov tl0,#0b0h
mov th0,#03ch
setb ET0 ;Enable Timer 0 Interrupt
setb EA ;Master Interrupt Enable
setb TR0 ;Clock start running
ret
;=================================
;jika terjadi interup dari timer
;=================================
Interrupt_Timer0:
mov tl0,#0b0h
mov th0,#03ch
djnz Counter20, EndInterrupt
mov Counter20,#20
call DoClock
EndInterrupt:
reti
;====================================
;program jam
;====================================
DoClock:
inc detik
mov A,detik
cjne A,#60,Update
mov detik,#0
OneMinute:
inc menit
mov A,#60
cjne A,menit,Update
mov menit,#0
mov detik,#0
OneHour:
inc jam
mov A,#24
cjne A,jam,Update
mov jam,#0
mov menit,#0
mov detik,#0
update:
mov A,detik
mov B,#10
DIV AB
mov DetikPuluhan,A
mov DetikSatuan,B
mov A,menit
mov B,#10
DIV AB
mov MenitPuluhan,A
mov MenitSatuan,B
mov A,jam
mov B,#10
DIV AB
mov JamPuluhan,A
mov JamSatuan,B
ret
;=================================
; menampilkan ke 7-segment
;=================================
ClockDisplay:
mov p2,#0ffh
Mov DPTR,#Decoder7Segmen
mov A,JamPuluhan
Movc A,@A+DPTR
Mov P0,A
Clr P2.6
call delay
setb p2.6
Mov DPTR,#Decoder7Segmen
mov A,JamSatuan
Movc A,@A+DPTR
Mov P0,A
Clr P2.5
call delay
ret
;=============================================
;subroutine delay created to rise delay time
;=============================================
delay: mov R0,#0fh
delay1: mov R2,#0fh
djnz R2,$
djnz R0,delay1
ret
;========================================
; L O O K U P T A B L E
; Decode to Seven Segmen -> g f e d c b a
;========================================
Decoder7Segmen: DB 11000000b,11111001b,10100100b,10110000b,10011001b, 10010010b,10000010b,11111000b,10000000b,10010000b
End
Semoga bermanfaat & selamat belajar!
Netizen
maksudnya part 1 sama part 2 bagaimana ya? apakah itu beda fungsinya ?
saya baru belajar bahasa asm maaf
hai FaruhanSan .. yup betul, itu beda experimental. part 1 dan part 2 tidak ada hubungannya, jadi hanya kode latihan saja.
Saat itu, guru kami sekedar memastikan bahwa apakah anak didiknya betul-betul memahami logika kodenya, maka beliau memberikan tugas kepada kami untuk bebas berkreasi membuat varian output yang berbeda menggunakan konsep yang sama.
kalau itu di program ada bagian 7segment tetapi di gambar skematik itu menggunakan lcd display, jadi nanti outputnya bagaimana ya? apakah program tersebut bisa digunakan untuk output 7segment?
- Edited
halo FaruhanSan tentu saja, LCD yang ditunjukkan skematik di atas kan tersusun dari beberapa 7 segmen, sehingga dapat menampilkan beberapa karakter.. jadi nanti tinggal di sesuaikan saja dengan kolektor 7 segment kamu, apakah common anode atau common cathode. Tentu jika kamu ingin menampilkan sebuah kata maka tidak cukup hanya menggunakan satu 7 segment, kamu harus menyusunnya minimal tiga 7 segment.