I have been unsuccessfully working with a MicroChip 24LC65 trying to get the example in the PBP Manual to work with a 16F628A. I have built the circuit exactly as shown in the book with 4.7K pullups on the data and clock lines. The example being that for the I2C command.
I am using a 4Mhz clock oscillator and the circuit is supplied with 5vdc. I have set the MClr pin as in the diagram and pulled it up also. I have grounded the various EPROM pins as the diagram shows.
I am using the hardware serial capability of the 16F628A to send program output to "Hyperterm" running on my notebook.
I have created the example coded as included below. The result returned from each of the three read statements is always "255." I don't think it is merely a coincidence that all the bits are 1's. I am not sure if this is a hardware problem, software problem or combination of both. I have read the 24LC65 data sheet and tried to understand what I can. It seems like there may be some hardware characteristics of this part that are not entirely compatible with the instructions given in the PBP manual, but I can't quite put my finger on that. Please look through the code below and see if you can spot an error. Perhaps I just destroyed the EPROM accidentally.
The code follows:
-----------------
' EP_Test.bas
' 16F628A- CPU Hardware Layout
' EPROM Hardware: MicroChip 24LC65
' ---------------------------
' RA0- Eprom data line (SDA), open drain, 4.7K pullup
' RA1- Eprom clock line (SCL), open drain, 4.7K pullup
' RA2- n.c.
' RA3- n.c.
' RA4- n.c.
' RA5- MasterClear is enabled just to match manual and jumpered high.
'
' RB0- n.c.
' RB1- n.c.
' RB2- HSER- Out to HyperTerm Display
' RB3- n.c.
' RB4- n.c.
' RB5- n.c.
' RB6- n.c.
' RB7- n.c.
'
@ __config _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF & _PWRTE_OFF & _BOREN_OFF
'
CMCON=7
'
Define OSC 4
Define HSER_BAUD 2400
Define HSER_RCSTA 90h
Define HSER_TXSTA 20h
'
B0 var byte
B1 var byte
'
' Set the tri-state registers using bits
TRISA=%00000000
TRISB=%00000000
' Initialize the ports using bits
PortA=%00000000
PortB=%00000000
'
Pause 1500
' start the eprom stuff
'
B0 = 0
I2CWRITE PortA.0,PortA.1,$A0,B0,[B0]
Pause 700
B0 = 1
I2CWRITE PortA.0,PortA.1,$A0,B0,[B0]
Pause 700
B0 = 2
I2CWRITE PortA.0,PortA.1,$A0,B0,[B0]
Pause 1500
'
B0 = 0
I2CREAD PortA.0,PortA.1,$A0,B0,[B1]
Hserout [#B1,13,10]
Pause 700
B0 = 1
I2CREAD PortA.0,PortA.1,$A0,B0,[B1]
Hserout [#B1,13,10]
Pause 700
B0 = 2
I2CREAD PortA.0,PortA.1,$A0,B0,[B1]
Hserout [#B1,13,10]
'
End
----------------------
Bookmarks