' 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 15 ' Set sampling time in uS
' Set PORTA to all input
' TRISA = %11111111
input porta.0
input porta.1
' This means AN0 to AN4 are analog
' and AN 5, 6, 7 are digital
ADCON1 = %10000010
adcVar VAR WORD ' ADC result
dutyCycle var byte ' Duty cycle for PWM
adcVar2 VAR WORD
dutyCycle2 var byte
' LED right row
led1 var portb.7
led2 var portb.6
led3 var portb.5
led4 var portb.4
led5 var portb.3
led6 var portb.2
led7 var portb.1
led8 var portb.0
led9 var portd.7
led10 var portd.6
led11 var portd.5
led12 var portd.4
' LED left row
led13 var portc.5
led14 var portc.4
led15 var portd.3
led16 var portd.2
led17 var portd.1
led18 var portd.0
led19 var portc.3
led20 var portc.2
led21 var portc.1
led22 var portc.0
led23 var porte.2
led24 var porte.1
output led1
output led2
output led3
output led4
output led5
output led6
output led7
output led8
output led9
output led10
output led11
output led12
output led13
output led14
output led15
output led16
output led17
output led18
output led19
output led20
output led21
output led22
output led23
output led24
main:
low led1
low led2
low led3
low led4
low led5
low led6
low led7
low led8
low led9
low led10
low led11
low led12
low led13
low led14
low led15
low led16
low led17
low led18
low led19
low led20
low led21
low led22
low led23
low led24
ADCIN 0, adcVar
adcin 1, adcVar2
' config 2 only calls for 1 adcin
' config 1 calls for 3 adcins (adcin 0, adcin 1, adcin 2)
' convert ADC value to a byte value:
dutyCycle = adcVar / 4
dutyCycle2 = adcVar2 / 4
' controlling a linear pot #1
if (5<dutyCycle) and (dutyCycle<20) then
high led1
high led2
high led3
endif
if (21<dutyCycle) and (dutyCycle<40) then
high led3
high led4
high led5
endif
if (41<dutyCycle) and (dutyCycle<60) then
high led5
high led6
high led7
endif
if (61<dutyCycle) and (dutyCycle<80) then
high led7
high led8
high led9
endif
' controlling a linear pot #2
if (81<dutyCycle) and (dutyCycle<100) then
high led9
high led10
high led11
endif
if (101<dutyCycle) and (dutyCycle<120) then
high led11
high led12
high led13
endif
if (121<dutyCycle) and (dutyCycle<140) then
high led13
high led14
high led15
endif
if (141<dutyCycle) and (dutyCycle<160) then
high led15
high led16
high led17
endif
' controlling a linear pot #3
if (161<dutyCycle) and (dutyCycle<180) then
high led17
high led18
high led19
endif
if (181<dutyCycle) and (dutyCycle<200) then
high led19
high led20
high led21
endif
if (201<dutyCycle) and (dutyCycle<220) then
high led21
high led22
high led23
endif
if (221<dutyCycle) and (dutyCycle<255) then
high led23
high led24
endif
serout2 portc.6, 16468, ["dutyCycle= ", DEC dutyCycle, 10, 13]
'serout2 portc.6, 16468, ["dutyCycle2= ", DEC dutyCycle2, 10, 13]
goto main