' RA2 Pot connection
' RB4 LED4
' RB3 LED3
' RB2 LED2
' RB1 LED1
' RB0 LED0
'-------------------- Revision History ----------------------------------------
include "pbppic14.lib"
include "16F877.bas"
'-------------------- Constants and Defines -----------------------------------
'Define ACDIN parameters
Define ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source ( 3 = RC )
DEFINE ADC_SAMPLEUS 50 ' Set sampling time to micro-seconds
'-------------------- Variables -----------------------------------------------
adval var byte ' Create adval to store result
PortB = %00000000 ' All outputs off to start
TrisB = %00000000 ' All of PortB is Outputs
MAIN:
TRISA = %00111111 ' Set PortA to all Inputs
ADCON1 = %00000010 ' Set PortA Analogue
LOOP:
ADCIN 2, adval ' Read channel to Adval
'******************* Let's Drive some LEDS ************************************
Ledtst1:
if adval > 25 tHEN tst2 ' If A/D val is less than 25 then
PortB = %0000001 ' light LED0 only
goto cont ' Continue with Programme
tst2:
if adval > 75 then tst3 ' If A/D val is between 25 - 75
PortB = %00000011 ' light LED0 - LED1 only
goto cont ' Continue with Programme
tst3:
if adval > 125 then tst4 ' If A/D val is between 75 - 125
PortB = %00000111 ' light LED0 - LED2 only
Goto cont ' Continue with Programme
tst4:
if adval = 175 then tst5 ' If A/D val is between 125 - 175
PortB = %00001111 ' light LED0 - LED3 only
goto cont ' Continue with Programme
tst5:
PortB = %00011111 ' If A/D value is greater than 175
' Then light all LEDS0 - 4
cont:
Pause 100 ' wiat 1 second
goto LOOP ' Go back to LOOP
end
Bookmarks