Interfacing DS 1307 with PIC

Thread Starter

RG23

Joined Dec 6, 2010
304
I am having a problem in setting the time data on RTC.

I am able to read the data from RTC perfectly

but the displayed time on LCD is not the actual time.

I want to set the correct time and then read from RTC.

If anyone has an idea please let me know

Thank you
 

Thread Starter

RG23

Joined Dec 6, 2010
304
set_clock:
;movlw 0xC4
;movwf PORTD
;call SND_CMD
movlw second-1 ; prompt user for data (month)
;call write
call readbcd
movwf SECS
movlw minute-1 ; prompt user for data (month)
;call write
call readbcd
movwf MINS
call RTC_brst_wr
return
RTC_brst_wr:
call I2C_STRT
movlw 0xD0
movwf I2C_Value
call I2C_SEND
movlw 0x00
movwf I2C_Value
call I2C_SEND
movf SECS,0
movwf I2C_Value
call I2C_SEND
movf MINS,0
movwf I2C_Value
call I2C_SEND
call I2C_STP
return
;write:
;movwf SCRATCH1
;GoWrite:
;call pclsub ; advance pointer and read pointed byte
;addlw 0h ; if contents are zero, Z will be set
;btfsc STATUS,Z ; skip if clear
;return ; current character is null: end of string
;movlw 0xC4 ; print one character
;movwf PORTD
;call SND_DTA

;goto GoWrite
;pclsub:
;incf SCRATCH1,1 ; advance table pointer
;movf SCRATCH1,0 ; move table pointer to W
;movwf PCL ; jump to address pointed by PCLATH,W
;
readbcd:
clrf I2C_Value ; clear temp reg

gobcd:
;call uart_getchar ; returns character in W
;call uart_putchar ; echo to screen
;movlw 0xC4
;movwf PORTD
;call SND_CMD

;movwf PORTD
;call SND_DTA
xorlw 0x0d ; if cr, Z will be set
btfss STATUS,Z ; skip if clear
goto bcd ; go to bcd if Z = 0
movf I2C_Value,0 ; done, move final value to W
return ; and return
bcd:
xorlw 0dh ; restore value
addlw -30h ; subtract ASCII offset
btfsc W,4 ; jump if not A-F
addlw -7 ; if A-F, subtract 7
digit:
andlw 0x0f ; clear upper nibble
bcf I2C_Value,4 ; clear upper nibble of temp reg
bcf I2C_Value,5
bcf I2C_Value,6
bcf I2C_Value,7
movwf SCRATCH1 ; save W
movf I2C_Value,0 ; copy TMP to W
movwf TMP2 ; save TMP
movf SCRATCH1,0 ; restore W
movwf I2C_Value ; TMP now has org W value
movf TMP2,0 ; W now has org TMP value
swapf TMP2,0 ; swap nibbles
iorwf I2C_Value,0 ; insert bits 0 to 3 of TMP to W
movwf I2C_Value ; move W into temp reg
goto gobcd ; continue until CR is encountered
 

jdraughn

Joined Jan 30, 2009
33
You are probably having trouble because it's in BCD format and you need to convert it to decimal so it makes sense. You also need to send it BCD when you write too it.
 
Top