'**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 10/4/2005 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** DEFINE OSC 4 ' Define ADCIN parameters DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source (3=rc) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS pulseRange VAR WORD sensorValue VAR WORD ' Create variable to store result TRISA = %11111111 ' Set PORTA to all input ADCON1 = %10000010 ' Set PORTA analog and right justify result PAUSE 500 ' Wait .5 second start: pulseWidth VAR WORD ' set up constants with the minimum and maximum pulsewidths minPulse CON 50 maxPulse CON 250 ' set up a constant with the time between pulses: refreshPeriod CON 5 ' set an initial pulsewidth: pulseWidth = minPulse pulseRange = maxPulse - minPulse main: ADCIN 0, sensorValue ' Read channel 0 to sensorVal 'take the output pin low so we can pulse it high LOW PORTC.3 ' pulse the pin PULSOUT PORTC.3, pulseWidth ' pause for as long as needed: PAUSE refreshPeriod ' change the angle for the next time around: pulseWidth = minPulse + (pulseRange * (sensorValue/4)) / 100 GOTO main