Error in programming Project 6 (ultrasonic range finder)

Programmer, In-Circuit Debugger, PIC Start-Up Kit, Memory Interface...

Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Wed Jul 04, 2012 1:03 pm

When I follow the source code given for project 6 ultra sonic range finder
i got error in adc.c...the code is

CODE: SELECT_ALL_CODE
/*******************************************************************************
* This file provides the functions for the ADC module
*
* Cytron Technologies Sdn. Bhd.
*******************************************************************************/
// This file is written for PIC16F887, if other model of PIC is uses, please modify accordingly


#include <htc.h>
#include "system.h"
#include "adc.h"



/*******************************************************************************
* PUBLIC FUNCTION: adc_initialize
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Initialize the ADC module.
*
*******************************************************************************/
void adc_initialize(void)
{
   // A/D Conversion Clock = FOSC/32.
   ADCS1 = 1;
   ADCS0 = 0;
   
   // Set AN as analog pin
   ANS0 = 1;
   
   // Configure the result to be right justified, will take as 10-bit ADC
   ADFM = 1;
   
   VCFG1 = 0;

   VCFG0 = 0;
   
   // Turn Off ADC module by default
   ADON = 0;
}

   
/*******************************************************************************
* PUBLIC FUNCTION: adc_on
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Activate ADC module
*
*******************************************************************************/
void adc_on(void)
{
   // Turn On ADC module
   ADON = 1;
}




/*******************************************************************************
* PUBLIC FUNCTION: adc_off
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Deactivate ADC module
*
*******************************************************************************/
void adc_off(void)
{
   // Turn Off ADC module, to save power
   ADON = 0;
}



/*******************************************************************************
* PUBLIC FUNCTION: ui_adc_read
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ The ADC result in 16-bit
*
* DESCRIPTIONS:
* Convert and read the result of the ADC from ANO.
*
*******************************************************************************/
unsigned int ui_adc_read(void)
{
   unsigned int pot = 0;
   // Select the ADC channel on AN0 for SK40C
   CHS2 = 0;
   CHS1 = 0;
   CHS0 = 0;
   
   // Delay 1mS to fully charge the holding capacitor in the ADC module.
   __delay_ms(1);
   
   // Start the conversion and wait for it to complete.
   GODONE = 1;
   while (GODONE == 1);
   
   // Return 10-bit ADC result.
   pot = (unsigned int)ADRESH << 8;
   pot = pot + ADRESL;
   return pot;
}   


but I got error with this :


Build C:\Users\Yeo\Desktop\ETP\Project_6\Project_6 for device 16F887
Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe

Make: The target "C:\Users\Yeo\Desktop\ETP\Project_6\adc.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\adc.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [192] C:\Users\Yeo\Desktop\ETP\Project_6\adc.c; 117.1 undefined identifier "GODONE"
Make: The target "C:\Users\Yeo\Desktop\ETP\Project_6\Project_6.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\Project_6.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Make: The target "C:\Users\Yeo\Desktop\ETP\Project_6\lcd.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\lcd.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Make: The target "C:\Users\Yeo\Desktop\ETP\Project_6\uart.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\uart.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"

********** Build failed! **********


anyone can guild me with this?? appreciate ^^
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby shahrul » Wed Jul 04, 2012 1:24 pm

Change GODONE into GO
Example Peripheral see here.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Error in programming Project 6 (ultrasonic range finder)

Postby robosang » Wed Jul 04, 2012 3:11 pm

well, this is due to different version of HI-TECH Compiler. As far as I know, v9.80 and v9.82 have header file generate with different register name. In this case, the GODONE is one version and GO_DONE should be another version. You can try what being suggested by shahrul, try ADGO if it does not solved the problem.

This also cause the configuration bits problem. I think I saw thread discuss about this before, anyway you should be able to to solve it from the suggestion given :)
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Wed Jul 04, 2012 4:38 pm

Thnks alot~!!!will try it soon!!haha..appreciate!!
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby zhenning » Thu Jul 05, 2012 11:57 am

robosang WROTE:well, this is due to different version of HI-TECH Compiler. As far as I know, v9.80 and v9.82 have header file generate with different register name. In this case, the GODONE is one version and GO_DONE should be another version. You can try what being suggested by shahrul, try ADGO if it does not solved the problem.

