# Hi tech c adc code not working as expected

I am new to using PIC micro-controllers, and I am working on a project that involves reading an analog value. I am using the PIC16F877A. I have found code for using the ADC posted below however when I try to compile it I get the error Error [192] C:\Users\Owner\Documents\Pic Projects\Analog\Main.c; 20.1 undefined identifier "GO_nDONE". Here is my code

#include<htc.h>
#include<pic.h>
#define _XTAL_FREQ 20000000

__CONFIG(UNPROTECT & PWRTDIS & WDTDIS & HS & LVPDIS);

{
TRISA   = 0x2f;
TRISE   = 0x07;
}

{
__delay_ms(10);
GO_nDONE = 1;
while(GO_nDONE);
}

void main()
{

}

• What PIC are you compiling it for? The register bits are named different things on different devices. In HTC you will usually need to reference them as a struct like REGISTERXbits.BITY, unlike C18. – David Mar 28 '14 at 15:56
• I am using PIC16F877A – popgalop Mar 28 '14 at 15:56
• A quick look at 16f877a.h from the 'include' directory of XC8 suggests that ADCON0bits.GO_nDONE is correct. – David Mar 28 '14 at 16:03
• that gives Error [192] C:\Users\Owner\Documents\Pic Projects\Analog\Main.c; 20.1 undefined identifier "ADCON0bits" Error [196] C:\Users\Owner\Documents\Pic Projects\Analog\Main.c; 20.21 struct/union required Error [196] C:\Users\Owner\Documents\Pic Projects\Analog\Main.c; 21.26 struct/union required – popgalop Mar 28 '14 at 16:05

Different versions of the HiTech C Compiler have defined PIC pins/ports in different ways. Then, when Microchip absorbed HiTech C, some were changed again.

If you look into your pic.h file, you will see which definitions file is being referenced for the PIC16F877A. Then, look into that file to find the mapping #defines...

For example, in PICC 9.50, it is defined as ADGO. In 9.83, it is defined as both ADGO and GODONE. I've also seen references to GO_DONE and GO_nDONE.

You could simply try these, and find which one works. I suggest, however, that you find the file so you can see the other pin/port/register mappings, too.

Good luck!

• The "different ways" were because the port and pin names in the header files were script-generated from data files we got straight from Microchip, and occasionally those files would change. Now we have fewer barriers between to communication with the creators of those data files, and things have also stabilised. – mlp Nov 5 '14 at 4:08
• @mlp Thanks! I wasn't saying that HiTech or Microchip had done anything wrong; these types of issues seem pretty common all over the place! (I just recently found two contradicting code snippets in the CMSIS ARM libraries) :) – bitsmack Nov 6 '14 at 18:07
• Likewise, I was not taking offense, but merely attempting to shed some light on the changing definitions. This sort of thing becomes more likely as the separation grows between compiler developers, chip documenters, and silicon designers, on a continuum from inside one highly-talented head to distinct corporate entities. – mlp Nov 7 '14 at 6:44
• @mlp I like that phrase: "from inside one highly-talented head to distinct corporate entities" :) – bitsmack Nov 10 '14 at 17:16