Position: Index > Unclassified >

Pic16F628A and 24LC256 EEPROM I2C

2017-11-21 11:44  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

Pic16F628A and 24LC256 EEPROM I2C

Is this hookup valid for I2C EEPROM storage of data?

First EEPROM is Address $00 and the other Address $01

Part of PicBASIC Pro program follows:

Using PIC16F628A and 24LC256 EEPROMs

SCLK VAR PORTB.6 ' Data Pin on I2C
SDATA VAR PORTB.7 ' Clock Pin on I2C
addr VAR WORD ' Memory location in EEPROM to use
CntRec VAR WORD ' Value of count to store in EEPROM

addr = %00000001 ' Location of memory to use
CMCON = 7 ' PORTA digital

' if power is applied, want last count of data stored in EEPROM -
' Read EEPROM first to get last count

I2CREAD SDATA,SCLK,$A0,addr,[CntRec]

GOSUB LCD_Display01 : Display count from EEPROM
' Send CntRec out to Serial bus or LCD Display to display content

 


Main:
If DET_IN = 1 THEN ' any form of detector circuit
CntRec = CntRec + 1 ' Increment count in EEPROM
GOSUB LCD_Display01
IF CntRec >= 255 THEN
CntRec = 1
GOSUB LCD_Display04 ' reset count
EndIf
EndIf

I2CWRITE SDATA,SCLK,$A0,addr,[CntRec] ' Write new count

GOTO Main ' continuous loop ....

LCD_Display01:
LCDOUT CMD, Line1, "* * * * * * * Detected Signal * * * * *"
LCDOUT CMD, Line2, " Detect Total = " ,#CntRec, " "
RETURN

LCD_Display04:
LCDOUT CMD, Line1, "* * * * * * * Reset Count * * * * * * *"
LCDOUT CMD, Line2, " EEPROM = " ,#CntRec, " "
PAUSE 5000 ' pause for 5 seconds
RETURN