-
Help condensing code
I have now finished my project and it has about 3000 lines of code, probably not written the best way so I am trying to condense some code to pack more features in. Listed below is something I believe could be condensed to save some space.
Code:
Lights var PortB.1
LightStatus VAR BYTE
SYMBOL WStatus = LightStatus.0
IF RTCHour = SetlightOnHour THEN
IF RTCMin = SetlightOnMin THEN
HIGH Lights
WStatus = Lights
WRITE 95, WStatus
ENDIF
ENDIF
IF RTCHour = SetlightOffHour THEN
IF RTCMin = SetlightOffMin THEN
LOW Lights
WStatus = Lights
WRITE 95, WStatus
ENDIF
ENDIF
I want to turn a light on and off at a certain time, then write the value of that port.X to the eeprom to save it incase of power failure but only want to write to the eeprom whenever the port changes state.
Hope someone can point me in the right direction.
Thanks!
-
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.
-
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
-
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.:D
-
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