7seg interfacing RTC- HELP!

Discussion in 'Programmer's Corner' started by digital, Feb 7, 2008.

  1. digital

    Thread Starter Member

    Nov 26, 2007
    11
    0
    hi,
    I developed a code for Real time clock displaying in 7segment.. I used i2c protocol for interfacing RTC8563 and pic16f877a.. The same code worked in LCD but i couldn display it on 7seg.. following is the code developed to display only seconds in 7seg.. please notify if u found any wrong with the program.. please help!

    ;RTC WITH SEG DISPLAY. FINAL CODE.
    LIST P=PIC16F877A
    INCLUDE"P16F877A.INC"
    CBLOCK 0X20
    ADDR
    RXDATA
    DD
    DD1
    COUNT
    MSB
    REG1
    REG2
    TEMP
    NEXXT
    ENDC

    ERRORLEVEL -302 ;; avoids warning
    ERRORLEVEL -305
    ERRORLEVEL -306

    ORG 0X00
    RVReset
    GOTO START

    ORG 0X04
    RVInt
    RETFIE

    START
    CALL SIO_INT
    CALL I2C_INIT

    CALL WRITE
    CLRF PORTB
    CLRF TRISB

    ;SECONDS
    BCF 3,5
    BCF 3,5
    MOVLW 0X50
    MOVWF FSR
    MOVLW 0X02 ;;address of seconds
    MOVWF ADDR
    CALL READ ;; reads the seconds value

    BCF 3,5
    MOVF RXDATA,0 ;; moving the readed value to RXDATA
    MOVLW 0XF0
    ANDWF RXDATA,0
    CALL LSB
    INCF FSR,1
    GOTO REPEAT

    LSB
    MOVWF MSB ;; swaping the received value to
    SWAPF MSB,0 on 7seg
    movwf REG1
    MOVWF INDF
    CALL S_TX
    CALL SEG1
    INCF FSR,1
    MOVF RXDATA,0
    ANDLW 0X0F
    MOVWF REG2
    MOVWF INDF
    CALL S_TX
    CALL SEG2
    MOVF INDF,0
    CALL S_TX
    INCF FSR,1
    RETURN

    I2C_INIT
    BSF 3,5
    MOVLW B'00011000' ;;initialising i2c protocol
    MOVWF TRISC
    BCF 3,5
    MOVLW B'00101000' ;; initialising SDA & SCL
    MOVWF SSPCON

    BSF 3,5
    MOVLW 0X02
    MOVWF SSPADD ;; for clock speed
    MOVLW 0X80
    MOVWF SSPSTAT
    RETURN


    WRITE
    BSF 3,5
    BSF SSPCON2,SEN ;START ENABLE
    CALL CHECK
    MOVLW 0XA2 ;WRITE ADDR
    CALL SEND
    MOVLW 0X00 ;CONTROL REG 1 ADDR
    CALL SEND
    MOVLW 0X00 ;CLEAR CONTROL REG 1
    CALL SEND

    BSF 3,5
    BSF SSPCON2,PEN ;STOP BIT
    CALL CHECK
    CALL D_10

    BSF 3,5
    BSF SSPCON2,SEN ;START BIT
    CALL CHECK
    MOVLW 0XA2 ;WRITE ADDR
    CALL SEND

    MOVLW 0X01 ;CONTROL REG2 ADDR
    CALL SEND

    MOVLW 0X00 ;CONTROL REG2 DATA
    CALL SEND
    MOVLW 0X00 ;SECONDS DATA
    CALL SEND
    MOVLW 0X38 ;MINUTES
    CALL SEND
    MOVLW 0X10 ;HOURS
    CALL SEND
    MOVLW 0X04 ;DATE
    CALL SEND
    MOVLW 0X05 ;WEEKDAYS
    CALL SEND
    MOVLW 0X08 ;MONTH
    CALL SEND
    MOVLW 0X05 ;YEAR
    CALL SEND

    BSF 3,5
    BSF SSPCON2,PEN
    CALL CHECK
    CALL D_10
    RETURN

    READ
    BSF 3,5
    BSF SSPCON2,SEN ;START BIT
    CALL CHECK

    MOVLW 0XA2 ;WRITE ADDR
    CALL SEND
    MOVF ADDR,0 ;REG ADDR
    CALL SEND

    BSF 3,5
    BSF SSPCON2,RSEN ;STOP
    CALL CHECK
    MOVLW 0XA3 ;READ ADDR
    CALL SEND
    BSF 3,5

    BSF SSPCON2,RCEN
    CALL CHECK
    BSF 3,5
    BSF SSPCON2,ACKDT
    BSF SSPCON2,ACKEN
    CALL CHECK
    BCF 3,5
    MOVF SSPBUF,0
    MOVWF RXDATA
    BCF PORTB,1
    BSF 3,5
    BSF SSPCON2,PEN
    CALL CHECK
    BCF PORTB,2
    CALL D_10
    RETURN

    SEND
    BCF 3,5
    MOVWF SSPBUF
    CALL CHECK
    BSF 3,5
    BTFSC SSPCON2,ACKSTAT
    GOTO SEND
    BCF 3,5
    RETURN
    CHECK
    BCF 3,5
    BTFSS PIR1,SSPIF
    GOTO $-1
    BCF PIR1,SSPIF
    RETURN
    D_2MS
    MOVLW 0X04
    MOVWF DD
    MOVLW 0XFF
    MOVWF DD1
    DECFSZ DD1,1
    GOTO $-1
    DECFSZ DD,1
    GOTO $-5
    RETURN

    SEG1

    CLRF PORTB
    BSF PORTB,0 ;; enabling 1st segment
    MOVF REG1,W
    CALL Datatable
    MOVWF PORTD
    CALL D_10
    CALL D_10
    CALL D_10
    return

    SEG2
    CLRF PORTB ;; enabling 2nd segment
    BSF PORTB,1
    MOVF REG2,W
    CALL Datatable
    MOVWF PORTD
    CALL D_10
    CALL D_10
    CALL D_10
    return
    **************************************************
    to display on hyperterminal
    *************************************************
    SIO_INT
    BCF 3,5
    BSF RCSTA,SPEN
    BSF RCSTA,CREN

    BSF 3,5
    CLRF TXSTA
    BSF TXSTA,TXEN
    MOVLW 0X09 ;setting baudrate as 9600bps
    MOVWF SPBRG
    BCF 3,5

    RETURN
    S_TX
    BCF 3,5
    BTFSS PIR1,TXIF
    GOTO $-1
    NOP
    NOP
    MOVWF TXREG
    RETURN

    D_10
    MOVLW .20
    MOVWF DD
    MOVLW 0XFF
    MOVWF DD1
    DECFSZ DD1,F
    GOTO $-1
    DECFSZ DD,F
    GOTO $-5
    RETURN

    ORG 800H

    Datatable addwf PCL ; add W value to PCL
    retlw b'00111111' ; 0
    retlw b'00000110' ; 1
    retlw b'01011011' ; 2
    retlw b'01001111' ; 3
    retlw b'01100110' ; 4
    retlw b'01101101' ; 5
    retlw b'01111101' ; 6
    retlw b'00000111' ; 7
    retlw b'01111111' ; 8
    retlw b'01101111' ; 9

    END
     
  2. digital

    Thread Starter Member

    Nov 26, 2007
    11
    0
    Hi,
    i posted a code for rtc interfacing 7 seg.. Please masters help!.. If any confusion or wrong with the program please notify
     
Loading...