1. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    Code ( (Unknown Language)):
    1.  
    2. # include<built_in.h>
    3. int value;
    4. void main()
    5. {
    6. ANSEL=0x01;
    7. TRISB=0;
    8. TRISA=0xFF;
    9. ADCON0=0xC0;
    10. ADCON1=0;
    11. ADCON0|=(1<<0);
    12. do
    13. {
    14. ADCON0|=(1<<1);
    15. while(ADCON0/1);
    16. if(value>500)
    17. PORTB=1;
    18. else
    19. PORTB=0;
    20. }
    21. while(1);
    22. }
    23.  
    5 324 Undeclared identifier 'ANSEL' in expression ledadc2.c
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You need to include the required header (s) for your compiler. What compiler are you using?
     
  3. whatsthatsmell

    Active Member

    Oct 9, 2009
    102
    4
    Is there an ANSEL register on this mystery chip you are trying to program?
     
  4. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    I am using MicroC Pro for making programs. Earlier I made 2-3 programs using only built_in.h but now its giving error of ANSEL register.
     
  5. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    Yes it helps in taking analog input for built in ADC.
     
  6. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    Anyone could help me?
     
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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?
     
  8. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    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.
     
  9. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    Thanks for your help and patience. But I think I found solution so I wont bother you for a little while:p
     
  10. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Perhaps you could post your solution, I am curious, and I'm sure it could help others...
     
  11. tshuck

    Well-Known Member

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

    Thread Starter Member

    Oct 6, 2011
    55
    0
    i already posted solution in 8th comment:D
     
  13. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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.:)
     
  14. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    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..:)
     
  15. corefinder

    Thread Starter Member

    Oct 6, 2011
    55
    0
    Very True.. But I thought that every pic might have ansel register. Microchip should work on standardizing its product:cool:
     
  16. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    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
     
  17. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    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.
     
Loading...