2
\$\begingroup\$

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);
void InitADC(void)
{
 ADCON1 = 0x80;
 TRISA = 0x2f;
 TRISE = 0x07;
 ADCON0 = 0x81;
}
unsigned int GetADCValue(unsigned char Channel)
{
 ADCON0 &= 0xc7;
 ADCON0 |= (Channel<<3);
 __delay_ms(10);
 GO_nDONE = 1;
 while(GO_nDONE);
 return ((ADRESH<<8)+ADRESL);
}
void main()
{
}
asked Mar 28, 2014 at 15:51
\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Mar 28, 2014 at 15:56
  • \$\begingroup\$ I am using PIC16F877A \$\endgroup\$ Commented Mar 28, 2014 at 15:56
  • \$\begingroup\$ A quick look at 16f877a.h from the 'include' directory of XC8 suggests that ADCON0bits.GO_nDONE is correct. \$\endgroup\$ Commented Mar 28, 2014 at 16:03
  • \$\begingroup\$ 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 \$\endgroup\$ Commented Mar 28, 2014 at 16:05

1 Answer 1

2
\$\begingroup\$

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!

answered Mar 28, 2014 at 17:06
\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Nov 5, 2014 at 4:08
  • \$\begingroup\$ @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) :) \$\endgroup\$ Commented Nov 6, 2014 at 18:07
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Nov 7, 2014 at 6:44
  • \$\begingroup\$ @mlp I like that phrase: "from inside one highly-talented head to distinct corporate entities" :) \$\endgroup\$ Commented Nov 10, 2014 at 17:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.