Undefined Identifier with Hi TECH C

Thread Starter

Jaden5165

Joined Sep 9, 2011
69
Rich (BB code):
#include<pic.h>
//===============configuration=================================
__CONFIG (0x3F32);
//===============define IO port================================
#define      lcd         PORTB
#define      RS         RA2
#define      E           RA5
#define      CHANNEL0    0b10000001   // AN0
#define      buzzer_led  RD0
#define      fan         RD1
//==============FUNCTION PTOTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void send_config(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
void read_adc(void);
unsigned short read_temp(void);
//====================MAIN================================
unsigned short result;
unsigned short temp,tempA;
void main(void)
{
   ADRESH=0;            //clear A/D result
   ADRESL=0;            //clear A/D result
   //setting ADCON1 Register
   ADCON1=0b11000101;         // A/D result right justified,             
                       // configure RA2 and RA5 as digital I/O
   TRISA=0b11011011;         //configure PORTA I/O direction
   TRISB=0b00000000;         //configure PORTB as output
   TRISD=0b00000000;         //configure PORTD as output
   PORTA=0;
   PORTB=0;
 
   while(1)               
   {
      send_config(0b00000001);       //clear display at lcd
      send_config(0b00000010);     //Lcd Return to home 
      send_config(0b00000110);       //entry mode-cursor increase 1
      send_config(0b00001100);       //diplay on, cursor off and cursor blink off
      send_config(0b00111000);       //function set
 
      lcd_goto(0);                //cursor start from beginning
 
      //display character on LCD
      send_char(' ');
      send_char('T');
      send_char('E');
      send_char('M');
      send_char('P');
      send_char('.');
      send_char('A');
      send_char('=');
      while(1)                  //infinity loop
      {
      //Temperature sensor
      ADCON0=CHANNEL0;   //CHANNEL0=0b10000001            
      lcd_goto(8);
 
      read_adc();
      temp=read_temp();
      dis_num(temp/10);
      send_char('.');
      dis_num(temp%10);
      send_char(0b11011111);
      send_char('C');
      send_char(' ');
      send_char(' ');
 
      tempA=temp;
 
           if(tempA>300)                    
            {                        
               buzzer_led=1;                  
               fan=1;                     
 
            }   
         else if(tempA<250)                         
            {                        
               buzzer_led=1;                  
               fan=0;                     
 
            }   
 
         else 
            {
               buzzer_led=0;
               fan=0;
            }      
      delay(2000);
 
      }
 
   }
 
}
 
 
//==================subroutine LCD setting ==========================
void send_config(unsigned char data)
{
    RS=0;
   lcd=data;
   delay(500);
   e_pulse();
}
void e_pulse(void)
{
   E=1;
   delay(500);
   E=0;
   delay(500);
}
void send_char(unsigned char data)
{
    RS=1;
   lcd=data;
   delay(500);
   e_pulse();
}
 
void lcd_goto(unsigned char data)
{
    if(data<16)
   {
       send_config(0x80+data);
   }
   else
   {
       data=data-20;
      send_config(0xc0+data);
   }
}
 
void lcd_clr(void)
{
   RS=0;
    send_config(0x01);
   delay(600);   
}
 
void dis_num(unsigned long data)
{
   unsigned char hundred_thousand;
   unsigned char ten_thousand;
   unsigned char thousand;
   unsigned char hundred;
   unsigned char tenth;
   hundred_thousand = data/100000;               
   data = data % 100000;
   ten_thousand = data/10000;
   data = data % 10000;
   thousand = data / 1000;
   data = data % 1000;
   hundred = data / 100;
   data = data % 100;
   tenth = data / 10;
   data = data % 10;
   if(hundred_thousand>0)
   {
      send_char(hundred_thousand + 0x30);   //0x30 added to become ASCII code
      send_char(ten_thousand + 0x30);
      send_char(thousand + 0x30);
      send_char(hundred + 0x30);
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }
   else if(ten_thousand>0) 
   {
      send_char(ten_thousand + 0x30);   //0x30 added to become ASCII code
      send_char(thousand + 0x30);
      send_char(hundred + 0x30);
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }
   else if(thousand>0)
   {
       send_char(thousand + 0x30);      //0x30 added to become ASCII code
      send_char(hundred + 0x30);
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }
   else if(hundred>0)
   {
       send_char(hundred + 0x30);      //0x30 added to become ASCII code
      send_char(tenth + 0x30);
      send_char(data + 0x30);
   }
   else if(tenth>0)
    {
      send_char(tenth + 0x30);      //0x30 added to become ASCII code
      send_char(data + 0x30);
   }
   else send_char(data + 0x30);         //0x30 added to become ASCII code
}
void increment(unsigned long data)
{   
   unsigned short j;
   for(j=10;j>0;j--)
   {   lcd_goto(32);
      data=data+1;
      dis_num(data);
      delay(10000);
   }
}
//==================subroutine ADC=========================
void read_adc(void)
{
   unsigned short i;
   unsigned long result_temp=0;
   for(i=2000;i>0;i-=1)            //looping 2000 times for getting average value 
   {
     ADCON0bits.GO = 1; 
 //ADGO is the bit 2 of the ADCON0 register 
 while(ADCON0bits.GO==1); 
 //ADC start, ADGO=0 after finish ADC progress 
 result=ADRESH; 
 result=result<<8; 
 //shift to left for 8 bit 
 result=result|ADRESL; 
 //10 bit result from ADC 
 result_temp+=result;
 }
   result = result_temp/2000;         //getting average value
}
unsigned short read_temp(void)
{
   unsigned short temp;
   temp=result;
   return temp;
}
//==================subroutine DELAY==========================
void delay(unsigned short i)
{   
   for(;i>0;i--);
}
-----------------------------------------------------------------------
Rich (BB code):
Clean: Deleting intermediary and output files.
Clean Warning: File "C:\Users\Jaden_Ng Chun Hau\Desktop\FYP\HTC_MPLAB_CODE\New folder\gg.p1" doesn't exist.
Clean: Deleted file "C:\Users\Jaden_Ng Chun Hau\Desktop\FYP\HTC_MPLAB_CODE\New folder\ds.mcs".
Clean: Done.
Build C:\Users\Jaden_Ng Chun Hau\Desktop\FYP\HTC_MPLAB_CODE\New folder\ds for device 16F877A
Using driver D:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe
Executing: "D:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 "C:\Users\Jaden_Ng Chun Hau\Desktop\FYP\HTC_MPLAB_CODE\New folder\gg.c" -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
Error   [192] C:\Users\Jaden_Ng Chun Hau\Desktop\FYP\HTC_MPLAB_CODE\New folder\gg.c; 243.1 undefined identifier "ADCON0bits"
Error   [196] C:\Users\Jaden_Ng Chun Hau\Desktop\FYP\HTC_MPLAB_CODE\New folder\gg.c; 243.15 struct/union required
Error   [196] C:\Users\Jaden_Ng Chun Hau\Desktop\FYP\HTC_MPLAB_CODE\New folder\gg.c; 245.20 struct/union required
********** Build failed! **********




I got this code from my friends and they can compile successful but why i build failed.they used project wizard to start and me too.but why i cant build success.
 

stahta01

Joined Jun 9, 2011
133
Did you try to include <htc.h> instead of <pic.h>

If that fails try defining _LEGACY_HEADERS before including the header file <htc.h>.

Tim S.
 
Last edited:

t06afre

Joined May 11, 2009
5,934
Go to the ....\HI-TECH Software\PICC\9.81\include folder. Open the header file for your PIC. Then browse (search) to you find the definition for the ADCON register. It will be something like this example that is for PORTA
Rich (BB code):
// Register: PORTA
volatile unsigned char           PORTA               @ 0x005;
// bit and bitfield definitions
volatile bit RA0                 @ ((unsigned)&PORTA*8)+0;
volatile bit RA1                 @ ((unsigned)&PORTA*8)+1;
volatile bit RA2                 @ ((unsigned)&PORTA*8)+2;
volatile bit RA3                 @ ((unsigned)&PORTA*8)+3;
volatile bit RA4                 @ ((unsigned)&PORTA*8)+4;
volatile bit RA5                 @ ((unsigned)&PORTA*8)+5;
 

Thread Starter

Jaden5165

Joined Sep 9, 2011
69
Go to the ....\HI-TECH Software\PICC\9.81\include folder. Open the header file for your PIC. Then browse (search) to you find the definition for the ADCON register. It will be something like this example that is for PORTA
Rich (BB code):
// Register: PORTA
volatile unsigned char           PORTA               @ 0x005;
// bit and bitfield definitions
volatile bit RA0                 @ ((unsigned)&PORTA*8)+0;
volatile bit RA1                 @ ((unsigned)&PORTA*8)+1;
volatile bit RA2                 @ ((unsigned)&PORTA*8)+2;
volatile bit RA3                 @ ((unsigned)&PORTA*8)+3;
volatile bit RA4                 @ ((unsigned)&PORTA*8)+4;
volatile bit RA5                 @ ((unsigned)&PORTA*8)+5;



i followed the step u said but the include files dont have ADCON.i try to use search the words ADCON also cannot find.
 

Thread Starter

Jaden5165

Joined Sep 9, 2011
69
@t06afre
i reinstall again my mplab and also the htc.my htc now is 9.7version.weird thing is when i compile the code 1st time build failed but when i build again it build successful.but if i click rebuild then it will be build failed.and i try rebuild still failed,but i try build then can.why?
 
Top