Analog Input with Pot and LED blink
'This is Basic for Analog INPUT
' PicBasic Pro program to display result of'
'10-bit A/D conversion through serial at 9600 baud''
Set Potentiometer to channel-0 (RA0)
'Analog has 8 channel, RA0 - RA4, AN4 -AN7
'This is really necessary for Analog Input
' 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
'This is really necessary, use for VAR
ADCvar VAR WORD
' Create variable to store result
'This is really necessary for Analog Input
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
Pause 500
' Wait .5 second
main:
'Always put this syntax here, means
'Read Channel 0 (wherever RA0-7, analog input is connected) to adval
ADCIN 0, ADCvar
' Read channel 0 to adval
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out,
' with linefeed(add the line from up and down) and carriage(add the text horizontally) return (10, 13)
GoTo main
' Do it forever
------------------------------
'Set Potentiometer to RA0 and set LED to portd.1
' PicBasic Pro program to display result of'
'10-bit A/D conversion through serial at 9600 baud''
'Connect analog input to channel-0 (RA0)
' 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
ADCvar VAR WORD
' Create variable to store result
TRISA = %11111111
' Set PORTA to all input (---potentiometer is set into RA0 as Analog INPUT)
ADCON1 = %10000010
' Set PORTA analog and right justify result (---Analog Justify)
Pause 500
' Wait .5 second
main:
ADCIN 0, ADCvar
' Read channel 0 to adval
'''''' This is additional if-statement. If the pot is more than 500,
if ADCVAR > 500 then
'LED of portd.1 blinks.
high portd.1
pause 200
low portd.1
pause 200
'Otherwise,
else
high portd.1
endif
pause 100
additional if-statement is ended''''''
'Serial Cable connects RC6 as RX (receive) and RC7 as TX (transmit)
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)
GoTo main
' Do it forever
0 Comments:
Post a Comment
<< Home