DS1820 with 16f688


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jessey View Post
    what starting address did you use in your test code?
    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

  2. #2
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Is there a way to declare a default value using EEPROMData?
    Not directly.

    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

  4. #4
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    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.
    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

    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
    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:
    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

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. DS1820 display with 7-seg 4 digits
    By chai98a in forum Code Examples
    Replies: 12
    Last Post: - 10th April 2008, 13:12
  2. PIC lcd ds1820
    By wchpikus in forum mel PIC BASIC
    Replies: 2
    Last Post: - 24th May 2007, 14:46
  3. Help with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th October 2006, 23:12
  4. DS1820 again
    By paxmowa in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th January 2006, 14:49
  5. Problem with 16F688 and Hserout
    By DWV in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 19th March 2005, 05:37

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts