Thanks Darrel,
I did notice that the pauses weren't quite right and after adding the define it works good now. I still couldn't get the EE_vars to work, what starting address did you use in your test code?
Regards
jessey
Thanks Darrel,
I did notice that the pauses weren't quite right and after adding the define it works good now. I still couldn't get the EE_vars to work, what starting address did you use in your test code?
Regards
jessey
I tried lots of different address (including 91).
As long as the data statements came before the include (yours does), and the areas didn't overlap, everything was fine.
Of course, I'm using a 16F877.
I don't see any reason why the 688 should be different.
But anyhow, as long as what you have works, why bother looking any further.
<br>
DT
Hi Darrel,
Yes that is strange that it works on the 877 but not on the 688. One of the things that I really like about your EEvars is that you can declare a default value for a variable that is initiated on the first power-up. It's nice to know what the value of a variable is at first power-up especially if it's used to execute a subroutine but I guess I could do some sort of a work a round for that in the code.
Is there a way to declare a default value using EEPROMData?
Thanks
jessey
Not directly.Is there a way to declare a default value using EEPROMData?
But if your data can NEVER include the value 255 ($FF), then yes.
On power up, read the value from EEPROM.
If it's 255, write the "default" value.
Then if you ever need to restore the default value, set the location to $FF and reset.
Unfortunately, some bootloaders have chosen to "erase" EEPROM values to 0 instead of the $FF done by hardware. This can be problematic.
As long as you know which way your programmer works, it's a definite possibility.
ADDED: You can also handle it the same way EE_vars does and create a location that indicates which EEPROM locations have been restored. If the value of that location is less than or equal to (<=) the address being tested, or $FF, restore the default value and only increment the counter AFTER a successful and verified WRITE.
This way 0, $FF and anything less than the address being tested indicates the location needs to be restored.
Last edited by Darrel Taylor; - 18th May 2009 at 06:32. Reason: ADDED:
DT
Hi Darrel,
Thanks for your most welcomed input as it got me thinking on the right path (I'm hoping). I haven't checked yet if my pickit 2 programmer erases the EEPROM values to 0 or 255 when programming but with the code below it wouldn't really matter. I haven't tried this work a round yet but I can't think of any reasons why it wouldn't work.
Thanks Again
jessey
My set point doesn't ever need to be set to 0 or 255 in my program and this routine would prevent the user from setting either of the two there.Code:'(2) PIC Config Fuse Definitions for 16f688 @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF & _BOD_ON @ ERRORLEVEL -306 ' Data for house and unit codes housetbl data $60,$70,$40,$50,$80,$90,$A0,$B0,$E0,$F0,$C0,$D0 data $00,$10,$20,$30 unittbl data 0,$10,$8,$18,$40,$50,$48,$58 EEPROMData94 var BYTE Set_Point VAR EEPROMData94 READ 94, EEPROMData94 IF Set_Point = 255 THEN Set_point = 150 ' Set a default value EEPROMData94 = Set_Point Write 94, EEPROMData94 ENDIF IF Set_Point = 0 THEN Set_point = 150 ' Set a default value EEPROMData94 = Set_Point Write 94, EEPROMData94 ENDIF GOTO Mainloop
Code:Adjust_The_Set_Point: Loop1: IF Push_Button1 = Is_Pressed THEN IF Set_Point < 255 THEN Set_Point = Set_Point + 1 : Save_Var = Yes IF Set_Point > 254 THEN Set_Point = 254 ' 255 is not allowed ENDIF IF Push_Button2 = Is_Pressed THEN Set_Point = Set_Point - 1 : Save_Var = Yes IF Set_Point < 2 THEN Set_Point = 1 ' 0 is not allowed ENDIF IF Push_Button1 = Is_Not_Pressed THEN IF Push_Button2 = Is_Not_Pressed THEN RETURN ENDIF ENDIF Pause 100 GOSUB Update_The_Lcd ' just in case a button is held down IF a = 0 THEN Loop1 ' a always equals zero, use instead of GOTO... RETURN
Hey jessey,
I guess it's just a matter of semantics, but you may find this interesting.
Code:<font color="#000000"><b>SetPoint </b><font color="#008000"><b>VAR BYTE </b></font>: <b>SetPoint_DEFAULT </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>150 </b></font><b>Threshold </b><font color="#008000"><b>VAR BYTE </b></font>: <b>Threshold_DEFAULT </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>5 </b></font><font color="#008000"><b>DATA </b></font>@<font color="#800000"><b>94 </b></font><font color="#0000FF"><b><i>; Start this block of data at EE addr 94 </i></b></font><b>EE_SetPoint </b><font color="#008000"><b>DATA </b></font><b>SetPoint_DEFAULT EE_Threshold </b><font color="#008000"><b>DATA </b></font><b>Threshold_DEFAULT </b><font color="#008000"><b>READ </b></font><b>EE_SetPoint</b>, <b>SetPoint </b><font color="#0000FF"><b><i>; read EE values on powerup </i></b></font><font color="#008000"><b>READ </b></font><b>EE_Threshold</b>, <b>Threshold </b><font color="#008000"><b>GOTO </b></font><b>Main </b><font color="#0000FF"><b><i>;----[Save/Restore EEPROM values]------------------------------------------ </i></b></font><b>Save_SetPoint</b>: <font color="#0000FF"><b><i>; write current SetPoint to EEPROM </i></b></font><font color="#008000"><b>WRITE </b></font><b>EE_SetPoint</b>, <b>SetPoint </b><font color="#008000"><b>RETURN </b></font><b>Default_SetPoint</b>: <font color="#0000FF"><b><i>; restore default SetPoint value </i></b></font><font color="#008000"><b>WRITE </b></font><b>EE_SetPoint</b>, <b>SetPoint_DEFAULT </b><font color="#008000"><b>READ </b></font><b>EE_SetPoint</b>, <b>SetPoint </b><font color="#008000"><b>RETURN </b></font><font color="#0000FF"><b><i>;----------------- </i></b></font><b>Save_Threshold</b>: <font color="#0000FF"><b><i>; write current Threshold to EEPROM </i></b></font><font color="#008000"><b>WRITE </b></font><b>EE_Threshold</b>, <b>Threshold </b><font color="#008000"><b>RETURN </b></font><b>Default_Threshold</b>: <font color="#0000FF"><b><i>; restore default Threshold value </i></b></font><font color="#008000"><b>WRITE </b></font><b>EE_Threshold</b>, <b>Threshold_DEFAULT </b><font color="#008000"><b>READ </b></font><b>EE_Threshold</b>, <b>Threshold </b><font color="#008000"><b>RETURN </b></font><font color="#0000FF"><b><i>;----------------- </i></b></font><b>Save_ALL</b>: <font color="#0000FF"><b><i>; save ALL values to EEPROM </i></b></font><font color="#008000"><b>GOSUB </b></font><b>Save_SetPoint </b><font color="#008000"><b>GOSUB </b></font><b>Save_Threshold </b><font color="#008000"><b>RETURN </b></font><b>Default_ALL</b>: <font color="#0000FF"><b><i>; restore ALL default values </i></b></font><font color="#008000"><b>GOSUB </b></font><b>Default_SetPoint </b><font color="#008000"><b>GOSUB </b></font><b>Default_Threshold </b><font color="#008000"><b>RETURN </b></font><b>Main</b>:
DT
Bookmarks