Real Time Clock

Thread Starter

RG23

Joined Dec 6, 2010
304
The following code I tried to display hrs, min, sec on LCD but was not successful

In the code below SND_DTA and SND_CMD are subroutines to display the data and to bring the cursor to a specific location on display

call RTC_rd

movlw 0x88 ;return LCD to Line 2 Char 8
movwf PORTD
call SND_CMD
movf HRS,0
movwf PORTD
call SND_DTA
movlw 0x3A
movwf PORTD
call SND_DTA
movf MINS,0
movwf PORTD
call SND_DTA
movlw 0x3A
movwf PORTD
call SND_DTA
movf SECS,0
movwf PORTD
call SND_DTA
 

hgmjr

Joined Jan 28, 2005
9,027
What voltage do you measure across the battery?

Sorry for all the questions. I am just trying to rule out anything on the hardware side before examining the code.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
I am not proficient enough in PIC assembly language to give you a quick answer. Hopefully a PIC guru will take up the challenge.

hgmjr
 

Thread Starter

RG23

Joined Dec 6, 2010
304
I am still finding it really difficult to just read the hours, minutes and seconds from DS1307 and display it on LCD.

If anyone has an idea please help me out.

I have tried another code but didn't work

RTC:
call read_RTC
read_regs:
movf SECS,0
call writebcd
;movwf temp15
;movlw 0xCB
;movwf PORTD
;call SND_CMD
;movf temp15,0
;movwf PORTD
;call SND_DTA
return
read_RTC:
call I2C_STRT
movlw 0xD0
movwf I2C_Value
call I2C_SEND
movlw 0x00
movwf I2C_Value
call I2C_SEND
call I2C_STRT
movlw 0xD1
movwf I2C_Value
call I2C_SEND
movlw 0x00
movwf I2C_Value
call I2C_SEND
call I2C_RD
movwf SECS
call I2C_STP
return
writebcd:
movwf temp16
swapf temp16,0
andlw 0x0F
addlw 0x06
btfss STATUS,DC
call lessnine
addlw 0x31
goto digit1

lessnine:
addlw 0x2A
return
digit1:
movlw 0xCB
movwf PORTD
call SND_CMD
movf temp16,0
movwf PORTD
call SND_DTA
return
I2C_RD:
bcf STATUS,RP1
bsf STATUS,RP0
clrf TRISC
bsf TRISC,4
bcf STATUS,RP1
bsf STATUS,RP0
clrf I2C_Value

movlw 0x08
movwf COUNTER5
goto I2C_read_loop
;rlf I2C_Value,1
;clrf I2C_Value
I2C_read_loop:
rlf I2C_Value,1
bsf I2C_CLOCK
btfsc PORTC,4
bsf I2C_Value,0
bcf I2C_CLOCK
decfsz COUNTER5,1
goto I2C_read_loop

movf I2C_Value,0
return
 

Thread Starter

RG23

Joined Dec 6, 2010
304
Please let me know

I am sure someone must have done this before.

Just reading the time from DS1307 and display it on LCD

Guys, please help me out
 

Thread Starter

RG23

Joined Dec 6, 2010
304
hgmjr

Super Moderator

you are a super moderator

Do you know someone who can help me out in this?

I am new to the PIC assembly coding

I am sure someone must have done this before that is just to read the seconds, min , hours from DS1307 and display it on LCD without any RS232 and all.

I am really having a hard time on this one
I need your help.

Thank you
 

Thread Starter

RG23

Joined Dec 6, 2010
304
Rich (BB code):
I2C_STRT:
;{
 bsf  I2C_CLOCK  ; set clock high
 bsf  I2C_DTA   ; set data high
 bcf  I2C_DTA   ; clear data bit
 bcf  I2C_CLOCK  ; set clock low 
 return
;}

I2C_STP:
;{
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_DTA   ; set data low
 bsf  I2C_DTA   ; set data high
 return
;}

I2C_SEND:
;{
 bcf  I2C_DTA   ; clear data bit
 btfsc   I2C_Value,7  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
 btfsc I2C_Value,6  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
 btfsc I2C_Value,5  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
 btfsc I2C_Value,4  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
 btfsc I2C_Value,3  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
 btfsc I2C_Value,2  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
 btfsc I2C_Value,1  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
 btfsc I2C_Value,0  ; test CARRY for hi
 bsf  I2C_DTA   ; hi, so set data bit
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 bcf  I2C_DTA   ; clear data bit
; bsf  STATUS,RP0  ; goto Bank 1
; bsf  TRISC,3   ; turn Data to input
 nop
; bcf  STATUS, RP0  ; goto Bank 0
 bsf  I2C_CLOCK  ; set clock high
 bcf  I2C_CLOCK  ; set clock low
 nop
; bsf  STATUS,RP0  ; goto Bank 1
; bcf  TRISC,3   ; turn Data back to output
; bcf  STATUS, RP0  ; goto Bank 0
 return
;}
 
Last edited by a moderator:

tom66

Joined May 9, 2009
2,595
Thanks for that information.

What crystal or oscillator are you using with your PIC? I think I know your problem: you are clocking the I2C bus too fast. Either the RTC can't keep up, or the resistors are too high in value, causing slew rate issues.

Do you have pull-up resistors of 1k or so to the 5V or 3.3V rail on your I2C bus lines?

If you have a scope or can get access to one, you would see the problem quickly.
 

hgmjr

Joined Jan 28, 2005
9,027
Did you see any flaws in the code if any?
Since no PIC assembly language knowledgeable member seems to be interested in assisting you then I will take a stab at it. I am going to have to get familiar with the opcodes. I do know the DS1307 so I am at least ahead in that part of the task.

hgmjr
 
Top