Electrical – PIC18F2550 and DS1307 i2c RTC MPLAB assembly code. Have to loop for seconds,mins,hrs

assemblyi2cmplabpicrtc

PIC18F2550 and DS1307 i2c RTC MPLAB assembly code.

I am using a PIC18f2550 to get time,date,etc from DS1307.

  • I am able to get the seconds,minutes, hours, etc by repeatly CALLing GET_TIME with a new Read Address 0 to 6.
  • I am unable to get all the Parameters sec, min, hrs, etc in one reading as below in Read_Clk.

Could someone tell me what I am doing wrong? Using it as it is only returns "Seconds" in each of the seconds, minutes, hours, etc…. I have posted a picture because of lines offset.

WAIT_PIR_SSPIF: 
    BTFSS   PIR1,SSPIF
    GOTO    WAIT_PIR_SSPIF 
    RETURN

WRITE_CLK:    ;Write data to slave.; //Write data to I2C bus
    BCF     PIR1,SSPIF
    MOVFF   WRITE_DATA,SSPBUF   
CheckWrite: 
    BTFSS   PIR1,SSPIF   
    GOTO    CheckWrite  
    RETURN

GET_TIME:       
    CALL     START_CLK
    MOVLW    b'11010000'   
    MOVWF    WRITE_DATA 
    CALL     WRITE_CLK      
    MOVLW    b'00000000'           ;ADDRESS OF TIME TO READ 
    MOVWF    WRITE_DATA 
    CALL     WRITE_CLK
    CALL     DELAY_2nd  
    CALL     RESTART_CLK          
    MOVLW    b'11010001'   
    MOVWF    WRITE_DATA
    CALL     WRITE_CLK  
    BSF      SSPCON2,ACKDT         ;SAME AS "NACK"
    CALL     DELAY_2nd  
    CALL     Read_Clk                       ;CALLS READ_CLK
    CALL     STOP_CLK   
    CALL     DELAY_2nd    
    GOTO     GET_TIME

Read_Clk:             ; //Read data from I2C bus
    BSF     SSPCON2,RCEN
    BCF     PIR1,SSPIF  
    CALL    WAIT_PIR_SSPIF
    MOVFF   SSPBUF,SECONDS 
    BSF     SSPCON2,ACKEN   
    BCF     PIR1,SSPIF  
    CALL    WAIT_PIR_SSPIF
    MOVFF   SSPBUF,MINUTES  
    BSF     SSPCON2,ACKEN   
    BCF     PIR1,SSPIF  
    CALL    WAIT_PIR_SSPIF  
    MOVFF   SSPBUF,HOURS
    BSF     SSPCON2,ACKEN   
    BCF     PIR1,SSPIF  
    CALL    WAIT_PIR_SSPIF
    MOVFF   SSPBUF,DAYS
    BSF     SSPCON2,ACKEN   
    BCF     PIR1,SSPIF  
    CALL    WAIT_PIR_SSPIF  
    RETURN

DELAY_2nd:
    MOVLW   b'00000100'
    MOVWF   COUNT_DOWN
DELAY_2:

enter image description here

Best Answer

After spending many hours on the internet I have come up with an answer to my own question. Below is the Updated code that in some parts replace the above code. PIC18F2550 and DS1307 i2c RTC MPLAB assembly code. Code used to get time,date,etc from DS1307.

Ds1307 Pic18f2550 assembly code for Time