start: low c.0 ;turn off interlock transistor low c.2 ;turn off pwm transistor b3=0 ;infrared detect pass counter b4=0 ;infrared detect fail counter wait 1 ;delay loop1: b2=0 ;reset interrupt counter for b0= 1 to 10 ;start loop setint %00000000,%00001000 ;detect infrared status change pwmout c.2, 25, 53 ;transmit 38khz infrared, 50% duty cycle pause 5 ;small delay pwmout c.2, off ;turn off infrared pause 5 ;small delay if pinc.1=0 then loop10 ;check pb status next ;continue loop if b2=10 then loop2: ;all 10 light transmissions received sound c.4,(125,2) ;sound piezo (light detection fail) b4=b4+1 max 3 ;increase fail counter b3=0 ;reset detect pass counter pause 400 ;delay goto loop3 loop2: pause 400 ;delay b3=b3+1 max 3 ;all light pulses recieved, increase counter b4=0 ;reset fail counter loop3: if b3=3 then high c.0 goto loop1 endif ;turn on interlock transister/led if b4=3 then: low c.0 endif ;turn off interlock transister/led goto loop1 interrupt: ;interrupt routine pwmout c.2, off ;turn off pwm transistor b2=b2+1 ;increment interrupt counter return loop10: sound c.4,(124,5,123,5,124,5) ;acknowledge pb press pwmout c.2, off ;turn off pwm transistor high c.0 ;turn on interlock transister/led pause 60000 ;pause 60 seconds pause 60000 ;pause 60 seconds goto start