Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RTC (PCF8583) with 16f877 PIC Problem

Status
Not open for further replies.

kvrajasekar

Junior Member level 3
Joined
Sep 18, 2008
Messages
28
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,517
RTC problem...

Hi all,

I am using RTC (PCF8583) with 16f877.I am not familiar with I2C interfacing.I used the following codes,while readiing data sheets and refering some sites.But i controller gets hanging problem when i used the coding.

Please help me to solve the problem....

Initialised RC3(SCL) and RC4(SDA) as input.

Configure the MSSP as an I2C master controller
movlw b'00101000' ; Select I2C master mode

movwf SSPCON
movlw I2CRATE ; Set the bus speed

movwf SSPADD
movlw b'00000000' ; And clear any status flags

movwf SSPSTAT
call I2CStop ; Ensure the bus is free

; Generates an I2C start condition.
I2CStart:

bsf SSPCON2,SEN ; Generate START condition
btfsc SSPCON2,SEN ; And wait for it to complete
goto $-1
return
; Generates an I2C restart condition.
I2CRestart:

bsf SSPCON2,RSEN ; Generate RESTART condition
btfsc SSPCON2,RSEN ; And wait for it to complete
goto $-1
return
; Generates an I2C stop condition.

I2CStop:

bsf SSPCON2,PEN ; Generate STOP condition
btfsc SSPCON2,PEN ; And wait for it to complete
goto $-1
return
; Transmits the byte in W to the I2C bus.

I2CWrite:
movwf SSPBUF ; Initiate I2C write

btfsc SSPSTAT,R_W ; And wait for completion
goto $-1
return
; Recieves a byte from the I2C and returns its value.
I2CRead:

bsf SSPCON2,RCEN ; Initiate I2C read
btfsc SSPCON2,RCEN ; And wait for completion
goto $-1

movf SSPBUF,W ; Then read the data value
return
; Sends an I2C ACK signal to the slave device.
I2CAck:

bcf SSPCON2,ACKDT ; Send acknowledgement
bsf SSPCON2,ACKEN
goto I2CWait
; Sends an I2C NAK signal to the slave device.
I2CNak:

bsf SSPCON2,ACKDT ; Send negative acknowledgement
bsf SSPCON2,ACKEN
; Waits for the current I2C action to complete.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top