$MOD51
Digit1			EQU	1
Digit2			EQU	2
ROM			EQU	2000H
BufferSize		EQU	05
Tabel_segmen		EQU	20H

	Org	ROM			;Reset Vector
	Ajmp	Start			;
	Org	ROM+3H			;External Interrupt 0 Vector
	Reti				;
	Org	ROM+0BH			;Timer 0 Interrupt Vector
	Reti				;
	Org	ROM+13H			;External Interrupt 1 Vector
	Reti				;
	Org	ROM+1BH			;Timer 1 Interrupt Vector
	Reti				;
	Org	ROM+23H			;Serial Interrupt Vector
	Reti

Start:
	Acall	IsiTabel_segmen		;Isi tabel seven segmen

Loop:
	Mov	A,#Digit1		;Kirim digit 1
	Acall	KirimSegmen		;
	Clr	P3.2			;aktifkan common 1
	Acall	Delay_Segmen		;
	Mov	P3,#0FFH		;matikan segmen
	Mov	A,#Digit2		;Kirim digit 2
	Acall	KirimSegmen		;
	Clr	P3.3			;aktifkan common 2
	Acall	Delay_Segmen	
	Mov	P3,#0FFH		;matikan segmen
	Ajmp	Loop			;lakukan kembali

;Bagian konversi BCD ke seven segmen
KirimSegmen:
	Mov	R0,#Tabel_segmen
	Add	A,R0
	Mov	R0,A
	Mov	A,@R0
	Mov	P1,A
	Ret	
	
Delay_Segmen:
	Push	B
	Mov	B,#04H

LoopDelay:
	Push	B
	Mov	B,#0FFH
Loop2Delay:
        Djnz    B,Loop2Delay
	Pop	B
	Djnz	B,LoopDelay
	Pop	B
	Ret

IsiTabel_segmen:
	Mov	R0,#Tabel_segmen
	Mov	@R0,#11000000b	;0
	Inc	R0
	Mov	@R0,#11111001b	;1
	Inc	R0
	Mov	@R0,#10100100b	;2
	Inc	R0
	Mov	@R0,#10110000b	;3
	Inc	R0
	Mov	@R0,#10011001b	;4
	Inc	R0
	Mov	@R0,#10010010b	;5
	Inc	R0
	Mov	@R0,#10000011b	;6
	Inc	R0
	Mov	@R0,#11111000b	;7
	Inc	R0
	Mov	@R0,#10000000b	;8
	Inc	R0
	Mov	@R0,#10010000b	;9
	Inc	R0
	Mov	@R0,#11111111b
	Ret
        END
