Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Real Time Clock with PIC

Status
Not open for further replies.

VRL_15

New Member
I want to implement RTC without using any timer in PIC 16F887.

I just want to read the time from RTC and display it on LCD in Hours: MIn: Sec format.

I tried the following code bt it did not work. Please help me out.

RTC_rd:
call I2C_STRT
movlw 0XD0 ; slave address + write
movwf I2C_Value
call I2C_SEND
movlw 0X00 ; set word address to seconds register
movwf I2C_Value
call I2C_SEND
call I2C_STRT
movlw 0XD1 ; slave address + read
movwf I2C_Value
call I2C_SEND
call read_RTC ; read the seconds data
movwf SECS ; save it
call ack

movlw 0X01 ; set word address to seconds register
movwf I2C_Value
call I2C_SEND
call I2C_STRT
movlw 0XD1 ; slave address + read
movwf I2C_Value
call I2C_SEND
call read_RTC ; read the seconds data
movwf MINS
call ack

movlw 0X02 ; set word address to seconds register
movwf I2C_Value
call I2C_SEND
call I2C_STRT
movlw 0XD1 ; slave address + read
movwf I2C_Value
call I2C_SEND
call read_RTC ; read the seconds data
movwf SECS
call nack
call I2C_STP
return

read_RTC:

bsf I2C_DTA ; set SDA for input
movlw 0x08 ; send 8 bits
movwf COUNTER5

bcf I2C_CLOCK ; SCL low (output)
clrf I2C_Value ; clear var
;rlf I2C_Value, 1 ; rotate carry in
;clrf I2C_Value ; clear var again

I2C_read_loop:
rlf I2C_Value, 1

bsf I2C_CLOCK ; SCL high (input)
btfsc PORTC,4
bsf I2C_Value, 0 ; if data out = 1, set bit

;bcf I2C_CLOCK

bcf I2C_CLOCK ; SCL low (output)

decfsz COUNTER5, 1
goto I2C_read_loop

movf I2C_Value, 0

return

ack:
bcf I2C_DTA ; set SDA for output
bsf I2C_CLOCK ; SCL high (input)

;nop
bcf I2C_CLOCK

;bcf I2C_CLOCK ; SCL low (output)
return



nack:
bsf I2C_DTA
bcf I2C_DTA ; set SDA for output
bsf I2C_CLOCK ; SCL high (input)
bcf I2C_CLOCK ; SCL low (output)

return
 
**broken link removed**

I tried the above link but it did not solve the problem.

I just want to read the data from DS1307(RTC) and not write anything to the RTC.

If anyone has an idea, please let me know.

Thank you.
 
Last edited:
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
 
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

Thank you
 
there have been 87 views and no reply

has anyone never displayed the time on LCD by only reading it from DS1307???
 
Status
Not open for further replies.

Latest threads

Back
Top