;###############################################
;PROGRAM FOR INTERFACING RTC WITH AT89S8252
;author: Tapan Rout
;###############################################
CE EQU P1.7 ;
IO EQU P3.4
SCLK EQU P1.6
com_adr equ 0fe00h ;LCD COMMAND REGISTER ADDRESS
dat_adr equ 0fe01h ;LCD DATA REGISTER ADDRESS
ORG 0000H
AJMP MAIN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;MAIN PROGRAM STARTS HERE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ORG 030H
MAIN:
ACALL LCD_INIT ;initializing LCD
MOV R1,#8EH ; WRITE PROTECT MODE
MOV R0,#0
LCALL WRITE
MOV R1,#90H ; TRICKLE CHARGER REGISTER AND DIODE SELECT
MOV R0,#0ABH ;2 DIODES, 8K
ACALL WRITE
MOV R1,#80H ; WRITE SECONDS
MOV R0,#0
ACALL WRITE
MOV R1,#82H ; WRITE MINUTES
MOV R0,#05H
ACALL WRITE
MOV R1,#84H ;WRITE HOURS
MOV R0,#11H
CALL WRITE
MOV R1,#86H ; WRITE DATE : 27
MOV R0,#27H
ACALL WRITE
MOV R1,#88H ;WRITE MONTH : 9(SEPTEMBER)
MOV R0,#9
ACALL WRITE
MOV R1,#8CH ; WRITE YEAR : 09 (2009)
MOV R0,#09H
ACALL WRITE
;/*
mov scon,#50h
mov tmod,#20h
mov th1,#0fdh
MOV TL1,0FDH
mov tcon,#45h
setb tr1 ;*/
SS:
setb TI
SS1: MOV R1,#81H ; READ SECONDS
CALL READ
MOV 20H,R0
MOV R1,#83H ; READ MINUTES
CALL READ
MOV 21H,R0
MOV R1,#85H ; READ HOUR
CALL READ
MOV 22H,R0
MOV R1,#87H ; READ DATE
CALL READ
MOV 23H,R0
MOV R1,#89H ; READ MONTH
CALL READ
MOV 24H,R0
MOV R1,#8DH ; READ YEAR
CALL READ
MOV 25H,R0
DIS:
MOV A,21H ;read minutes and display in lcd
PUSH ACC
MOV A,#86H
ACALL COMNWRT
ACALL DELAY
MOV A,#':'
ACALL DATAWRT
ACALL DELAY
POP ACC
ACALL ASCIICONV
MOV A,22H ;rad hours and display in lcd
PUSH ACC
MOV A,#84H
ACALL COMNWRT
ACALL DELAY
POP ACC
ACALL ASCIICONV
MOV A,22H
JB ACC.5,GO ;check the condition for AM or PM
MOV A,#8AH
ACALL COMNWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
SJMP GO1
GO: MOV A,#8AH
ACALL COMNWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
GO1:
JNB RI,SS1
CLR RI
AJMP SS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;WRITE OPERATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WRITE:
CLR SCLK ;CLEAR SCLK LINE
NOP
NOP
SETB CE ; SET CE HIGH FOR WRITE OPERATION
NOP
MOV A,R1 ;LOAD THE ADDRESS
MOV R2,#8 ;COUNT =8
WRITE_1: RRC A ;
MOV IO,C ; SEND LSB FIRST AND THEN CONTINUE
NOP
NOP
SETB SCLK
NOP
NOP
CLR SCLK
DJNZ R2,WRITE_1
NOP
NOP
;*************
MOV A,R0 ;LOAD THE DATA
MOV R2,#8 ;SET COUNT =8
WRITE_2: RRC A ;
MOV IO,C
NOP
NOP
SETB SCLK
NOP
NOP
CLR SCLK
DJNZ R2,WRITE_2
NOP
NOP
CLR CE
NOP
NOP
RET
;**********************************************/
;READ OPERAION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
READ:
SETB CE ;SET CE
MOV A,R1 ;LOAD ADDRESS FIRST
MOV R2,#8
READ_1: RRC A
MOV IO,C ;MOVE THE ADDRESS THROUGH IO PIN
NOP
NOP
SETB SCLK ;SET SCLK
NOP
NOP
CLR SCLK ;CLEAR SCLK FOR WRITE OPERATION
DJNZ R2,READ_1
NOP
NOP
SETB IO
CLR A
CLR C
MOV R2,#8
READ_2: MOV C,IO
RRC A
NOP
NOP
SETB SCLK
NOP
NOP
CLR SCLK
NOP
NOP
DJNZ R2,READ_2
MOV R0,A
; ANL A, #7FH
CLR CE
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;LCD INITIALIZATION
;...............................................
LCD_INIT:
MOV A,#38H
ACALL COMNWRT
ACALL DELAY
MOV A,#0CH
ACALL COMNWRT
ACALL DELAY
MOV A,#01H
ACALL COMNWRT
ACALL DELAY
MOV A,#06H
ACALL COMNWRT
ACALL DELAY
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;
COMNWRT:
MOV DPTR,#COM_ADR
MOVX @DPTR,A
NOP
NOP
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DATAWRT:
MOV DPTR,#DAT_ADR
MOVX @DPTR,A
NOP
NOP
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ASCIICONV:
PUSH ACC
; MOV A,R0
SWAP A
ANL A,#0FH
ORL A,#30H
ACALL DATAWRT
ACALL DELAY
; MOV A,R0
POP ACC
ANL A,#0FH
ORL A,#30H
ACALL DATAWRT
ACALL DELAY
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
DELAY:
MOV R3,#200
BACK: MOV R4,#255
DJNZ R4,$
DJNZ R3,BACK
RET
END