Question: Project Name: _ ADC _ Compare _ ANO Description: - This program reads the Analog voltage from the potentiometer on input AN 0 (

Project Name:
_ADC_Compare_ANO
Description:- This program reads the Analog voltage from the potentiometer on input "AN0(RA0)" and turns ON the LED connected to pin "RB0" if the input voltage is greater than approximately 2.5 V . The LED is turned OFF if the input voltage is less than approximately 2.5 V .
Tip: In Proteus, use Page Up/Page Down keys to adjust the Pot value while hovering over it
Instructions:-
1. Create a macro name for the LED:-
E.g.\#define LED RB0
2. Create a macro name for ON and OFF :-
E.g.\#define ON 1
\#define OFF 0
3. Use the macros listed above in your program.
4. Setup RB0 pin as a Digital Output.
5. Setup AN0/RA0 pin as an Analog input.
6. Setup the ADC as follows (see ADCON0\& ADCON1 registers on pages 114/115 of the PIC16F188 Datasheet):-
ADCON0
- Setup "ADCS \(1: 0>\)" bits to select the internal RC oscillator
- Setup "CHS2:0>" to select Channel 0(i.e. RA0/AN0)
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 A/D module
ADCON1
- Setup "ADFM" bit to select Left Justified result
- Setup "ADCS2" bit as disabled
- Setup "VCFG \(1: 0>\)" bits to use AVDD and AVss
7. Create an 8-bit variable called "adc_val" to store the value of the ADC result.
8. Inside a continuous loop, start an AD C conversion by writing to the "GO_DONE" bit.
9. Wait until the ADC conversion has completed.
10. Turn ON the LED connected to pin RBO if the digitised input voltage adc_val is greater than or equal to 2.5 V otherwise turn OFF the LED.
11. Add comments to your code (marks lost for no comments).
12. Ensure all code is properly indented (i.e. marks lost for no indentation).
Inputs:-1(i.e. AN0(RA0))
Outputs:-1(i.e RB0)
Project Name: _ ADC _ Compare _ ANO Description:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!