Question: Using MPLAB - ADC _ LED _ Port _ 1 0 Bit Project Name: _ ADC _ LED _ 1 0 Bit Description: - This

Using MPLAB - ADC_LED_Port_10Bit
Project Name: _ADC_LED_10Bit
Description:- This program reads the Analog voltage from the potentiometer on input "AN0(RA0)" and turns ON the 10 LEDs connected to ports \(\mathrm{RA}2: 1>\) and \(\mathrm{RB}7: 0>\). The number of LEDs illimunated on \(\mathrm{RA}2: 1>\) and \(\mathrm{RB}7: 0>\) is a 10-bit binary representation of the ADC value.
Instructions:-
1. Setup AN0/RA0 pin as an Analog input.
Note:- Ensure to set ANS2 and ANS1 bits high as there is unexplained operation for this exercise if ANS2 and ANS1 bits are low.
ANSEL =0b11111111; // Ensure to set ANS2 and ANS1 bits high
2. Setup PORTA pins RA2:1> as Digital Outputs
3. Setup PORTB pins \(\mathrm{RB}7: 0>\) as Digital Outputs.
4. Setup the ADC as follows (see ADCON0\& ADCON1 registers on pages 114/115 of the PIC16F188 Datasheet):-
ADCON0
- Setup "ADCS1:0>" bits to select the internal RC oscillator
- Setup "CHS2:0>" to select Channel 0(i.e. RA0/AN0)
- Setup "ADON" bit to turn on A/D module
ADCON1
- Setup "ADFM" bit to select Right Justified result
- Setup "ADCS2" bit as disabled
- Setup "VCFG \(1: 0>\)" bits to use AVDD and AVss
5. Inside a continuous loop, start an ADC conversion by writing to the "GO_DONE" bit.
6. Wait until the ADC conversion has completed.
7. Use ADRESH and ADRESL to drive pins RA2:1> and RB 7:0>(i.e. PORTB) respectively. There is no need to create a variable here since ADRESL and ADRESH values can be used to drive the PORT pins directly.
Tip: For PORTA pins RA2:1> use bit masking:-
(e.g. PORTA \(=\) PORTA \(/((A D S R E S H \& 0 b 00000011)1)\)
8. Add comments to your code (marks lost for no comments).
9. Ensure all code is properly indented (i.e. marks lost for no indentation).
Inputs:-1(i.e. AN0(RA0))
Outputs:-10(i.e RA2:1>, RB7:0>)
Using MPLAB - ADC _ LED _ Port _ 1 0 Bit Project

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!