A2D code for pic18f452

Status
Not open for further replies.

shlomo

Newbie level 3
Joined
Jun 11, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18
Hi everyone/
I'm having a problem using A2D code with mplab c18 .

can anyone tell me if this part of example code is correct?
and if not, whats wrong?


int result;
......
......
......
result=ADRESH;
if(result==0xff)
{
PORTB=0xaa;
}
else
{
PORTB=0xbb;
}


Thanks

Shlomo
 

The code isn't wrong but the 18F452 only has a 10-bit ADC. The lower 8 bits are returned in ADRESL and the upper 2 bits in ADRESH. That means ADRESH can never be equal to 0xFF. The maximum value it can hold is 0x03.

Brian.
 
Reactions: shlomo

    shlomo

    Points: 2
    Helpful Answer Positive Rating
Thank you Brian !

But I wrote in the code:

ADCON1=0x0E // ADFM (bit7)=0 ----> Left justified

Still not working.

Shlomo
 

Zip and post the complete MPLAB project files. We have to see full adc code to answer.
 

Hi
I found my mistake in the a2d code.
The project is a thermometer using p18f452 and lm335,
The temperature value is sending to 2x16 lcd as string-
{"Temp -/+ xxx^C"}

I forgot to use the "#INCLUDE <STRING.H>"
:sad:

Now it's working good/

Shlomo
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…