Example code for ADC in mikroc for pic 18f4520

Status
Not open for further replies.

fuuton

Advanced Member level 4
Joined
Jul 21, 2010
Messages
104
Helped
9
Reputation
18
Reaction score
2
Trophy points
1,298
Location
Pakistan, Rawalpindi
Activity points
1,881
hi

can anyone send me some example code for ADC in mikroc for pic 18f4520. thanks
 


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.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…