I'm using a pic 16F627, Picbasic, Ic prog and a JDM programmer
I have a chip programmed to if you hold the switch down on startup, it sets a variable to 1, writes it to eeprom. Then carries on with startup as normal
The next part (only part, if no switch held down) of it is done everytime it starts up, is to set the varaible to 0, read the variable from the eeprom and if its equal to 1, to switch on output on.
The problem is that when you hold down the switch when switching it on, it will switch the output on, its obviously written and read back the eeprom, but if you switch it off and on again without the switch held down, the output stays low, its as if the eeprom has forgotten its contents
any ideas?, I can post the simple code here later, but I do not have it on this computer
It is very rare that an EEPROM will forget things it has been given to memorize unless
1) You have exceeded the endurance cycle of EEPROM (around 10M). This will rarely happen.
2) Your program is accidently writing to the EEPROM.
Do this in your code.
Forcefully disable the EEPROM memory write (WREN) at startup (eventhough it is disabled at startup).
Enable EEPROM memory only when it is is read or write.
This may solve your problem.
And to know if there are any other bugs, post your code here.
The eeprom may be inadvertently being overwritten as the the chip is being powered down. Make sure you disable writing to the eeprom (BCF EECON1,WREN) after each write is completed. Post your code.
I've never been able to have it working the f627 with picbasic's built in read and write commands, a mate of mine wrote the parts that set the registeres directly.
This isn't my final code, its merly all the stuff that works stripped out, so I can work on the bit that doesn't work.
Code:
'@ device INTRC_OSC_NOCLKOUT
'eeprom 1, [0]
EECON1 = %00000000 'Control 1 register, disable EEPROM write
cmcon = 7
box var byte
box = 1
if porta.1 = 1 then
EEADR = %00000001 'Address register
EEDATA = box 'Data register, replace 127 with data to store
EECON1 = %00000100 'Control 1 register, enable EEPROM write
EECON2 = 85 'Control 2 register
EECON2 = 170 'Control 2 register
EECON1.1 = 1 'Control 1 register, begin write
EECON1 = %00000000 'Control 1 register, disable EEPROM write
else
EECON1 = %00000000 'Control 1 register, disable EEPROM write
pause 100
endif
high portb.0
box = 0
EEADR = %00000001 'Read from location 1
EECON1 = %00000001 'Initiate read
PAUSE 1 'Pause may not be required, experiment
box = EEDATA 'Place value from EEPROM into variable
if box = 1 then
high portb.4
endif
END
You cannot write to EEPROM the way you are trying to. The write sequence is very time critical and has to be done in assembler. Either persevere with the built in commands or, if your basic compiler supports inline asm then replace your write code with the following sequence.