DS1820 with 16f688


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    I tried programming a new chip with ee_vars.pbp and I got the same results as before but I got the firecracker code working good using the saving routines below:

    EEPROMData91 var BYTE
    X VAR EEPROMData91
    READ 91, EEPROMData91

    '' To write to the eprom
    '' ================
    'EEPROMData91 = X
    'Write 91, EEPROMData91
    '-----------------------

    EEPROMData92 var BYTE
    Y VAR EEPROMData92
    READ 92, EEPROMData92

    '' To write to the eprom
    '' ================
    'EEPROMData92 = Y
    'Write 92, EEPROMData92
    '-----------------------

    EEPROMData93 var BYTE
    Z VAR EEPROMData93
    READ 93, EEPROMData93

    '' To write to the eprom
    '' =================
    'EEPROMData93 = Z
    'Write 93, EEPROMData93
    ''-----------------------

    I tried changing the starting address in EE_Vars.pbp from CON 0 to CON 91 and although it compiles it doesn't work but when I comment out your eeprom saving routine and use the program below, the X10 code turns On and Off the X10 appliance modules and saving to the eeprom works like a charm.

    As I mentioned in my previous post, when I comment out the con 0 in EE_Vars.pbp and include it in my program as con 91 I get " ERROR Line 24: Redefinition of CON EE_start.(EE_Vars.PBP) " when I try to compile.

    It was only a guess on my part that the firecracker code was using some of the same address's as EE_Vars.PBP was using. I still don't quite understand mathematically how the address's of the various eeprom and other registry locations work using the Decimal, Hex and Binary number Systems. I should have stayed in school instead of being a juvenile delinquent then this would be a lot easier but I guess it's better late than never to get a little savy and this is interesting! Any ideas on what's happening with this?

    Thanks
    jessey

    Code:
    '* Name    : Test Program for the Firecracker Interface 
    '* Author  : Jessey Montgomery
    '* Includes: Al Williams Firecracker Interface 
    '* Date    : April 24/th 2009
    '* Version : Using PicBasic Pro Ver 2.50, MPASM Ver 5.20, Using MicroCode
    '*         : Studio 3.0.0.5, PICkit 2 programmer - Application Version
    '*         : 2.50.02 - Device File Version 1.5100 - OS Firmware Version
    '*         : 2.30.01. Using a Pic16F688-I/P 04470AY.
    
    
    '(1) Comments & Objectives
    '   =====================
    ' this program is just a test program for checking the firecracker
    
     '              Clear Each Port Before Setting The TRIS Registers  
                                    
     Clear   ' Set all ram registers to zero
     PORTA = 0
     PORTC = 0                           
    
     '                            VSS VDD Pins  
     
     'VDD +       '(pin 1)
     'VSS -       '(pin 14)
                           
     '                    SET THE TRIS 
    
     '                     PORTA PINS
    
     TRISA.0 = 0 '(pin 13) Not Used VAR PORTA.0   
     TRISA.1 = 0 '(pin 12) ..........................................Led VAR PORTA.1    
     TRISA.2 = 1 '(pin 11) ..................................Push_Button VAR PORTA.2
     TRISA.3 = 0 '(pin 4)  Not Used VAR PORTA.3       
     TRISA.4 = 0 '(pin 3)  .....connect to red wire of firecracker - dtr VAR PORTA.4         
     TRISA.5 = 0 '(pin 2)  ...connect to green wire of firecracker - rts VAR PORTA.5      
                                                       
     '                     PORTC PINS 
     
     TRISC.0 = 0 '(pin 10) Not Used VAR PORTC.0   
     TRISC.1 = 0 '(pin 9)  Not Used VAR PORTC.1 
     TRISC.2 = 0 '(pin 8)  Not Used VAR PORTC.2             
     TRISC.3 = 0 '(pin 7)  Not Used VAR PORTC.3  
     TRISC.4 = 0 '(pin 6)  Not Used VAR PORTC.4    
     TRISC.5 = 0 '(pin 5)  Not Used VAR PORTC.5
    
    
    '(2) PIC Config Fuse Definitions for 16f688 
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF & _BOD_ON 
    @ ERRORLEVEL -306; 
    
     '(3) PIC Hardware Definitions (ie Pin-Out & Port Assignments)
     ANSEL = 0          ' all pins are digital 
     CMCON0 = 7         ' turn off comparators
     OSCCON.3 = 1       ' Use internal clock 
     OSCCON = %1110111  ' Use Internal OSC at 8MHz
    
     Push_Button VAR PORTA.2 ' pin 11 
     Led var PORTA.1         ' pin 12 
    
    ' Firecracker Interface (Al Williams)
     rts VAR PORTA.5 ' pin 2 connects to DB9 pin 4 of the firecracker (green wire)
     dtr VAR PORTA.4 ' pin 3 connects to DB9 pin 7 of the firecracker (red wire)
    
     a VAR BYTE
     a = 0  
     Timer VAR byte
     Timer = 0 
    
    ' byte to send 
     byt var byte  
     tmp var byte
     i var BYTE 'was a nib
     state var bit(4)
     house var byte '0=A 1=B...
     unit var BYTE  ' 0-15  (must be 0 for bright/dim) 'was a nib
     cmd var BYTE  ' 0=off 1=on 2=bright 3=dim 'was a nib
    
     Is_Pressed CON 0
     Is_Not_Pressed CON 1
     Is_Turned_On CON 1
     Is_Turned_Off CON 0
    
     h1 con $D5
     h2 con $AA
     foot con $AD
    
    '4a. EEPROM Assignments
    '    ================== 
    ' 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 
    
    EEPROMData91 var BYTE
    X VAR EEPROMData91
    READ 91, EEPROMData91 
    '' To write to the eprom 
    '' =====================
    'EEPROMData91 = X 
    'Write 91, EEPROMData91         
    '------------------------ 
    EEPROMData92 var BYTE
    Y VAR EEPROMData92 
    READ 92, EEPROMData92 
    '' To write to the eprom 
    '' =====================
    'EEPROMData92 = Y 
    'Write 92, EEPROMData92         
    '------------------------ 
    EEPROMData93 var BYTE
    Z VAR EEPROMData93
    READ 93, EEPROMData93 
    '' To write to the eprom 
    '' ===================== 
    'EEPROMData93 = Z 
    'Write 93, EEPROMData93        
    ''------------------------- 
    
     gosub resetfirecracker 
    
    ' Reset the three X10 modules to the states they were before the power-loss 
    
     IF X = 1 THEN   
        house = 0 : unit = 4 : cmd = 1 'when unit = 4 in code, set X10 receiver to 5
        gosub sendcmd : PAUSE 1000    
     ELSE 
        house = 0 : unit = 4 : cmd = 0  
        gosub sendcmd : PAUSE 1000   
     ENDIF
    
     IF Y = 1 THEN 
        house = 0 : unit = 2 : cmd = 1 'when unit = 2 in code, set X10 receiver to 3 
        gosub sendcmd : PAUSE 1000   
     ELSE   
        house = 0 : unit = 2 : cmd = 0 
        gosub sendcmd : PAUSE 1000   
     ENDIF
    
     IF Z = 1 THEN
        house = 0 : unit = 3 : cmd = 1 'when unit = 3 in code, set X10 receiver to 4 
        gosub sendcmd : PAUSE 1000   
     ELSE  
        house = 0 : unit = 3 : cmd = 0  
        gosub sendcmd : PAUSE 1000   
     ENDIF 
     Led = Is_Turned_On
     PAUSE 200
     Led = Is_Turned_Off
    
    IF a = 0 THEN MainLoop ' a always equals zero, use instead of GOTO... 
    
    ' Start Of Subroutines Area Below 
    ' ===============================
    
    ' Firecracker Interface by (Al Williams)
    ' http://www.awce.com/firecracker.htm 
    sendcmd:
      byt=h1
      gosub sendbyte
      byt=h2
      gosub sendbyte
      read housetbl+house,byt
      if unit<9 then lowunit
      byt=byt+4
    lowunit:
      gosub sendbyte
      byt=$20
      if cmd=0 then addunit
      byt=0
      if cmd=1 then addunit
      byt=$88              
                         
      if cmd=2 then nounit 
      byt=$98              
      if cmd=3 then nounit 
    ' huh???
    
    addunit:
      read unittbl+(unit//8),tmp
      byt=byt+tmp
    nounit:
      gosub sendbyte
      byt=foot
      gosub sendbyte
    return
    
    ' Send 1 raw byte
    sendbyte:
      debug hex byt," "
      for i=0 to 7
       if (byt & $80) = $80 then xmit1
       gosub send0
    nextbit:
       pause 1
       byt=byt*2
       next
       return
    
    ' Send a 1
    xmit1:
      gosub send1
      IF a = 0 THEN nextbit
    
    ' Send bits (0 or 1)
    send0:
      low rts
      pause 1
      high rts
      return
    
    send1:
      low dtr
      pause 1
      high dtr
      return
    
    ' Always reset firecracker first   
    resetfirecracker:
    low rts
    low dtr
    pause 50  ' reset
    high rts
    high dtr
    pause 50
    return
    '============'
    
    Turn_On_Or_Off_4:
        if X = 0 then ' X toggles the #4 X10 module On/or/Off with each button press 
           X = 1      ' Turn On
           house = 0 : unit = 4 : cmd = 1 'when unit=4 in code,set X10 receiver to 5
           gosub sendcmd  
        ELSE
           X = 0      ' Turn Off 
           house = 0 : unit = 4 : cmd = 0   
           gosub sendcmd 
        ENDIF
        EEPROMData91 = X 
        Write 91, EEPROMData91         
    '@  EE_write_var  _X    
    RETURN
    
    Turn_On_Or_Off_3:
        if Y = 0 then ' Y toggles the #3 X10 module On/or/Off with each button press 
           Y = 1      ' Turn On
           house = 0 : unit = 2 : cmd = 1 'when unit=2 in code,set X10 receiver to 3 
           gosub sendcmd 
        ELSE
           Y = 0      ' Turn Off
           house = 0 : unit = 2 : cmd = 0  
           gosub sendcmd 
        ENDIF 
        EEPROMData92 = Y 
        Write 92, EEPROMData92          
    '@  EE_write_var  _Y 
    RETURN
    
    Turn_On_Or_Off_5:
        if Z = 0 then ' Z toggles the #4 X10 module On/or/Off with each button press 
           Z = 1      ' Turn On
           house = 0 : unit = 3 : cmd = 1 'when unit=3 in code,set X10 receiver to 4 
           gosub sendcmd
        ELSE
           Z = 0      ' Turn Off
           house = 0 : unit = 3 : cmd = 0  
           gosub sendcmd
        ENDIF
        EEPROMData93 = Z
        Write 93, EEPROMData93
    '@  EE_write_var  _Z  
    RETURN 
    
    'XXXXXXXXXXX'
    
    MainLoop:
    
     IF Push_Button = Is_Pressed THEN 
       Timer = 0
       WHILE Push_Button = Is_Pressed
         Timer = Timer + 1 
         IF Timer = 1 THEN Led = Is_Turned_On
         IF Timer = 2 THEN Led = Is_Turned_Off
         IF Timer = 3 THEN Led = Is_Turned_On
         IF Timer = 4 THEN Led = Is_Turned_Off
         IF Timer = 5 THEN Led = Is_Turned_On
         IF Timer = 6 THEN Led = Is_Turned_Off
         PAUSE 500
       WEND
         Led = Is_Turned_Off                
         PAUSE 100 ' Debounce   
         IF Timer = 1 THEN GOSUB Turn_On_Or_Off_3
         IF Timer = 2 THEN GOSUB Turn_On_Or_Off_3
         IF Timer = 3 THEN GOSUB Turn_On_Or_Off_4
         IF Timer = 4 THEN GOSUB Turn_On_Or_Off_4 
         IF Timer = 5 THEN GOSUB Turn_On_Or_Off_5
         IF Timer >= 6 THEN GOSUB Turn_On_Or_Off_5
     ENDIF 
             
    IF a = 0 THEN MainLoop 
    
    End

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


    Did you find this post helpful? Yes | No

    Default

    Well, since brittons (in the EE_vars thread) appeared to have a similar problem changing the EE_start location ... I figured I better take another look.

    So I did.
    I've checked it starting at the default 0 location in EEPROM, and changed EE_start to several other values, and added DATA statements to duplicate your situation ... all with the same results.
    I does exactly what it's supposed to do. The EE_var locations move to the appropriate places and everything works fine.

    I don't have a Firecracker, so can't test that part.

    The only thing I can see in your code, is that you've set the internal oscillator to 8Mhz, but didn't put a DEFINE OSC 8 in there. PBP will default to 4Mhz and all those pauses will only be half as long.

    That doesn't explain ANY of the described problems, but it needs to be fixed before you'll be able to see the REAL problem.
    <br>
    DT

  3. #3
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default still no go

    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

  4. #4
    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

  5. #5
    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

  6. #6
    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

  7. #7
    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

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

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