jessey
- 19th June 2005, 05:01
Hello,
I was wondering if someone could review some code I wrote and make suggestions on any different approaches or more efficient ways of accomplishing this? I have these 2 segments of code that will be read in the mainloop. Of these 2 segments of code only one will be true so only one will be executed. When I first apply power to the circuit then one of these blocks of code is only executed once and also whenever I switch from operating the circuit on batteries to a 120 VAC transformer (or vise versa) then the other code segment will be true and will be executed again but only once while in the mainloop. The reason that I want to do this is that I have other If...Then statements that use this same variable to accomplish other tasks in the mainloop.
Here are the two segments code:
Circuit_Is_Powered_By VAR PORTC.5 'when the transformer is plugged in, a 1 is placed here.
The_Transformer CON 1
The_Batteries CON 0
IF Circuit_Is_Powered_By = The_Batteries THEN
U = 0
ELSE
U = U + 1
ENDIF
IF U >= 2 THEN U = 2 'prevents the var from rolling over & equaling 1 again
'----------------------- First Segment Of Code -----------------------------'
IF Circuit_Is_Powered_By = The_Transformer AND U = 1 THEN
this is where I place the code that I want to be read only
once whenever the transformer is powering the circuit.
ENDIF
----------------------------------------------------------------------------------------------------------------
IF Circuit_Is_Powered_By = The_Transformer THEN
V = 0
ELSE
V = V + 1
ENDIF
IF V >= 2 THEN V = 2 'prevents the var from rolling over & equaling 1 again
'---------------------- Second Segment Of Code -----------------------------'
IF Circuit_Is_Powered_By = The_Batteries AND V = 1 THEN
this is where I place the code that I want to be read only
once whenever the batteries are powering the circuit
ENDIF
----------------------------------------------------------------------------------------------------------------
Any comments or suggestions will be gratefully accepted.
Thanks jessey
I was wondering if someone could review some code I wrote and make suggestions on any different approaches or more efficient ways of accomplishing this? I have these 2 segments of code that will be read in the mainloop. Of these 2 segments of code only one will be true so only one will be executed. When I first apply power to the circuit then one of these blocks of code is only executed once and also whenever I switch from operating the circuit on batteries to a 120 VAC transformer (or vise versa) then the other code segment will be true and will be executed again but only once while in the mainloop. The reason that I want to do this is that I have other If...Then statements that use this same variable to accomplish other tasks in the mainloop.
Here are the two segments code:
Circuit_Is_Powered_By VAR PORTC.5 'when the transformer is plugged in, a 1 is placed here.
The_Transformer CON 1
The_Batteries CON 0
IF Circuit_Is_Powered_By = The_Batteries THEN
U = 0
ELSE
U = U + 1
ENDIF
IF U >= 2 THEN U = 2 'prevents the var from rolling over & equaling 1 again
'----------------------- First Segment Of Code -----------------------------'
IF Circuit_Is_Powered_By = The_Transformer AND U = 1 THEN
this is where I place the code that I want to be read only
once whenever the transformer is powering the circuit.
ENDIF
----------------------------------------------------------------------------------------------------------------
IF Circuit_Is_Powered_By = The_Transformer THEN
V = 0
ELSE
V = V + 1
ENDIF
IF V >= 2 THEN V = 2 'prevents the var from rolling over & equaling 1 again
'---------------------- Second Segment Of Code -----------------------------'
IF Circuit_Is_Powered_By = The_Batteries AND V = 1 THEN
this is where I place the code that I want to be read only
once whenever the batteries are powering the circuit
ENDIF
----------------------------------------------------------------------------------------------------------------
Any comments or suggestions will be gratefully accepted.
Thanks jessey