This also cause the configuration bits problem. I think I saw thread discuss about this before, anyway you should be able to to solve it from the suggestion given :)

Yup. Not sure why they want to change the names from one version to another. They also change their configuration format:

__CONFIG(MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRCIO);
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Wed Jul 11, 2012 11:01 am

Guys...i have change the code and it can be build already...however my display shows distance of 503.....no matter how I move the sensor...the display still show 503?? What is happening??
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Wed Jul 11, 2012 11:09 am

I change the cinfig to this
__CONFIG(MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRCIO);

and i get build failed?? how come?
I;m so noob in this~~
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yonghui » Wed Jul 11, 2012 1:06 pm

u can refer the the compiler reports error to know what are the errors. if its parameter definition errors, it will shows something undefined, or redefined. etc. then u will know which to correct.
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Wed Jul 11, 2012 1:22 pm

I got this error and i do not understand...can help??

Error [194] C:\Users\Yeo\Desktop\ETP\Project_6\Project_6.c; 20.11 ")" expected
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Re: Error in programming Project 6 (ultrasonic range finder)

Postby yeosteven » Thu Jul 12, 2012 7:09 pm

I manage to find the problem with the error there as I change the ___ to __
howeever i got another problem now....my code is

CODE: SELECT_ALL_CODE
//==========================================================================
//   Author            : CYTRON TECHNOLOGIES SDN BHD
//   Project            : SK40C sample code for PIC16F887
//   Project description   : Analog Sensor: Range using Ultrasonic Range Finder
//                    3 mode : (1: Analog)
//                           (2: PWM   )
//                           (3: UART  )
//==========================================================================

//   include
//==========================================================================
#include <htc.h>
#include "lcd.h"
#include "adc.h"
#include "system.h"
#include "uart.h"

//   Configuration
//==========================================================================
__CONFIG(MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRCIO);

//   global variable
//===========================================================================
unsigned int To=0,T=0,TH=0;
unsigned char data[6] = {0};

//  Interrrupt Subroutine
//============================================================================
static void interrupt isr(void)
{
   if (T0IF)                        // TMR0 is overflow
   {
      T0IF = 0;                      // clear flag bit
      To +=0x100;                     // count number of TMR0 overflow ( make it to 16bit TMR)
   }
      
   if(RBIF)                        // there is change bit on RB4-RB7
   {
      RBIF = 0;                     //                                           ____
      if (PWM_IN)                     // PWM_IN(RB2) is 1 mean is rising form 0  __|         
      {
         TMR0 = 0;                  // clear all counter involved, start new count for period of RB4 high
         To = 0;
      }
                                 //                                 ___
      else TH = TMR0 + To;            // PWM_IN(RB2) is 0 mean is falling form 1       |_____  // save TH, RB4 high period
   }
}

