problems working with 24C512
Dear fellows
Im facing problems working with 24C512 eeprom. Im posting here my coding. IN simulation, it seems to work fine on proteus but in the real it doesnt. Herez my coding.
Include "Modedefs.Bas"
' ** Setup the Crystal Frequency, in Mhz **
Define OSC 4 ' Set Xtal Frequency
' ** Setup the I2C configuration **
Define I2C_SCLOUT 1 ' No need for the pullup resistor on the SCL pin
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
' Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTC
' Set LCD Register Select bit
DEFINE LCD_RSBIT 0
' Set LCD Enable port
DEFINE LCD_EREG PORTC
' Set LCD Enable bit
DEFINE LCD_EBIT 1
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 8
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50
' ** Declare the Variables **
SCL Var PortD.0 ' I2C data pin
SDA Var PortD.1 ' I2C clock pin
Addr Var Word ' 16-bit memory address within the Eeprom
E_ByteOut Var Byte ' Data byte to be written to the Eeprom
E_ByteIn Var Byte ' Data byte read from the Eeprom
x var byte
' ** The main program starts here **
' Write the string, "HELLO WORLD" into the first 11 address's of the Eeprom
For Addr=0 To 10 ' Create a loop of 11
Lookup Addr,[1,255,222,134,10,1,13,19,10,99,219],E_ByteOut' Build up the string
Gosub EWrite ' Write the byte to the Eeprom
Next ' Close the Loop
' Read the first 11 address's within the Eeprom,
' and display them on the LCD
Again:
lcdout $FE,1, "starting"
Pause 1000 ' Clear the LCD
Pause 500 ' Pause for drama
For Addr=0 To 10 ' Create a loop of 11
Gosub ERead ' Read the byte from the Eeprom
hserout [dec e_bytein,13,10]
pause 100
lcdout $FE,1,#E_bytein
' Print the characters read in from the eeprom
Pause 2000 ' Pause inbetween displays, for drama
Next ' Close the loop
Goto Again ' Do it forever
' ** SUBROUTINES **
EWrite:
I2CWRITE SDA,SCL,%10100000,Addr,[E_ByteOut] ' Write out the byte
Pause 10 ' Delay 10ms after each write
Return
ERead:
I2CREAD SDA,SCL,%10100001,Addr,[E_ByteIn] ' Read in the byte
Return
The problem im facing is this that the LCD displays "starting" and then instead of displaying the values it read from the eeprom, it displays just 2.
PLease help me what to do here. I have tried addr.highbyte addr.lowbyte, took control as a byte variable. But nothing seems to work here.