Changing declared variables names on the fly


Results 1 to 16 of 16

Threaded View

  1. #8
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Partial sucess

    Hello Sayzer,

    Thanks for your code example, I like the way the IncrFlag and the DecrFlag variables work in that you don't have to set it back to 0 and just use "IF DecrFlag THEN", that's cool. I tried your code and it didn't work as posted, in order to save the OnTime & OffTime I had to place Index.0=OffTime & Index.1=OnTime before the write then it would save ok. Another thing I had to do in order to save the on/off times was to change the FOR-NEXT loop from 1 - 10 to 0 - 1 then it saved?

    You and Steve say that EEPROM or DATA will work at Programming time and you have EEPROM 1,[1,2,3,4,5,6,7,8,9,10,101,102,103,104,105,106,107,1 08,109,110] but when I program the code then OnTime shows 2 and OffTime shows 255. As far as I can figure location 1 is OnTime and when I replace 1 in the above EEPROM statement with 8 then after programming then OnTime dose show 8 but I can't figure out how to get address 101 to show anything but 255 using the EEPROM?

    Am I correct in placing Index.1 and Index.0 before the write and if so how would I write to all the other addresses? I've been playing around with the code and can't seem to get it working properly. I'd like to be able to add additional subroutines to program additional on off times.

    Thanks
    jessey

    Code:
    EEPROM 1,[8,2,10,11,12,6,7,8,9,10,101,102,103,104,105,106,107,108,109,110]
    'Keep this command at the first line.
    'this will run only one time during the programming.
    'not each time you power your PIC.
    'These are your initial default values.
    
    
    Increase_OnTime_Push_Button     VAR PORTD.2 '(pin 21)  2nd  
    Decrease_OnTime_Push_Button     VAR PORTB.0 '(pin 33)  3rd  
    Increase_OffTime_Push_Button    VAR PORTB.1 '(pin 34)  4th                 
    Decrease_OffTime_Push_Button    VAR PORTB.2 '(pin 20)  5th  
    Change_Times_Push_Button  VAR PORTD.1       '(pin 35)  6th  
    Led                             VAR PORTA.1 '(pin 3)
    Buzzer                          VAR PORTC.2 '(pin 17)
    IncrFlag VAR BIT
    DecrFlag VAR BIT
    IncrFlag = 0 '0 =  button is NOT pressed. 1= button is pressed.
    DecrFlag = 0
    
    OnTime  VAR byte
    OffTime VAR byte
    Index   VAR byte
    Hour    VAR byte
    HOUR = 0
    
    Is_Pressed      CON 0
    Is_Not_Pressed  CON 1
          
     
    GOTO MainLoop
    
    Change_Times:
        GOSUB buzz
        WHILE Change_Times_Push_Button = Is_Pressed : PAUSE 100 : WEND
    Loop:
    
        IF Increase_OnTime_Push_Button = Is_Pressed THEN
           GOSUB buzz : IncrFlag = 1 : OnTime = OnTime + 1
        ENDIF
    
        IF Decrease_OnTime_Push_Button = Is_Pressed THEN
           GOSUB buzz : IncrFlag = 1 : OnTime = OnTime - 1
        ENDIF
                                       
        IF Increase_OffTime_Push_Button = Is_Pressed THEN
           GOSUB buzz : DecrFlag = 1 : OffTime = OffTime + 1 
        ENDIF
    
        IF Decrease_OffTime_Push_Button = Is_Pressed THEN
           GOSUB buzz : DecrFlag = 1 : OffTime = OffTime - 1 
        ENDIF
    
        IF Change_Times_Push_Button = Is_Pressed THEN
          gosub buzz 
          IF IncrFlag THEN  
             Index.1=OnTime : WRITE 1,OnTime
          ENDIF       
          IF DecrFlag THEN 
             Index.0=OffTime : WRITE 101,OffTime
          ENDIF   
          WHILE Change_Times_Push_Button = Is_Pressed : PAUSE 100 :WEND
          GOTO MainLoop
        ENDIF
    
        LCDOUT $fe,1,   "OnTime  = ",dec Ontime
        LCDOUT $fe, $c0,"OffTime = ",dec OffTime 
        PAUSE 100
    
    GOTO Loop
    
    
    MainLoop:
        IF Change_Times_Push_Button = Is_Pressed THEN goto Change_Times
    
        IF Increase_OnTime_Push_Button = Is_Pressed THEN 
           GOSUB buzz : Hour = Hour + 1
        ENDIF
    
        IF Decrease_OnTime_Push_Button = Is_Pressed THEN
           GOSUB buzz : Hour = Hour - 1 
        ENDIF
    
        FOR Index = 0 to 1
            READ Index , OnTime            ' Read stored ON  time.
            READ Index +100, OffTime       ' Read stored OFF time.
            IF Hour = Ontime  THEN Led = 1 ' If yes, turn ON the relay.
            IF Hour = Offtime THEN Led = 0 ' If yes, turn OFF the relay.
        NEXT Index 
    
        LCDOUT $fe,1,   "Hr=",dec Hour," OnTime=",DEC Ontime
        LCDOUT $fe, $c0,"OffTime = ",DEC OffTime
    
        PAUSE 100
        
    
    GOTO MainLoop     
    
    
    Buzz:
         PWM Buzzer,250,1
         RETURN
    
    END
    Last edited by jessey; - 13th December 2006 at 04:44.

Similar Threads

  1. changing osc on the fly
    By viewgsm in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th February 2010, 15:13
  2. Mode changing on the fly
    By Angus Anderson in forum GSM
    Replies: 1
    Last Post: - 28th November 2006, 08:58
  3. edit names of variables
    By mischl in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th January 2005, 21:00

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