Sorry for my english
I am an italian student.
This is my problem:
I need to connect a eeprom 24C64 at PIC 16F877 and i didn'know how set MSSP module.
I wouldn't use I2C read and write command
I like code sample for MSSP
thank you!!
Printable View
Sorry for my english
I am an italian student.
This is my problem:
I need to connect a eeprom 24C64 at PIC 16F877 and i didn'know how set MSSP module.
I wouldn't use I2C read and write command
I like code sample for MSSP
thank you!!
Christian,
there will be more chance to find a solution to your problem if you would post your code here rather than sending PMs only.
(With your code on the board many people could have a look at it and reply)
Please shrink the code down to the necessary to make it readable.
regards
Ralph
I have find the routine for mssp. It work fine
'Impostazioni modulo MSSP
SSPCON.5=1
SSPCON.3=1
SSPCON.2=0
SSPCON.1=0
SSPCON.0=0
SSPCON2=0
SSPSTAT.7=0
SSPSTAT.6=0
SSPADD= 24 ' Freq di clock 100 KHz a 10 MHz
'------------------------------------------------
' Subroutine Tx su bus I2C per indirizzi a 16 bit
:I2CSendw
gosub I2CStart
SSPBUF = addressbus
gosub I2CWait
SSPBUF = address.lowbyte
gosub I2CWait
SSPBUF = address.highbyte
gosub I2CWait
SSPBUF = dati
gosub I2CWait
gosub I2CStop
Return
'------------------------------------------------
' Subroutine Rx su bus I2C per indirizzi a 16 bit
:I2CReceivew
gosub I2CStart
SSPBUF = addressbus
gosub I2CWait
SSPBUF = address.lowbyte
gosub I2CWait
SSPBUF = address.highbyte
gosub I2CWait
gosub I2CRestart
SSPBUF = addressbus + 1
gosub I2CWait
while ( SSPSTAT.2=1 )
WEND
SSPCON2.3=1
Gosub I2CWait
dati=SSPBUF
gosub I2CNak
gosub I2CStop
Return
'------------------------------------------------
' Subroutine Rx su bus I2C per indirizzi a 8 bit
:I2CReceive
gosub I2CStart
SSPBUF = addressbus
gosub I2CWait
SSPBUF = address.lowbyte
gosub I2CWait
gosub I2CRestart
SSPBUF = addressbus + 1
gosub I2CWait
while ( SSPSTAT.2=1 )
WEND
SSPCON2.3=1
Gosub I2CWait
dati=SSPBUF
gosub I2CNak
gosub I2CStop
Return
'------------------------------------------------
' Subroutine Tx su bus I2C per indirizzi a 8 bit
:I2CSend
gosub I2CStart
SSPBUF = addressbus
gosub I2CWait
SSPBUF = address.lowbyte
gosub I2CWait
SSPBUF = dati
gosub I2CWait
gosub I2CStop
Return
'------------------------------------------------
' Subroutine MSSP I2C
:I2CAck
SSPCON2.5=0
SSPCON2.4=1
gosub I2CWait
Return
:I2CNak
SSPCON2.5=1
SSPCON2.4=1
gosub I2CWait
Return
:I2CRestart
SSPCON2.1=1
GOSUB I2CWait
Return
:I2CStart
SSPCON2.0=1
GOSUB I2CWait
Return
:I2CStop
SSPCON2.2=1
GOSUB I2CWait
Return
:I2CWait
while (PIR1.3=0)
WEND
PIR1.3=0
Return
In the mainprogram
addressbus=$A0
address=x
dati=y
gosub I2CSendw