This is driving me Nuts, I don't seem to be able to get the outputs to advance properly. Can some kind person please show me the error of ways before I blow a gasket!
What seems to happen is the 'portstep' instruction steps from 0 to 1 and Port 1 goes high, but next time round it ignores thr portstep = portstep + 1
'An RC Switch Program for 10F202 Pos Working
dir GPIO b'001000'
'make GPIO.3 a digital input
goto Initialise
Main:
'This Do-Loop should be about 16 instrucions, or 16 us
'1 instr BTFSS, 12 instr wait 12 us (or use 12 nop's), 1 instr incf, 2 instr goto
Do While Rx_Input On
wait 12 us
Count = Count + 1
Loop
If count > 10 then
newcount = count
end if
count = 0
If newcount > 80 Then
Set LED On
Goto Port_Out
End If
goto Main
Port_Out:
portstep = portstep + 1
wait 1 s
Set LED Off
newcount = 0
If portstep = 1 Then
Set Port_1 On
End if
Goto Main
If portstep = 2 Then
Set Port_1 Off
End if
portstep = 0
Goto Main
Initialise:
count = 0
portstep = 0
Set Port_1 Off
Set Port_2 Off
Set Port_3 Off
Set Port_4 Off
Goto Main:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is driving me Nuts, I don't seem to be able to get the outputs to advance properly. Can some kind person please show me the error of ways before I blow a gasket!
What seems to happen is the 'portstep' instruction steps from 0 to 1 and Port 1 goes high, but next time round it ignores thr portstep = portstep + 1
;Chip Settings
#chip 12F508,4
#config MCLRE=OFF, CP=OFF, WDT=OFF, OSC=INTRC
;Defines (Constants)
#define RX_Input GPIO.3
#define Port_1 GPIO.0
#define Port_2 GPIO.1
#define Port_3 GPIO.2
#define Port_4 GPIO.4
#define LED GPIO.5
'An RC Switch Program for 10F202 Pos Working
dir GPIO b'001000'
'make GPIO.3 a digital input
goto Initialise
Main:
'This Do-Loop should be about 16 instrucions, or 16 us
'1 instr BTFSS, 12 instr wait 12 us (or use 12 nop's), 1 instr incf, 2 instr goto
Do While Rx_Input On
wait 12 us
Count = Count + 1
Loop
If count > 10 then
newcount = count
end if
count = 0
If newcount > 80 Then
Set LED On
Goto Port_Out
End If
goto Main
Port_Out:
portstep = portstep + 1
wait 1 s
Set LED Off
newcount = 0
If portstep = 1 Then
Set Port_1 On
End if
Goto Main
If portstep = 2 Then
Set Port_1 Off
End if
portstep = 0
Goto Main
Initialise:
count = 0
portstep = 0
Set Port_1 Off
Set Port_2 Off
Set Port_3 Off
Set Port_4 Off
Goto Main:
Never gets to If portstep = 2 Then…. because it goes back to Main beforehand, Put the "goto Main" inside the If portstep = 1 Then……..
Thanks again Kent, it works just fine now!
(what a Muppet am I )
I think if you line up your "end if" with your "if" statements you would have caught the mistake. And it reads a lot better.
If portstep = 1 Then
Set Port_1 On
End if
Goto Main <-- stands out you never reach code after this goto with no label or fall through
If portstep = 2 Then
Set Port_1 Off
End if
portstep = 0
Goto Main