You are also aware that multiple pauses (one in each channel) will affect the time delay in the other channels? Therefore if one channel is on, the loop will have a 50mS delay... if four channels are on then your loop time will be 200mS and your delay will be a lot longer than expected. It would be easier to stick to one delay which is either ON or OFF depending if it is needed...
There is still one dissadvantage here... if a momentary pulse arrives during the 50mS Pause, then it would be missed... but then you can increase the Count time and proportionately decrease the Pause (eg count to 1000 and Pause for 5mS, or Count to 5000 and Pause for 1mS etc etc) - not forgetting to change your variables to WORDS from BYTES if you're going to do this...
Also, if you alias the PORTS as I have done, it makes the program more understandable, and if you have to change I/O's (usually at PCB layout time!!!) then it is done just ONCE in your program, not a dozen times throughout your code where it could easily be missed.
Code:
SwitchA var PortA.0
SwitchB var PortA.3
SensorA var PortA.1
SensorB var PortA.2
LEDA var PortB.2
LEDB var PortB.0
TRISA=%11111111
TRISB=%00000000
Low LEDA
Low LEDB
i=100
j=100
Loop:
'
' Read Inputs
' -----------
If SwitchA=1 then i=0
If SensorA=1 then i=0
If SwitchB=1 then j=0
If SensorB=1 then j=0
'
' Process Outputs
' ---------------
If i < 100 then
High LEDA
else
Low LEDA
endif
If j < 100 then
High LEDB
else
Low LEDB
endif
'
' Update Counters & Timer
' -----------------------
If i < 100 then i=i+1
If j < 100 then j=j+1
If ((i+j)<200) then Pause 50
Goto Loop
Bookmarks