Help condensing code


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Help condensing code

    How about reading the value at 95 before writing, and if it is the same as Lights then do not do the write.

    Perhaps another suggestion convert your time to all minutes (word) then you only need one test instead of 2.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Help condensing code

    Code:
    Lights var PortB.1
    LightStatus VAR BYTE
    SYMBOL WStatus = LightStatus.0
    ChkLights var bit
    
      
    WStatus = 0
    ChkLights = lights   ' Take status.
    
    IF RTCHour = SetlightOnHour THEN
         IF RTCMin = SetlightOnMin THEN
            Lights = 1
            WStatus = 1   ' set flag for write.
         ENDIF
    ENDIF
    
    IF RTCHour = SetlightOffHour THEN
        IF RTCMin = SetlightOffMin THEN
           Lights = 0
           WStatus = 1   ' set flag for write.
        ENDIF
    ENDIF
    
    if WStatus = 1 then                 ' Flag is set
        if chklights <> lights then     ' and lights pin changed its status; so write.
            WRITE 95, Lights            ' This way, writing to eeprom for entire 1 minute duration is avoided.
            WStatus = 0        ' clear flag. 
        endif
    endif
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Dec 2011
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: Help condensing code

    Thanks aerostar and sayzer!!
    I totally overlooked the fact that it would write for the entire minute. That tip is better than condensing the code!!
    And it only added 1 byte to the program for 4 lights. Now if I could only get the routines for setting the actual time and the time for each light on/off a lot smaller, right now its like 2000 bytes, but thats for me to work out... or go to a bigger pic.

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Help condensing code

    If you are not using LightStatus.1 anywhere in your program, then

    remove "ChkLights var bit" and have this one instead (will save you one byte) : ChkLights var LightStatus.1
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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