Check the attached code . The intent is to show usage of preprocessor #define and to let you use DEBUGIN to change the pattern independently of input thus allowing for controlled debugging.
In production ( debugged) working code all you need to comment out the #define debugging and you are set.
Use STOP to stop the code execution at the desired place.
I used debug "here",cr to further identify where the code went / stopped.
As long as you have program memory use the above hints to help you step thru your program.You can comment out DEBUG and STOP as you go.
Please note that I used DEBUGIN without qualifier - it will process only one decimal digit correctly! ( Homework for you!)
' {$STAMP BS2e}
' {$PBASIC 2.5}
pattern VAR Nib
timeout VAR Word
control VAR Word
*** and how does pattern get changed in this loop?
DO
IF pattern=0 THEN GOTO intern1 ' the code gets stuck here
LOOP
intern1:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=2
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern2
LOOP
intern2:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=1
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern3
LOOP
intern3:
HIGH 11
LOW 10
PAUSE 1000
LOW 11
LOW 10
timeOut = 5000dopattern = INDtimeOut = timeOut - 1if timeOut = 0 then goto beginninguntil pattern = 2Whenever I have a block in my code that looks like the above, I encounter a problem. The problem being that it won't go to beginning when timeout=0; it is like the Stamp has difficulties executing the if ...then statement.
Even when I use a a simple test program that contains an IF...THEN ...ELSE ...ENDIF conditioning, the Stamp seems to have ignored the presence of the conditioning.
Assume that nothing affects the execution of the above block; what could be causing the problem?
There are at least two major errors in your code to even compile.
Did you check the compiler errors?
And again IF branches when evaluated to true,
if not it executes ELSE or if just simple IF THEN than it goes to next command.
It takes some practice to string IF(s) properly.
DEBUG is still your friend!
To solve check
syntax for IF ... THEN
and DO...LOOP
timeOut VAR Word
pattern VAR Nib
beginning:
timeOut = 5000
do
pattern = IND
timeOut = timeOut - 1
IF timeOut = 0 THEN GOTO beginning
until pattern = 2
Comments
#define
#if ... #then...#end
DEBUGIN
STOP
Check the attached code . The intent is to show usage of preprocessor #define and to let you use DEBUGIN to change the pattern independently of input thus allowing for controlled debugging.
In production ( debugged) working code all you need to comment out the #define debugging and you are set.
Use STOP to stop the code execution at the desired place.
I used debug "here",cr to further identify where the code went / stopped.
As long as you have program memory use the above hints to help you step thru your program.You can comment out DEBUG and STOP as you go.
Please note that I used DEBUGIN without qualifier - it will process only one decimal digit correctly! ( Homework for you!)
' {$STAMP BS2e}
' {$PBASIC 2.5}
pattern VAR Nib
timeout VAR Word
control VAR Word
#DEFINE debugging
beginning:
pattern = IND
DO
#IF debugging #THEN
DEBUG "input pattern = "
'STOP
DEBUGIN pattern
DEBUG CR,? pattern, CR
STOP
#ELSE
pattern = IND
#ENDIF
'STOP
DEBUG ? pattern, CR
LOOP UNTIL pattern=8
' STOP
DEBUG "here",CR
*** and how does pattern get changed in this loop?
DO
IF pattern=0 THEN GOTO intern1 ' the code gets stuck here
LOOP
intern1:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=2
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern2
LOOP
intern2:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=1
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern3
LOOP
intern3:
HIGH 11
LOW 10
PAUSE 1000
LOW 11
LOW 10
Even when I use a a simple test program that contains an IF...THEN ...ELSE ...ENDIF conditioning, the Stamp seems to have ignored the presence of the conditioning.
Assume that nothing affects the execution of the above block; what could be causing the problem?
I would appreciate your assistance.
Thank You.
Did you check the compiler errors?
And again IF branches when evaluated to true,
if not it executes ELSE or if just simple IF THEN than it goes to next command.
It takes some practice to string IF(s) properly.
DEBUG is still your friend!
To solve check
syntax for IF ... THEN
and DO...LOOP
timeOut VAR Word
pattern VAR Nib
beginning:
timeOut = 5000
do
pattern = IND
timeOut = timeOut - 1
IF timeOut = 0 THEN GOTO beginning
until pattern = 2
Suggstion
When you write code for IF start with
IF .... THEN....
ENDIF
And then fill out the blanks
Same for DO
DO
....
LOOP UNTIL....
And then fill out the blanks
Vaclav
Thank you.
I will try out your suggestions.