PDA

View Full Version : Values in EEPROM get erased on power cycle



senojlr
- 6th September 2005, 01:20
Hi, I am a newbie to using pic chips and programming the pic chips with picbasic pro. My problem is, I am using a PIC 18f452 and am trying to store user input variables to the onboard eeprom of the chip. I am using the pic basic pro write and read command and it seems to work OK as long as the chip is powered up. When power is cycled to the chip, I loose the values that should be stored in the EEPROM. Shouldn't these values be maintained since the values are stored to the EEPROM or am I trying to use the EEPROM improperly?

Thanks

mister_e
- 6th September 2005, 04:17
never get any problem with it with all PIC with on-board EEPROM. What about a snip of your code??? PBP Version???

CocaColaKid
- 6th September 2005, 04:37
I use the write and read commands all the time without problems. I use the data command when I want to pre-load the eeprom with known values.

senojlr
- 7th September 2005, 02:50
Thanks for reply mister e and cocacolakid. Below is a snippet of code from my program. I am reading dip switches that I have connected to portc and portd and storing the values in the onboard eeprom when a switch I have connected to portb.2 is on. This code is at the beginning of program after variable declarations and only executes once on startup before program goes into loop. It works OK until I turn the switch off on portb.2 and cycle the power. The value read from the EEPROM is then 65535. Any help that you can give me will be greatly appreciated.


if PORTB.2 = 1 Then 'Check Calibration Switch. If on read Dip Switches
Write 0, PORTC 'Read Dip Switches on Port C and Store Value in
'EEPROM Address 0
pause 10
Write 1, PORTD 'Read Dip Switches on Port D and Store Value in
'EEPROM Address 1
pause 10
EndIf
Read 0, TMTR1KFLO.byte0 'Read Value in EEPROM Addres 0 and store
'in low byte of TMTR1KFLO (Declared as Word)
pause 10
read 1, TMTR1KFLO.byte1 'Read Value in EEPROM Addres 1 and store
'in Hi byte of TMTR1KFLO (Declared as Word)
pause 10
loop: 'Program Loop

senojlr
- 7th September 2005, 02:52
Sorry, my code and remarks kinda of got scrambled together after I posted it.

mister_e
- 7th September 2005, 03:03
mm i doubt you can do


Write 0, PORTC 'Read Dip Switches on Port C and Store Value in
'EEPROM Address 0
pause 10
Write 1, PORTD 'Read Dip Switches on Port D and Store Value in
'EEPROM Address 1

what about


TempVar var byte
'//////////// blah blah blah \\\\\\\\\\\\\\\\
TempVar=PORTC
Write 0, TempVar

TempVar = PORTD
Write 1, TempVar

CocaColaKid
- 7th September 2005, 03:13
What version of PBP are you using. There were some issues with odd number eeprom locations being misread on the 18Fxxxx series chips. PBP 2.44 and later corrected this issue.

Also you do have a pull-down on portb.2 do you not? I floating input can cause very unpredictable results.

CocaColaKid
- 7th September 2005, 03:20
Mr E, I was wondering about that too but since I'm not at work I can't confirm nor deny the statement. Yours is definitely the safe option.

senojlr
- 7th September 2005, 04:13
Thanks Guys, I do have pull down resistors on PORTC and PORTD but overlooked the one for PORTB.2. I did install one and it did fix my problem. However I don't quite understand why this would cause the problem that I had since this switch was used only to tell the program when to write to EEPROM. By the way the Write 0, PORTC does work OK.

Thanks Again for your help
Roy

CocaColaKid
- 7th September 2005, 04:32
The input on portb.2 was left floating which means that it's not really ground nor is it vcc. A floating input can change it state be simpling touch it or even something around it. Think of it this way, if the input requires say 0.7V to register as a low and 1.2V to register as a high you now have a 500mV dead zone than can go either way, pull in one way and the problem is resolved because you now know where it will always be without any other for of influence like a switch.