Hi Jessey,
Here are the code snippets I created to handle the inputs to my project. I used a 4051 with 8 inputs feeding into a window comparator. The two outputs of the window comparator gave me one signal for loop open condition and another for loop shorted condition. PortC pins 5,6, and 7 were the bcd out to select one of 8 inputs to be tested by the micro. First is tested for an open loop, then it tested for a shorted loop. If either condition was already handled then a bit flag is set when the condition is first handled and the bit flag gets reset when the reset of the condition is handled. I did this code 3 years ago and was my first big project so the coding is rather crude and I'm sure it can be done some other way but it did the job and has been working great in the field since so I guess that's all that matters.
loop0op:
portC.5 = 0: portC.6 = 0: portC.7 = 0 'set portC to look at 1st loop
pause delay 'take a short break
If portA.0 = 0 Then G0on 'if loop is open turn led on
If portA.0 = 1 then G0off 'if loop is normal turn led off
goto loop0sh 'go test for shorts
loop0sh:
If portA.1 = 0 then R0on 'if loop is shorted turn led on
If portA.1 = 1 then R0off 'if loop is normal turn led off
Goto loop1op 'goto next loop
G0on:
If Bit0 = 1 then loop0sh 'if already open goto next test
Portb.0 = 1 'turn led on
Bit0 = 1 'set flag that loop is open
Goto loop0sh 'go test for shorts
G0off:
If Bit0 = 0 then loop0sh 'If loop is normal goto short test
Portb.0 = 0 'turn led off
Bit0 = 0 'reset flag
Goto loop1op 'goto next test
R0on:
If Bit8 =1 then loop1op 'if already tripped goto next loop
PortD.0 = 1 'turn led on
B2 = 120 'set apt #
gosub Sendata 'send apt # to main display board
Pause 10
Bit8 = 1 'set flag that we're tripped
Goto loop1op 'goto next test
R0off:
PortD.0 = 0 'turn led off
pause 10
if bit8 = 0 then loop1op 'if flag already cleared then next loop
B2 = 280 'restore code for 1st zone
gosub Sendata 'send restore report to main board
Bit8 = 0 'clear flag so we're back to normal
Goto loop1op 'goto next test
Hope this helps you!
BobK
Bookmarks