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.

[SOLVED] need help in A/D for 18f4431

Status
Not open for further replies.

prem123

Newbie level 5
Newbie level 5
Joined
Jul 11, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,380
can somebody give me a sample code for A/D conversion in mikroc for 18f4431..
or please tell me the error in the following code...


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
40
unsigned int temp_res;
 
void interrupt()
{
 if(PIR1.ADIF){
  PIR1.ADIF=0;
  ADCON0.GO=1;
 }}
 
void main()
{
 TRISB=0x00;
 TRISD=0x00;
 TRISA=0xFF;
 ANSEL0=0b00000001;
 ANSEL1=0x00;
 ADCHS=0x00;
 ADCON0=0b00110101;
 ADCON1=0b00010000;
 ADCON2=0b01000001;
 ADCON3=0b11000000;
 INTCON.GIE=1;
 INTCON.PEIE=1;
 ADCON0.GO=1;
 PIE1.ADIE=1;
 PIR1.ADIF=0;
 Delay_us(10);
 
while(1)
{
 
 PORTD= 0x00;
 PORTB= 0x00;
 temp_res=Adc_Read(0);
 PORTD = temp_res;       // Send lower 8 bits to PORTD
 PORTB = temp_res >> 2;  // Send 2 most significant bits to RB7, RB6
 
 Delay_ms(50);
}
}

 
Last edited by a moderator:

Code:
PORTD= 0x00;
PORTB= 0x00;

what you are trying to do in these lines?
 

it is just to clear ports before showing new values....
 

i think these will makes LOW the two ports of the MCU,you are making these pins low and not given any comment to make it high its inside a infinite loop so wont go out.
 
Last edited:
You should use the ADC_Init(); before while loop to initialize ADC.

Add ADCHS.GASEL1 = 0; and ADCHS.GASEL0 = 0; in the configuration. you should connect AVdd to 5 v and Avss to ground.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top