
Originally Posted by
midali
@ Amoque - Also, I tried with () but no effect
In your code () will have no effect because the simple comparisons work as expected. But using () makes the code easier to read and it is good practice to always use them.
@ Alain - 1000X thx for your example.
Alain's code is almost the same as yours
Code:
varb var byte
varb = 0
pause 200
init:
pulsin portc.2 , 1, varb
if varb < 140 or varb > 160 then init
if varb > 140 and varb < 160 then goto beep
goto init
Except he added a pause 100 and a retry just to make sure
Code:
varb var byte
varb = 0
pause 200
init:
pulsin portc.2 , 1, varb
if (varb < 140) or (varb > 160) then init
pause 100
pulsin portc.2 , 1, varb
if (varb < 140) or (varb > 160) then init
if (varb > 140) and (varb < 160) then goto beep
goto init
Your code that works is adding delays in a complicated way and also has a retry.
Code:
init:
pulsin portc.2 , 1, varb
for i = 1 to 50
pulsin portc.2 , 1, varb
varb = varb +1
next i
if varb > 60 then
goto init2
else
goto init
endif
goto init
init2:
pulsin portc.2 , 1, varb
if varb > 160 or varb <140 then goto init
if varb > 140 and varb < 160 then goto beep
goto init2
beep:
...code...
goto beep
It looks to me that on starting the RC a "false signal" is received that satisfies the "if varb > 140 and varb < 160 then goto beep" condition and by adding the delay and retry these "false signals" are trapped. Can you try your modified code above, the one with the added pause 100 and retry in red?
Bookmarks