I2CRead
banksel SSPCON2 ; restart I2C because i have previous
bsf SSPCON2,RSEN ; i2c session on of writing
call CheckMSSP
movlw chip_write ; chip write byte
call Send_I2C_Byte
call CheckMSSP
call ACK_STAT
banksel SSPCON2
btfsc SSPCON2,ACKSTAT
goto I2CRead
movlw 0x02 ; start address
call Send_I2C_Byte
call CheckMSSP
call ACK_STAT
banksel SSPCON2 ; restart i2c
bsf SSPCON2,RSEN
call CheckMSSP
movlw chip_read ; chip read byte send
call Send_I2C_Byte
call CheckMSSP
call ACK_STAT
banksel SSPCON2 ; receive enabled
bsf SSPCON2,RCEN
call CheckMSSP
banksel SSPBUF ; 0x02 in sec
movf SSPBUF,w
movwf sec
; section starts from here sequential read
;
banksel SSPCON2 ; sending ACK instead of NACK for
bcf SSPCON2,ACKDT ; further bytes to read
bsf SSPCON2,ACKEN
banksel SSPCON2 ; receive enabled
bsf SSPCON2,RCEN
call CheckMSSP
banksel SSPBUF ; 0x03 stored in min
movf SSPBUF,w
movwf min
;sequential read end
banksel SSPCON2 ; NACK bit
bsf SSPCON2,ACKDT
bsf SSPCON2,ACKEN
call CheckMSSP
bsf SSPCON2,PEN ; stop bit
call CheckMSSP
swapf sec,w ; seconds in BCD for 7seg display
andlw 0x0F
movwf sec1
movf sec,w
andlw 0x0F
movwf sec0
banksel PORTB ; displaying 0x03 (minutes) on PORTB
movf min,w
movwf PORTB
goto I2CRead
Send_I2C_Byte
banksel SSPBUF
movwf SSPBUF
retlw 0x00
CheckMSSP
banksel PIR1
btfss PIR1,SSPIF
goto $-1
bcf PIR1,SSPIF
retlw 0x00
ACK_STAT
banksel SSPCON2
btfsc SSPCON2,ACKSTAT
goto I2C_Fail ; its code is not listed here
retlw 0x00