//   main function
//==========================================================================
void main(void)
{
unsigned char mode = 1;
   PORTA = 0;                     // Clear Port
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;

   
   TRISA = 0b11111111;               // set PORTA as INPUT
   TRISB = 0b00000111;               // set PORTB<7:3> as OUTPUT , PORTB<2:0> as INPUT
   TRISC = 0b10000000;
   TRISD = 0b00000000;               // set PORTD as output
   

   ANSELH = 0;                   // SET PORTB as DIGITAL I/O for PIC16F887
   WPUB = 1;                     // PORTB Weak Pull Up enable

   // Interupt on change
   IOCB0 = 0;            
   IOCB1 = 0;
   IOCB2 = 1;                     // when PORTB.2 detect change will interrupt
   IOCB3 = 0;
   IOCB4 = 0;
   IOCB5 = 0;
   IOCB6 = 0;
   IOCB7 = 0;

   RBIE = 1;                     // PORTB Change Interrupt Enable bit   


   // TMR 0 configuation
   T0CS = 0;                  
   PSA = 0;                  
   PS2 = 1;                     // prescale 1:256
   PS1 = 1;                  
   PS0 = 1;                  
   T0IE = 1;                     // TMR0 Interrupt
   TMR0 = 0;
   
   GIE = 1;                     // Global Intterupt enable
   PEIE = 1;                     // Peripheral Interrupt enable

   lcd_initialize();               // Initialise LCD

   adc_initialize();               // Initialise ADC

   uart_initialize();               // Initialise UART

   TX == 1;                     // ON Transmit pin (refer Maxbotix EZ1 Ultrasonic datasheet)

   lcd_home();
   lcd_putstr("Dist:");
   lcd_goto(0x0B);
   lcd_putstr("inch");

while (1)
   {
   switch(mode)
      {
   case 1:         lcd_2ndline();
               lcd_putstr("Analog");
               while (SW1 == 1)
                  {
                  unsigned int adc_value = 0;
                  unsigned int range_an = 0; 
                  unsigned char j;
                  adc_on();
                  for(j = 0 ; j < 10 ; j++)                  // take analog result for 20 times
                     {
                     adc_value = adc_value + ui_adc_read();      
                     }
   
                  adc_value = adc_value/10;                  // adc_value devide by 10 to get average result
                  range_an = adc_value/2;                     // max vslue adc_value = 2.55/5 *1024 - 1 =  522
                  lcd_goto(0x05);                           // max is 254 inch... 522/254 = ~2
                   lcd_bcd(3,range_an);                     // (1 to 6 inch) is readed as 6 inch (refer to ultrasonic datasheet)
                  }   
               while (SW1 == 0);
               break;

   case 2:         lcd_2ndline();
               lcd_putstr("PWM   ");
               unsigned int range_pwm;
               while(SW1 == 1)
                  {
                  range_pwm = TH;                           // read TH from interrupt subroutine
                  lcd_goto(0x05);                           // each value = 256*4/20mhz = 51.2us, 1 inch = 147us 
                  range_pwm = (range_pwm*100)/288;            // 147us/51.2us = 2.87
                  lcd_bcd(3,range_pwm);   
                  }
               while (SW1 == 0);
               break;

   case 3:          lcd_2ndline();
               lcd_putstr("UART   ");
               unsigned int value,k,l = 0;
               while(SW1 == 1)
                  {
                  
                  for (l=0 ; l<6 ; l++)
                     {
                     uc_uart_receive();                     //take value from UART subroutine
                     if(RCREG == 'R') data[k=0] = RCREG;         // check if start byte 'R' is met 
                     if(data[0] == 'R') data[k++] = RCREG;      // save the data in data array
                     if (k>4) k = 4;                        // if the data array reached max, set the index to 4
                     }
                     lcd_goto(0x05);
                     send_lcd_data(1,data[1]);
                     send_lcd_data(1,data[2]);
                     send_lcd_data(1,data[3]);
                  }
      }

      while (SW1 == 0);
      if (++mode > 3)             // if SW1 is press, increase the mode number until it is max and loop back
         {
         mode = 1;
         }   
      
   }   
}


and i got this error...

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\Yeo\Desktop\ETP\Project_6\adc.p1".
Clean Warning: File "C:\Users\Yeo\Desktop\ETP\Project_6\Project_6.p1" doesn't exist.
Clean: Deleted file "C:\Users\Yeo\Desktop\ETP\Project_6\lcd.p1".
Clean: Deleted file "C:\Users\Yeo\Desktop\ETP\Project_6\uart.p1".
Clean: Done.
Build C:\Users\Yeo\Desktop\ETP\Project_6\Project_6 for device 16F887
Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe

Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\adc.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\Project_6.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\lcd.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\Yeo\Desktop\ETP\Project_6\uart.c -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" -oProject_6.cof -mProject_6.map --summary=default,-psect,-class,+mem,-hex --output=default,-inhx032 adc.p1 Project_6.p1 lcd.p1 uart.p1 --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error [800] C:\Users\Yeo\AppData\Local\Temp\s4s4.; 45. undefined symbol "FOSC_INTRCIO"

how should I define this?? anyone help??
yeosteven
Novice
 
Posts: 26
Joined: Wed Jul 04, 2012 8:21 am

Next

Return to PIC Development Tool

Who is online

Users browsing this forum: No registered users and 5 guests

cron