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
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