Code:
@ DEVICE pic16f877a,WDT_ON, PWRT_ON, BOD_ON
DEFINE OSC 4
define ADIN_RES 10
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
RLH VAR word
SLM var word
position var word
COUNT1 VAR BYTE ' COUNTER FOR PORTD.5
COUNT2 VAR BYTE ' COUNTER FOR PORTD.6
TRISA = %00000011
TRISB = %00000000
TRISD.0 = %0
TRISD.1 = %0
ADCON0 = %11000101
ADCON1 = %10000000
low portd.7
COUNT1 = 0
COUNT2 = 0
START:
ADCIN 0 , RLH
ADCIN 1 , SLM
IF (PORTD.5=1) AND (COUNT1<50) THEN SKIP1 '50 LOOPS WILL BE ~1 SEC
IF RLH =< 621 then
high PORTD.5
else
low PORTD.5
endif
COUNT1 = 0
SKIP1:
IF (PORTD.6=1) AND (COUNT2<50) THEN SKIP2
IF SLM => 621 then
high PORTD.6
position = 100
else
low PORTD.6
position = 170
endif
COUNT2 = 0
SKIP2:
PULSOUT PORTD.7, position
pause 18
COUNT1 = COUNT1 + 1
COUNT2 = COUNT2 + 1
GOTO START
QUOTE]
I made some assumptions here. I assumed if you wanted to keep them high, you didn't need to check the sensor readings.
I used 50 for the loop count because of this: pulseout will be between 1-2 mSec, then an 18mSec pause. this is 19-20 mSec. * 5= .1sec * 10 = 1 sec. This won't be exact, but you can play with the numbers to get it right
Bookmarks