******************************************************************************
*		PROGRAM PENAMPIL JAM DENGAN RTC 1287			     
*		- Menampilkan jam setiap detik ke serial port DST-51	     
* Disain oleh:
*	Paulus Andi Nalwan, ST
*	electronic@sby.centrin.net.id
*
*	DELTA ELECTRONIC
*	Kompleks Ruko Manyar Megah Indah Plaza D-22
*	Ngagel Jaya Selatan
*	Surabaya 60284
*	Phone: 62-31-5020210
*	Fax: 62-31-5054561
*	http://www.delta-electronic.com
******************************************************************************

;RTC-1287 Routines
;Alamat RTC harus diset pada DPTR terlebih dahulu
;Interrupt harus diaktifkan apabila ingin alarm interrupt

Kalender_Display	EQU	0441H
;Display_Waktu		EQU	04A5H
ASCII_Out	EQU	197H
Serial_Out	EQU	1C8H
Delay_5mS		EQU	0180H
HexASCII2		EQU	00FAH

Init_LCD	EQU	237H
Kirim_Karakter	EQU	295H
PosisiAwal_LCD	EQU	216H

Alamat_RTC	EQU	6000H
RegA		EQU	0AH
RegB		EQU	0BH
RegC		EQU	0CH
RegD		EQU	0DH
Detik		EQU	00H
Detik_Alarm	EQU	01H
Menit		EQU	02H
Menit_Alarm	EQU	03H
Jam		EQU	04H
Jam_Alarm	EQU	05H
Hari		EQU	06H
Tanggal		EQU	07H
Bulan		EQU	08H
Tahun		EQU	09H

	Org	2000H			;Reset Vector
	Ajmp	Start			;
	Org	2003H			;External Interrupt 0 Vector
	Reti				;
	Org	200BH			;Timer 0 Interrupt Vector
	Reti				;
	Org	2013H			;External Interrupt 1 Vector
	Reti				;
	Org	201BH			;Timer 1 Interrupt Vector
	Reti				;
	Org	2023H			;Serial Interrupt Vector
	Reti				;

Start:
	Lcall	Init_LCD
	Mov	DPTR,#Alamat_RTC+RegA	;Aktifkan osilator
	Mov	A,#20H			;
	Movx	@DPTR,A			;
	Inc	DPTR			;Update Interrupt aktif, Mode 24 Jam
	Mov	A,#12H			;Output BCD Data
	Movx	@DPTR,A			;

Loop:
	Mov	DPTR,#Alamat_RTC+RegC	;Periksa Flag IRQ
	Movx	A,@DPTR			;
	ANL	A,#080H			;
	Jnb	A.7,Loop		;Tidak ada flag, loop
	Clr	A.7			;Ada Flag, Clear Flag
	Movx	@DPTR,A			;
	Mov	DPTR,#Alamat_RTC	;Displaykan waktu
	Lcall	Display_Waktu		;
	Ajmp	Loop

Display_Waktu:         
	Lcall 	Clrscr                        
        Lcall 	Clrscr                        
	Lcall	Ambil_Jam
;	Lcall	ASCII_Out
	Lcall	KirimASCII_LCD	 
        Mov   	A,#03AH                        
;        Lcall 	Serial_Out                        
	Lcall	Kirim_Karakter
	Lcall	Ambil_Menit
;	Lcall	ASCII_Out
	Lcall	KirimASCII_LCD	 
        Mov   	A,#03AH                        
	Lcall	Kirim_Karakter
;        Lcall 	Serial_Out                        
	Lcall	Ambil_Detik
;	Lcall	ASCII_Out
	Lcall	KirimASCII_LCD
        RET                                  

Clrscr:
	Push  	A                           
        Mov   	A,#00DH                        
;        Lcall 	Serial_Out                        
	Lcall	PosisiAwal_LCD 
        Lcall 	Delay_5mS                       
        Lcall 	Delay_5mS                       
        Pop   	A                           
        Ret                                  

Ambil_Jam:
	Mov	DPL,#Jam
	Mov	A,#00H
	Movc	A,@A+DPTR
	Ret

Ambil_detik:
	Mov	DPL,#detik
	Mov	A,#00H
	Movc	A,@A+DPTR
	Ret

Ambil_Menit:
	Mov	DPL,#Menit
	Mov	A,#00H
	Movc	A,@A+DPTR
	Ret

KirimASCII_LCD:
	Lcall	HexASCII2
	Lcall	Kirim_Karakter
	Mov	A,B
	Lcall	Kirim_Karakter
	Ret