PDA

View Full Version : 16f628 Eeprom



Fred
- 7th March 2006, 18:31
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

Melanie
- 8th March 2006, 08:29
What version of PBP are you using?

I seem to recall there bas a bug way back in v2.40 or thereabouts that concerned the 16F628's (when they first came out) internal EEPROM. Go check MeLabs website for Revisions...

I've not looked at your code, but if you do something simple like...

CounterA var Byte
LED var PortB.0
TRISB.0=0
Start:
Low LED
For CounterA=0 to 63
WRITE CounterA,CounterA
Next CounterA
Finish:
Toggle LED
Pause 500
Goto Finish
End

When the LED starts to blink, switch-off and remove your PIC, reinsert it into your programmer and read the EEPROM contents (always assuming your programmer/software has that capability). The first 64 bytes of EEPROM should have zero to 63 incrementally written to them.

Fred
- 8th March 2006, 19:46
Patches fixed it.
Thanks