I made a lot of assumptions since you don't mention the PIC type, osc speed, etc, but something like this should work.
Using RB6 & RB7 as sensor inputs you could have the interrupt generated on change.Code:y var byte x var byte Loop VAR BYTE ' used for delay loop Time CON 25 ' 60 x 25uS = 1500 uS for PAUSEUS loop Sensor1 VAR PORTB.7 ' sensor 1 input Sensor2 VAR PORTB.6 ' sensor 2 input PORTB.4 = 0 ' ununsed output PORTB.5 = 0 ' unused output TRISB = %11000000 ' RB6, RB7 sensor inputs, rest outputs OPTION_REG = 0 ' internal pull-ups off on Interrupt Goto IntService ' where to go on interrupt INTCON = %10001000 ' RB port change interrupt enabled Start: for x= 0 to 20 for y=1 to 50 PORTB = %00001010 for Loop = 0 TO 59 pauseus Time ' pause 25uS per pass allowing faster interrupt next Loop ' service time (assumes 4MHz osc) PORTB = %00001001 for Loop = 0 TO 59 pauseus Time next Loop PORTB = %00000101 for Loop = 0 TO 59 pauseus Time next Loop PORTB = %00000110 for Loop = 0 TO 59 pauseus Time next Loop next y next x GOTO Start ' Assumption on my part here? IntService: ' Object detected by sensors Disable while (Sensor1=1) AND (Sensor2=1) ' stay here until both return low ' do something useful here wend INTCON.0 = 0 ' clear RB port change interrupt flag bit resume Enable ' return after processing object detection end
The Loop with pauseus cuts down on the time it takes for the polled BASIC interrupt to be serviced.




Bookmarks