LinkMTech
- 21st December 2008, 23:20
I'm working on a program using PBP2.47 that would have me repeating sub-routines for multiple input conditions and wondered if it were "allowable" to:
Alias a VAR to a line label, or
Assign a temporary variable name to a previously defined VAR
My direction was this:
Monitor two digital inputs then react upon a change and assign a variable name to the detected input variable.
Scan two other inputs (switch setting) and assign a temporary variable name to VAR Mode.
Here's a snipet of the code that shows my intentions but falls short of compiling.
Start:
' Turn OFF timer and clear registers
T1CON.0 = 0 ' Turn off TMR1
TMR1H = 0 ' Clear TMR1 high byte counter
TMR1L = 0 ' Clear TMR1 low byte counter
T1CON = 48 ' Prescaler set to 1:8, and timer OFF
While (lts = 0) and (rts = 0): wend
pause 10 ' Debounce time
gosub time1 ' Start timer and come back
if (lts = 0) and (rts = 0) then start 'False switch, go back and wait
if (lts = 1) and (rts = 1) then start 'Hazard lights ON, go back
' Check mode select switch position and assign Mode variable
if (msel2 = 0) and (msel3 = 0) then md = 1
if (msel2 = 1) and (msel3 = 0) then md = 2
if (msel2 = 0) and (msel3 = 1) then md = 3
if md = 1 then
mode = timed ' Mode now this label
endif
if md = 2 then
mode = fixed1 ' Mode now this label
endif
if md = 3 then
mode = fixed2 ' Mode now this label
endif
' Check which side activated and assign side variables
if lts = 1 then sd = 1
if rts = 1 then sd = 2
if sd = 1 then
Side_brake = lrl ' Side_brake assigned to this VAR
side = lts ' Side assigned to this VAR
endif
if sd = 2 then
side_brake = rrl
side = rts
endif
goto start
This way one sub-routine can be performed using the "inserted" variable names, such as:
i = 0
HIGH side_brake ' side_brake previously assigned to certain output
FOR i = 1 to 3
PULSOUT side, "x time" ' side previously assigned to certain output
GOSUB ChecknSee ' Monitor inputs during OFF period and return
NEXT i
LOW side_brake
RETURN
I'm hoping I'm doing something feasible but needed someone's help in case I'm close or to stop me before I spiral out of control with an exercise in futility.
Thanks in advance...
Alias a VAR to a line label, or
Assign a temporary variable name to a previously defined VAR
My direction was this:
Monitor two digital inputs then react upon a change and assign a variable name to the detected input variable.
Scan two other inputs (switch setting) and assign a temporary variable name to VAR Mode.
Here's a snipet of the code that shows my intentions but falls short of compiling.
Start:
' Turn OFF timer and clear registers
T1CON.0 = 0 ' Turn off TMR1
TMR1H = 0 ' Clear TMR1 high byte counter
TMR1L = 0 ' Clear TMR1 low byte counter
T1CON = 48 ' Prescaler set to 1:8, and timer OFF
While (lts = 0) and (rts = 0): wend
pause 10 ' Debounce time
gosub time1 ' Start timer and come back
if (lts = 0) and (rts = 0) then start 'False switch, go back and wait
if (lts = 1) and (rts = 1) then start 'Hazard lights ON, go back
' Check mode select switch position and assign Mode variable
if (msel2 = 0) and (msel3 = 0) then md = 1
if (msel2 = 1) and (msel3 = 0) then md = 2
if (msel2 = 0) and (msel3 = 1) then md = 3
if md = 1 then
mode = timed ' Mode now this label
endif
if md = 2 then
mode = fixed1 ' Mode now this label
endif
if md = 3 then
mode = fixed2 ' Mode now this label
endif
' Check which side activated and assign side variables
if lts = 1 then sd = 1
if rts = 1 then sd = 2
if sd = 1 then
Side_brake = lrl ' Side_brake assigned to this VAR
side = lts ' Side assigned to this VAR
endif
if sd = 2 then
side_brake = rrl
side = rts
endif
goto start
This way one sub-routine can be performed using the "inserted" variable names, such as:
i = 0
HIGH side_brake ' side_brake previously assigned to certain output
FOR i = 1 to 3
PULSOUT side, "x time" ' side previously assigned to certain output
GOSUB ChecknSee ' Monitor inputs during OFF period and return
NEXT i
LOW side_brake
RETURN
I'm hoping I'm doing something feasible but needed someone's help in case I'm close or to stop me before I spiral out of control with an exercise in futility.
Thanks in advance...