'jleblanc 10.29.05: dim LED with pulsout command with 20mHz clock
' Connect a POT at A0 (assumes 0-1023 output) and this
'will dim an LED at portd.2. The LED must be linked to the
'output pin with a 220 ohm resitor then to ground
'dividing adcVar by 10 produced a good range of dimming but
'this may be modified
' 10-bit A/D conversion
' Connect analog input to channel-0 (RA0)
DEFINE OSC 20
' Define ADCIN parameters
' Set number of bits in result
DEFINE ADC_BITS 10
' Set clock source (3=rc)
DEFINE ADC_CLOCK 3
' Set sampling time in microseconds
DEFINE ADC_SAMPLEUS 10
adcVar VAR WORD ' Create variable to store result
' Set PORTA to all input
TRISA = %11111111
' Set up ADCON1
ADCON1 = %10000010
PAUSE 500 ' Wait .5 second
main:
ADCIN 0, adcVar ' Read channel 0
PULSOUT portd.2, adcVar/10
GOTO main