Hello.
I've decided to use 25LC640 EEPROM with 16F870. For that purpose, I've took the LAB1X code from here:
http://melabs.com/samples/LABX1-16F887/spix.htm
and modified it to my needs( just changed LCD and EEPROM ports and added details to info screen):
It appears to not write anything and reads the same sequence of 0s and 255 in each cycle, but the sequence is different on each power up.Code:' Define LCD registers and bits include "modedefs.bas" DEFINE OSC 4 DEFINE LCD_DREG PORTB DEFINE LCD_DBIT 4 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 0 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 1 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE LCD_COMMANDUS 1500 DEFINE LCD_DATAUS 44 ADCON1=%00000110 'CONFIGURE PORT A AS DIGITAL CS Var PORTB.3 ' Chip select pin SCK Var PORTC.6 ' Clock pin SI Var PORTC.5 ' Data in pin SO Var PORTB.2 ' Data out pin addr Var Word ' Address B0 Var Byte ' Data For addr = 0 To 15 ' Loop 16 times B0 = addr + 100 ' B0 is data for SEEPROM Lcdout $fe,1,#addr,": ",#B0 ' Display Lcdout $fe,$C0,"Writing... " ' Display Gosub eewrite ' Write to SEEPROM Pause 10 ' Delay 10ms after each write Next addr pause 1000 mainloop: For addr = 0 To 15 ' Loop 16 times Gosub eeread ' Read from SEEPROM Lcdout $fe,1,#addr,": ",#B0 ' Display Lcdout $fe,$C0,"Reading... " ' Display Pause 1000 Next addr Goto mainloop ' Subroutine to read data from addr in serial EEPROM eeread: CS = 0 ' Enable serial EEPROM Shiftout SI, SCK, MSBFIRST, [$03, addr.byte1, addr.byte0] ' Send read command and address Shiftin SO, SCK, MSBPRE, [B0] ' Read data CS = 1 ' Disable Return ' Subroutine to write data at addr in serial EEPROM eewrite: CS = 0 ' Enable serial EEPROM Shiftout SI, SCK, MSBFIRST, [$06] ' Send write enable command CS = 1 ' Disable to execute command CS = 0 ' Enable Shiftout SI, SCK, MSBFIRST, [$02, addr.byte1, addr.byte0, B0] ' Send address and data CS = 1 ' Disable Return End
I was not able to find schematics how correctly wire another pins of EEPROM, such as HOLD. This can be wrong connection issue?




Bookmarks