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
Hope this is useful & happy learning!
Netizens
what do you mean by part 1 and part 2? do they have different functions?
I'm just learning ASM, sorry
hi FaruhanSan .. yup that's right, it's different from experimental. part 1 and part 2 have nothing to do, so it's just a practice code.
At that time, our teacher just wanted to make sure that his students really understood the logic of the code, so he gave us the task of being free to create different output variants using the same concept.
If in the program there is a 7segment section but in the schematic image it uses an LCD display, so how will the output be? Can the program be used for 7segment output?
- Edited
hello FaruhanSan of course, the LCD shown in the schematic above is composed of several 7 segments, so it can display several characters.. so later just adjust it to your 7 segment collector, whether common anode or common cathode. Of course if you want to display a word then it is not enough to use just one 7 segment, you have to arrange at least three 7 segments.