I am trying to write some data into the EEPROM on a 16F628. It just flat doesn't work. According to the data sheet it should have 128X8 storage. So I wrote a test program to check and every data "slot" reads back 255. Here's the code:
INCLUDE "modedefs.bas"
DEFINE OSC 20
Col VAR BYTE ' Keypad column
Row VAR BYTE ' Keypad row
Key VAR BYTE ' Key value
SerPin VAR PortA.0 ' Serial output pin
KeyCode var byte
LED VAr PortB.7
Relay1 var PortA.3
Relay2 var PortA.4
CMCON = 7 ' PortA = digital I/O
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0 ' Enable PORTB pull-ups
SetCode VAR BYTE
OldCode VAR BYTE[11]
NewCode VAR BYTE[10]
LoopCount VAR BYTE
NumDig VAR BYTE
Unlock VAR BYTE
A var byte
ProgramSwitch var PortA.2
input programswitch
Setcode = 1
unlock = 1
numdig = 6
pause 5000
serout serpin,N9600,[254,1]
serout serpin,N9600,[254,128]
serout serpin,N9600,["Power On"]
Read 0,numdig 'Read number of digits of unlock code from memory
For loopcount = 1 to numdig ' Read unlock code from memory
Read loopcount,oldcode[loopcount]
a = oldcode[loopcount]
serout serpin,N9600,[254,(192+loopcount)]
serout serpin,N9600,[(oldcode[loopcount])]
Next loopcount
Loop:
serout serpin,N9600,[254,1]
for a = 1 to 20
keycode = a
write a,keycode
serout serpin,N9600,[254,128]
serout serpin,N9600,["location "]
serout serpin,N9600,[#A]
serout serpin,N9600,[254,192]
serout serpin,N9600,["value "]
serout serpin,N9600,[#keycode]
Pause 1000
next
serout serpin,N9600,[254,1]
For A = 1 to 20
read a,keycode
serout serpin,N9600,[254,128]
serout serpin,N9600,["read location "]
serout serpin,N9600,[#A]
serout serpin,N9600,[254,192]
serout serpin,N9600,["value "]
serout serpin,N9600,[#keycode]
pause 1000
next
goto loop
END
The VAR's at the top are left over from the "real" program. Any thought's? I would have thought this easier than this but it's really whipping my fanny.
Thanks
Bookmarks