pic adc help

Thread Starter

corefinder

Joined Oct 6, 2011
55
Rich (BB code):
# include<built_in.h>
int value;
void main()
{
ANSEL=0x01;
TRISB=0;
TRISA=0xFF;
ADCON0=0xC0;
ADCON1=0;
ADCON0|=(1<<0);
do
{
ADCON0|=(1<<1);
while(ADCON0/1);
if(value>500)
PORTB=1;
else
PORTB=0;
}
while(1);
}
5 324 Undeclared identifier 'ANSEL' in expression ledadc2.c
 

tshuck

Joined Oct 18, 2012
3,534
Why, yes, I did forget...:)

I am not familiar with MikroC, so I may not be too much help on that front, but I'm pretty sure that the compiler includes the required files automatically...

What PIC are you using?
 

Thread Starter

corefinder

Joined Oct 6, 2011
55
hey all, I found the solution to my problem so please don't mind the question. The compiler was giving this error because I was using pic16f877 and I dont know if ansel register is defined in its library. Anyway I changed to pic16f887 and it worked fine.
 

Thread Starter

corefinder

Joined Oct 6, 2011
55
Why, yes, I did forget...:)

I am not familiar with MikroC, so I may not be too much help on that front, but I'm pretty sure that the compiler includes the required files automatically...

What PIC are you using?
Thanks for your help and patience. But I think I found solution so I wont bother you for a little while:p
 

tshuck

Joined Oct 18, 2012
3,534
Okay, whatsthatsmell wins the prize! the 16F877 doesn't have an ANSEL register! The ADC pin functions are selected using ADCON1....
 

tshuck

Joined Oct 18, 2012
3,534
i already posted solution in 8th comment:D
Anyway I changed to pic16f887 and it worked fine.
This isn't a solution to your problem, this is a work around. What if you had to use that device in a professional product? Would you tell your boss that you have to buy a new PIC just because you were getting an error?

Anyway, I believe I've already found the proper solution as in my previous post...

For future reference, you cannot hope to program a microcontroller without first reading the datasheet.:)
 

Thread Starter

corefinder

Joined Oct 6, 2011
55
Okay, whatsthatsmell wins the prize! the 16F877 doesn't have an ANSEL register! The ADC pin functions are selected using ADCON1....
I see.. I thought he was just asking and i never gave a thought that he might be giving a hint to check whether this pic supports Ansel register. Great whaatsthatsmell..:)
 

Thread Starter

corefinder

Joined Oct 6, 2011
55
This isn't a solution to your problem, this is a work around. What if you had to use that device in a professional product? Would you tell your boss that you have to buy a new PIC just because you were getting an error?

Anyway, I believe I've already found the proper solution as in my previous post...

For future reference, you cannot hope to program a microcontroller without first reading the datasheet.:)
Very True.. But I thought that every pic might have ansel register. Microchip should work on standardizing its product:cool:
 

absf

Joined Dec 29, 2010
1,968
Very True.. But I thought that every pic might have ansel register. Microchip should work on standardizing its product:cool:
That's not possible. Considering there are so many PIC produced and spaced out in so many years. Some of the PIC dont even have an ADC or UART. Some have banked switched registers and some dont. Some like the 16F84 are being phased out and replaced by 16F628 etc etc.

Like tshuck said... "always read the datasheets before you start to use that particular PIC"
is a piece of good advice.

Allen
 

ErnieM

Joined Apr 24, 2011
8,377
Very True.. But I thought that every pic might have ansel register. Microchip should work on standardizing its product:cool:
They have, but it's not like they can go back and change some very old and near obsolete devices (such as the one you are using) once released.

That is a very bad thing to do to those who are already using it.
 
Top