Question: Project Name: _ ADC _ Compare _ ANO Description: - This program reads the Analog voltage from the potentiometer on input AN 0 (
Project Name:
ADCCompareANO
Description: This program reads the Analog voltage from the potentiometer on input ANRA and turns ON the LED connected to pin RB if the input voltage is greater than approximately V The LED is turned OFF if the input voltage is less than approximately V
Tip: In Proteus, use Page UpPage Down keys to adjust the Pot value while hovering over it
Instructions:
Create a macro name for the LED:
Eg#define LED RB
Create a macro name for ON and OFF :
Eg#define ON
#define OFF
Use the macros listed above in your program.
Setup RB pin as a Digital Output.
Setup ANRA pin as an Analog input.
Setup the ADC as follows see ADCON& ADCON registers on pages of the PICF Datasheet:
ADCON
Setup "ADCS : bits to select the internal RC oscillator
Setup CHS: to select Channel ie RAAN
Note: you can write directly to ADCONO or you can also write directly to the Channel Select Bits defined in header file:ADCONObits.CHS xx;
Setup "ADON" bit to turn on AD module
ADCON
Setup "ADFM" bit to select Left Justified result
Setup "ADCS bit as disabled
Setup VCFG : bits to use AVDD and AVss
Create an bit variable called "adcval" to store the value of the ADC result.
Inside a continuous loop, start an AD C conversion by writing to the GODONE" bit.
Wait until the ADC conversion has completed.
Turn ON the LED connected to pin RBO if the digitised input voltage adcval is greater than or equal to V otherwise turn OFF the LED.
Add comments to your code marks lost for no comments
Ensure all code is properly indented ie marks lost for no indentation
Inputs:ie ANRA
Outputs:ie RB
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
