16f676 adc with 4 leds
Using
the analog to digital conversion module of 16f676
My
test based on pic16f676 only. We should read the associated datasheet of
manufacturer.
Here,
I use 4 leds to view digital output and 500k ohm potentiometer of variable dc
input to sensing pin.
My
codes . . . . .
'****************************************************************
'* Name
: 16f676_adc_with_4led.pbp *
'* Author
: WAAGYI *
'* Notice
: Copyright (c) 2016 FEEL FREE TO SHARE AND MODIFY *
'* : All Rights Reserved *
'* Date
: 10/11/2016 *
'* Version : 1.0 *
'* Notes
: read adres 10 bit and display result in 4 led *
'* :
*
'****************************************************************
'16f676
analog test
'use
registers
'TRISA
'TRISC
'PORTA
'PORTC
'ADCON0
'ADcon1
'ANSEL
'ADRESL
'ADRESH
'RESS
WORD SIZE VAR
'display
leds are attached to RC0 to RC3
TRISA=000001 'RA0 is analog input
TRISC=000000 'PORTC is OUTPUT
ANSEL=000001 'AN0 channel 0 is selected
led0
var PORTC.0 '4 display leds
led1
var PORTC.1
led2
var PORTC.2
led3
var PORTC.3
RESS
var word '16 bit variable to store
both ADRESL AND ADRESH
ADCON1=000000 'ADCS is Fosc/2
ADCON0=%10000001 'right justify, AN), ADON
loop:
ADCON0=%10000011
pause 10
if ADCON0.1=0 then show
goto loop
show: 'just testing it is working or
not
RESS=ADRESL
RESS.8=ADRESH.0
RESS.9=ADRESH.1
pause 500
if RESS<256 then display_255
if ress>256 and REss<511 then
display_510
if ress>510 and REss<788 then
display_765
if ress>785 and REss<1024 then
display_1023
goto loop
display_255:
high led0
pause 50
goto loop
display_510:
high led1
high led0
pause 50
goto loop
display_765:
high led1
high led2
HIGH led0
pause 50
goto loop
display_1023:
high led1
high led2
high led3
HIGH led0
pause 50
goto loop
end 'END OF CODING
The codes are not perfect and lengthly. I did not read the example codes of pbp. It is very helpful.
Comments
Post a Comment