eliminating or substitutes for a DO / LOOP
gc3076
Posts: 44
I have tried to code a project in two stages and in doing so have created (2)·DO/LOOPs in each stage of the project.
The problem I now encounter is·when I merged the two programs. The way I merged was·I made the main body of each project a GOSUB and·moved the DO / LOOP·to encompass the whole project. However this still leaves a set of DO-LOOPs in each of the newly created GOSUBs. This prevents the merged·code from working coreectly. I have checked with the DEBUG that each work correctly ·independantly.
Is there a way to change the code so that something other than a DO/LOOP· is used in these newly created subroutines ? Thus giving the same result but not preventing the code from executing on?
The problem I now encounter is·when I merged the two programs. The way I merged was·I made the main body of each project a GOSUB and·moved the DO / LOOP·to encompass the whole project. However this still leaves a set of DO-LOOPs in each of the newly created GOSUBs. This prevents the merged·code from working coreectly. I have checked with the DEBUG that each work correctly ·independantly.
Is there a way to change the code so that something other than a DO/LOOP· is used in these newly created subroutines ? Thus giving the same result but not preventing the code from executing on?
Comments
Lee Harker
The escape variable can cossists by I/O input too...
example code:
GOSUB part1
GOSUB part2
part1:
DO
.
.
.
LOOP WHILE (IN4 = 1)
RETURN
part2:
DO
.
.
.
LOOP WHILE (variable = 0)
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
running = 1
'
[noparse][[/noparse] Program Code hall sensor]
Main:
DO ' will be moved to encompass whole program
GOSUB Check_Sensor ' scan the sensor
CW_rotation = CW_rotation + (hall_sensor * running) ' update count when running
DO WHILE (hall_sensor = 1) ' would like to delete
GOSUB Check_Sensor
SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls, LcdOn]
SEROUT LcdPin,LcdBaudMode, [noparse][[/noparse]Line1, "CW count:"]
SEROUT Lcdpin, LcdBaudMode,LcdCls, [noparse][[/noparse]" ", DEC CW_rotation]
LOOP ' would like to delete
LOOP' will be moved to encompass whole program
END
'
[noparse][[/noparse] Subroutine hall-sensor ]
Check_Sensor:
hall_sensor = 1 ' assume active
hall_sensor = hall_sensor & ~A_hall_pin ' hall sensor stays active
PAUSE 1
RETURN
Perhaps I'm missing something, but why can't you just do this:
Main:
··· GOSUB Check_Sensor························· ' scan the sensor
······ CW_rotation = CW_rotation + (hall_sensor * running)······· ' update count when running
··· DO WHILE (hall_sensor = 1)······················ ' would like to delete
········· GOSUB Check_Sensor
····· SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls, LcdOn]
····· SEROUT LcdPin,LcdBaudMode, [noparse][[/noparse]Line1, "CW count:"]
····· SEROUT Lcdpin, LcdBaudMode,LcdCls, [noparse][[/noparse]" ", DEC CW_rotation]
··· LOOP· ' would like to delete
··GOTO Main:
· END
'
[noparse][[/noparse] Subroutine hall-sensor ]
Check_Sensor:
hall_sensor = 1········· ' assume active
hall_sensor = hall_sensor & ~A_hall_pin· ' hall sensor stays active
··· PAUSE 1
· RETURN
I'm just not sure how or why you were planning to exit the enitre thing.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
The reason I want to get rid of the DO/LOOP is this portion below is going to be merged into another portion of· code and the below·is an endless loop.
I am trying to display two constantly changing values on a 2x16 LCD display. Line0 displays one result and Line1 displays the other. I have both portions of code working independantly however when they merge I can't get past the below.
Probably the way I am counting is not the best?
Main:
··· GOSUB Check_Sensor························· ' scan the sensor
······ CW_rotation = CW_rotation + (hall_sensor * running)······· ' update count when running
··· DO WHILE (hall_sensor = 1)······················ ' would like to delete
········· GOSUB Check_Sensor
····· SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls, LcdOn]
····· SEROUT LcdPin,LcdBaudMode, [noparse][[/noparse]Line1, "CW count:"]
····· SEROUT Lcdpin, LcdBaudMode,LcdCls, [noparse][[/noparse]" ", DEC CW_rotation]
··· LOOP· ' would like to delete
··GOTO Main:
· END
'
[noparse][[/noparse] Subroutine hall-sensor ]
Check_Sensor:
hall_sensor = 1········· ' assume active
hall_sensor = hall_sensor & ~A_hall_pin· ' hall sensor stays active
··· PAUSE 1
· RETURN