Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Example code for ADC in mikroc for pic 18f4520

Status
Not open for further replies.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <ADC.h>
#pragma config WDT=OFF
long int count;
int adc_result, loop;
void main()
{
TRISD = 0x04;
PORTDbits.RD0 = 0;
PORTDbits.RD1 = 0;
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD,
ADC_CH0 & ADC_INT_OFF, 0); //open adc port for reading
ADCON1 =0x00; //set VREF+ to VDD and VREF- to GND (VSS)
SetChanADC(ADC_CH3); //Set ADC to Pin 5
while(1)
{
while (PORTDbits.RD2)
{
for(count = 1; count < 40000; count++);
PORTDbits.RD0 = !PORTDbits.RD0;
}
ConvertADC(); //perform ADC conversion
while(BusyADC()); //wait for result
adc_result = ReadADC(); //get ADC result
for(loop = 1; loop < 21; loop++)
{
for(count = 1; count < 20000; count++);
PORTDbits.RD1 = !PORTDbits.RD1;
}
while (PORTDbits.RD2)
{
for(count = 1; count < 40000; count++);
PORTDbits.RD0 = !PORTDbits.RD0;
}
SetChanADC(ADC_CH0); //Set ADC to Pin 2
ConvertADC(); //perform ADC conversion
while(BusyADC()); //wait for result
adc_result = ReadADC(); //get ADC result
}
}



---------- Post added at 23:57 ---------- Previous post was at 23:57 ----------

https://www.egr.msu.edu/classes/ece480/capstone/ForMiniprojects/Lab3.pdf
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top