5441336607

5441336607



(884/1024) *5V= 4.32V


The annotated codę to do this is shown below.


#include <pl8cxxx.h>

#include <usart.h>

#include <ADC.h>

#pragma config LVP=OFF #pragma config WDT=OFF

void rx_handler (void); //Declare the ISR function int adc_result; //The variable to storę the ADC value in

void main()

{

RCONbits.IPEN = 1; /* Enable interrupt priority */

IPRlbits.RCIP = 1; /* Make receive interrupt high priority */

INTCONbits.GIEH = 1; /* Enable all high priority interrupts */ OpenADC(ADC_FOSC_32 & ADC_RIGHT_DUST 8 ADC_12_TAD,

ADC_CH0 8 ADC_INT_OFF, 0); //open adc port for reading ADC0N1 =0x00; //set VREF+ to VDD and VREF- to GND (VSS)

while(l)

{

ConvertADC(); //perform ADC conversion while(BusyADC()); //wait for result adc_result = ReadADC(); //get ADC result

//////////////////////////////////////////////////////////////////////// // adc_result is the digital representation of the voltage at pin2 // it is a number out of 1024 that specifies a fraction of VDD ////////////////////////////////////////////////////////////////////////

>

}


Conclusion

This application notę showed how to wire a PIC18F4520 microcontroller for basie voltage sensing and provided some codę to read a voltage from pin 2 of the microcontroller. Also, it explained how to calculate an analog value from the digital result of the ADC measurement. This technique can be combined with any other amount of codę to make a multifunction PIC program capable of reacting to changes in an analog voltage input.




Wyszukiwarka

Podobne podstrony:
skanowanie0029 (18) Even if the teacher hopes to do morę to sharpen students own response to the li
Chapter 5: Help and TroubleshootingView the Installation Documentation To view this document online
Have to want to T1i6 TfiiiicjS I vai]t to Do and The Things I Have to Do Fili in the blanks with hav
cp 49 HOW TO ATTAIN CORRECT POSTURĘ FORE starting 10 tell the reader what to do to attain tlgMj corr
007 6 Sailbaot Connect the dots from A to P. Color. Sara is sailing on a sunny day. O Pmr.ie Schaler
calibre cover CONTORTIONISnHANDBOOK “I swear to God this is the best book I have read in easily five
Starting MySQL as a Windows Service On Windows, the recommended way to run MySQL is to install it as
The Sultan s Labyrinth2 Menu Chck and drag each puzzle piece to the correct spot to complele this le
INDEX TO AUTHORS This index does not include authors listed in the cover-to-cover tables of contents
VPC05 ClosexJ What do you want the virtual machinę to do? Save State Saves the current State of the
WIĘCEJ FILMÓW ^IpH no/IbLUA BMTe/ii % but to do this they need to pass through‘: Ęa nayigable strai
1270361p004591669032327442397 o ► tr*SS The firFt question to ask yourself is why you want to resear
CSG056 The Preterit Tense 45 • Yerbs with i in the stem: hacer (to do)    hic- querer

więcej podobnych podstron