Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

rtc ds 1302 code needed ( RTC doesn't count)

Status
Not open for further replies.

tapan.entc

Newbie level 6
Joined
Dec 25, 2009
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
bhubaneswar, India
Activity points
1,393
rtc ds 1302 code

I HAVE WRITTEN ASM CODE FOR DS 1302.
I HAVE WRITE TIME TO RTC REGISTER AND READIND THE TIME WHICH IS CORRECT.

BUT THE PROBLEM IS THE TIME IS NOT INCREASING...

CAN ANY ONE HELP ME???
 

rtc ds 1302 code

Hi,
At address 00H(address 0), bit 7 is CH (clock halt). Make sure that you have cleared this bit. Unless you do so, time is not counted. Once cleared, your problem should be solved.
Hope this helps.
Tahmid.
 

Re: rtc ds 1302 code

Hi Tahmid
Thanks for reply.
First i have given 00h to second register.. but the time clock is not increasing..
i will give u my code ...please give me suggestion....

with regards
Tapan
 

rtc ds 1302 code

Hi,
It'll be helpful if you post your code.
By the way, which language and compiler are you using?
 

Re: rtc ds 1302 code

hi Tahmid

I am using keil software and my code is written in assembly language..

i have to complete this project by tomorrow , so please give me some suggestion.


my code is:

;###############################################
;PROGRAM FOR INTERFACING RTC WITH AT89S8252
;author: Tapan Rout
;###############################################
CE EQU P1.7 ;Chip Enable pin P1.7
IO EQU P3.4 ;Data pin P3.4
SCLK EQU P1.6 ;Clock pin 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 scon,#50h
mov tmod,#02h
mov th0,#0fdh
; MOV TL1,0FDH
mov tcon,#45h
setb tr0 */

CLR CE ;
CLR SCLK
NOP
NOP
SETB CE

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 R1,#80H ; WRITE SECONDS
mov a,#00h
MOV @r1,a
nop
nop */

SS:

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,PM ;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 M
PM: MOV A,#8AH
ACALL COMNWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
M: MOV A,#'M'
ACALL DATAWRT
ACALL DELAY

SJMP 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




with regards
Tapan
 

rtc ds 1302 code

Hi Tapan,
Sorry man, I have no idea what you wrote. I work with PIC and not AVR.

Added after 4 minutes:

But, since you said, you cleared the CH bit, there shouldn't be any other problem since you mentioned read/write is working fine.
Check the 32.768kHz crystal and did you set any frequency on the SQW pin? If so, check if you are getting the correct frequency, if you haven't enable it and check for correct frequency.
I guess that's all I can say. I can't understand a single word of what you wrote.
 

Re: rtc ds 1302 code

You have to test your code in stages ..
Try, for example, increase the value of M(21) => minutes

Modify your code like this:

;MOV R1,#83H ; READ MINUTES
;CALL READ
;MOV 21H,R0

MOV R1, #21h
INC @R1

And check out what is displayed on the LCD ..

 

Re: rtc ds 1302 code

hello IanP

Thanks for Reply.
I think in RTC the time should increase automatically.
I have to read the time and show in lcd.

But as u said that, increase time in program.

Modify your code like this:

;MOV R1,#83H ; READ MINUTES
;CALL READ
;MOV 21H,R0

MOV R1, #21h
INC @R1



here I have another doubt that :
at 21h , there is no data , how i will increase that data.

please reply me and help me.

With regards

Tapan
 

Re: rtc ds 1302 code

On power-on the value of M(21h) is not defined, so to make sure it is 00h add one line of code in the very beginning of the program ..

ORG 030H
MAIN:
ACALL LCD_INIT ;initializing LCD
MOV 21h, #00h
...

If everything else works fine you should see the MINUTES changing ..


All this is done temporary, just to test the rest of your code that is responsible for the display and to show you that the code runs and is not locked somewhere in an infinite loop ..

Rgds,
IanP
 

Re: rtc ds 1302 code

Hello IanP

I have done as you say but the same thing is happening.

my problem is
Writing to RTC is ok
then reading from RTC is the same thing that was written.....

when reading the sec register,after displaying the second
some question mark is displaying which I have not given in the program.

please through my code .
I am new to embedded field..
I expected more from you.
I hope you will help me.....


With Regards
Tapan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top