CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Error: Previous identifier must be a pointer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pyu



Joined: 04 Feb 2009
Posts: 51

View user's profile Send private message Yahoo Messenger

Error: Previous identifier must be a pointer
PostPosted: Thu Oct 08, 2009 1:54 pm     Reply with quote

Hi.

I have declared
Code:
signed int16 Temp[4];


Then,
Code:
 for (numRoms=1;numRoms<=4;numRoms++)
         {
            if (Send_MatchRom())
            {
               write_byte(0xBE); // Read scratch pad command
               dowcrc = 0;       // Reset the crc to start a new calculation
   
               for (i=0;i<=7;i++)
               {
                   scratch[i] = read_byte();
                   ow_crc(scratch[i]);     // Accumulate the crc
               }
   
               scratch[8] = read_byte();   // Received crc byte
               ow_reset();
   
               // If calculated crc from incoming bytes equal to crc byte
               // then data is valid. Calculate and output temperature.
               
               if (scratch[8] == dowcrc)
               {
               temp = make16(scratch[1],scratch[0]);
               result = (float) temp / 16.0; //0.1 deg C resolution
               //printf(lcd_putc,"\fT%i= %3.1f \uC", numRoms, result);
               Temp[numRoms] = result;
               }
               else
            {
               printf(lcd_putc,"\fData error.");       // There was an error in the data
               delay_ms(1000);
            }
            }
         }


I want to assign a value to Temp[0], Temp[1], Temp[2], Temp[3],
and then to print this value to LCD.

Code:
printf(lcd_putc, "\nENG:\%3.1fC \EXT:%2.1fC", Temp[0], Temp[1]);



I get 2 errors:
Quote:
** Error 116 "C:\Car_LCD\CarLCD.c" Line 570(62,63): Printf variable count (%) does not match actual count ::
*** Error 66 "C:\Car_LCD\CarLCD.c" Line 638(6,13): Previous identifier must be a pointer


First error I get it from this line:
Code:
   printf(lcd_putc, "\nENG:\%3.1fC \EXT:%2.1fC", Temp[0], Temp[1]);

The second error:
Code:
Temp[numRoms] = result;



What is wrong in my code?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 08, 2009 2:14 pm     Reply with quote

Quote:
signed int16 Temp[4];
printf(lcd_putc, "\nENG:\%3.1fC \EXT:%2.1fC", Temp[0], Temp[1]);

Look at your code. You have an array of 'signed int' values, but you're
trying to display them as floating point numbers.


Quote:
Temp[numRoms] = result;

You didn't post the declarations for 'numRoms' or 'result'.

It's easier to give you an answer if you post a real test program,
with all varible declarations, and that is compilable. Also post
your PIC and compiler version.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 1:59 am     Reply with quote

Surely the problem lies with the fact the '\' is an escape char i.e

\% will escape the %

If your intention is to disply a '\' then you need to use 2 off them but I suspect you have just made a mistake! :-

printf(lcd_putc, "\nENG: %3.1fC EXT:%2.1fC", Temp[0], Temp[1]);

But PCM programmer has a valid point.
pyu



Joined: 04 Feb 2009
Posts: 51

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Oct 09, 2009 2:37 am     Reply with quote

I had corrected the first error.

Code:
int8 numROMs;
float result=0;



Here is my entire project, after build, I get that single error (Previous identifier must be a pointer):
http://cid-e0cf397449e54fc9.skydrive.live.com/self.aspx/Public/PicKit2/CarLCD/CarLCD.zip


Last edited by pyu on Fri Oct 09, 2009 2:44 am; edited 1 time in total
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 2:44 am     Reply with quote

An array has a zero based index in C

So
signed int16 Temp[4];

gives you
Temp[0] to Temp[3]

you either need to change your for loop
for (numRoms=0;numRoms<=3;numRoms++)

or change the assignment.
Temp[numRoms - 1] = result;

I don't think this is your problem though.

post more info, including definitions of vars used.
pyu



Joined: 04 Feb 2009
Posts: 51

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Oct 09, 2009 2:53 am     Reply with quote

Wayne_ wrote:
An array has a zero based index in C
or change the assignment.
Temp[numRoms - 1] = result;

I don't think this is your problem though.

I tried
Code:
Temp[numROMs - 1] = result;
, but no succes.

In previous post, I added a zip with my project.
Here is a sample code:
Code:

int8 numROMs;
float Temp[4];

void Read_DS_Temperature(void)
{
   int8 i;
   signed int16 temperature;
   int8 scratch[9];
   signed int16 temp;
   float result=0;
   
   if (!ow_reset())     // If a device is present
      {
         write_byte(0xCC); // Skip Rom command
         write_byte(0x44); // Temperature convert command
         output_float(DQ);
         delay_ms(750);    // Max. conv. time is 750mS for 12 bit
         ow_reset();
 
         // Now get the device raw temperature data using Match ROM with the
         // addresses obtained with FindDevices().  Scale to deg. C, scaling is
         // 0.0625 (1/16) deg. C/bit with default 12 bit res. Could reduce res.
         // and therefore shorten conversion time if necessary.
         // Output the temperatures in whole degrees, apply rounding by adding
         // half denom.
   
         for (numROMs=1;numROMs<=4;numROMs++)
         {
            if (Send_MatchRom())
            {
               write_byte(0xBE); // Read scratch pad command
               dowcrc = 0;       // Reset the crc to start a new calculation
   
               for (i=0;i<=7;i++)
               {
                   scratch[i] = read_byte();
                   ow_crc(scratch[i]);     // Accumulate the crc
               }
   
               scratch[8] = read_byte();   // Received crc byte
               ow_reset();
   
               // If calculated crc from incoming bytes equal to crc byte
               // then data is valid. Calculate and output temperature.
               
               if (scratch[8] == dowcrc)
               {
               temp = make16(scratch[1],scratch[0]);
               result = (float) temp / 16.0; //0.1 deg C resolution
               //printf(lcd_putc,"\fT%i= %3.1f \uC", numRoms, result);
               Temp[numROMs - 1] = result;
               }
               else
            {
               printf(lcd_putc,"\fData error.");       // There was an error in the data
               delay_ms(1000);
            }
            }
         }

      }
      else
      {
         printf(lcd_putc,"\fSenzor Error!");
         delay_ms(1000);
      }
}

then:
while(1){
     printf(lcd_putc, "\nENG:\%3.1fC \EXT:%2.1fC", Temp[0], Temp[1]);
}

Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 3:33 am     Reply with quote

So which error are you still getting and what is the line ? please show code surrounding this and any definitions as well.
pyu



Joined: 04 Feb 2009
Posts: 51

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Oct 09, 2009 3:41 am     Reply with quote

Error:
Code:
*** Error 66 "C:\Car_LCD\CarLCD.c" Line 638(6,13): Previous identifier must be a pointer


Line:
Code:
Temp[numROMs - 1] = result;




main.c:
Code:

#include <16F887.H>
#include <math.h>

#fuses HS,NOWDT,NOLVP,PUT,NOPROTECT,NOBROWNOUT,NOWRT

#use delay(clock = 20000000)

//#device adc=10  *=16      - ???
#define DQ PIN_E0 // One Wire Bus pin assignment

#define RTC_SDA  PIN_C4
#define RTC_SCL  PIN_C3

#use I2C(MULTI_MASTER,sda=RTC_SDA, scl=RTC_SCL)

#include "Flex_LCD420.c"


#include "CarLCD.h"
#include "CarLCD.c"

void main(void)
{

    lcd_init();

   output_float(DQ);       // Set as input. 4k7 pullup on bus.
   FindDevices();
   ow_reset();

while(1)
   {
      DisplayInformations();
   }
}



CarLCD.h:
Code:

// Global variables
int8 Rom_Bit[8]; // Rom_Bit bit
int8 lastDiscrep = 0;
short doneFlag = 0;
int8 FoundROM[7][8]; // Table of found ROM codes, 8 bytes for each
int8 numROMs;
int8 dowcrc; // crc is accumulated in this variable

// crc lookup table
int8 const dscrc_table[] = {
0,94,188,226,97,63,221,131,194,156,126,32,163,253,31,65,
157,195,33,127,252,162,64,30,95,1,227,189,62,96,130,220,
35,125,159,193,66,28,254,160,225,191,93,3,128,222,60,98,
190,224,2,92,223,129,99,61,124,34,192,158,29,67,161,255,
70,24,250,164,39,121,155,197,132,218,56,102,229,187,89,7,
219,133,103,57,186,228,6,88,25,71,165,251,120,38,196,154,
101,59,217,135,4,90,184,230,167,249,27,69,198,152,122,36,
248,166,68,26,153,199,37,123,58,100,134,216,91,5,231,185,
140,210,48,110,237,179,81,15,78,16,242,172,47,113,147,205,
17,79,173,243,112,46,204,146,211,141,111,49,178,236,14,80,
175,241,19,77,206,144,114,44,109,51,209,143,12,82,176,238,
50,108,142,208,83,13,239,177,240,174,76,18,145,207,45,115,
202,148,118,40,171,245,23,73,8,86,180,234,105,55,213,139,
87,9,235,181,54,104,138,212,149,203,41,119,244,170,72,22,
233,183,85,11,136,214,52,106,43,117,151,201,74,20,246,168,
116,42,200,150,21,75,169,247,182,232,10,84,215,137,107,53
};

// Returns 0 for one wire device presence, 1 for none
int8 ow_reset(void);

// Read bit on one wire bus
int8 read_bit(void);

void write_bit(int8 bitval) ;

int8 read_byte(void) ;

void write_byte(int8 val) ;

// One wire crc
int8 ow_crc(int8 x) ;

// Searches for the next device on the one wire bus. If there are no more
// devices on the bus then false is returned.
int8 Next(void);

// Resets current state of a ROM search and calls Next to find the first device
// on the one wire bus.
int8 First(void);

void FindDevices(void);

// Sends Match ROM command to bus then device address
int8 Send_MatchRom(void);


float Temp[4];




CarLCD.c:
Code:

//DS18B20



// Returns 0 for one wire device presence, 1 for none
int8 ow_reset(void)
{
   int8 presence;

   output_low(DQ);
   delay_us(488);          // Min. 480uS
   output_float(DQ);
   delay_us(72);           // Takes 15 to 60uS for devices to respond
   presence = input(DQ);
   delay_us(424);          // Wait for end of timeslot

   //printf(lcd_putc, "\fPresence= %i", presence);

//delay_ms(500);
   return(presence); 
}

/******************************************************************************/
// Read bit on one wire bus
int8 read_bit(void)
{
   output_low(DQ);
   delay_us(1);         // 1uS min. Original code relied on 8051 being slow
   output_float(DQ);
   delay_us(20);        // Wait at least 15mS from start of time slot
   
   return(input(DQ));   // Delay to finish time slot (total 60 to 120uS)
} // must be done next.

/******************************************************************************/
void write_bit(int8 bitval)
{
   output_low(DQ);

   if(bitval == 1) {
      delay_us(1);      // 1uS min. Original code relied on 8051 being slow
      output_float(DQ);
   }
   delay_us(105);       // Wait for end of timeslot
   
   output_float(DQ); 
}

/******************************************************************************/
int8 read_byte(void)
{
   int8 i;
   int8 val = 0;

   for(i=0;i<8;i++)
   {
      if(read_bit()) val |= (0x01 << i);
      delay_us(120);  // To finish time slot
   }

   return val;
}

/******************************************************************************/
void write_byte(int8 val)
{
   int8 i;
   int8 temp;

   for (i=0;i<8;i++)
   {
      temp = val >> i;
      temp &= 0x01;
      write_bit(temp);
   }

   delay_us(105);
}

/******************************************************************************/
// One wire crc
int8 ow_crc(int8 x)
{
   dowcrc = dscrc_table[dowcrc^x];
   
   return dowcrc; 
}

/******************************************************************************/
// Searches for the next device on the one wire bus. If there are no more
// devices on the bus then false is returned.
int8 Next(void)
{
   int8 m = 1;             // ROM Bit index
   int8 n = 0;             // ROM Byte index
   int8 k = 1;             // Bit mask
   int8 x = 0;
   int8 discrepMarker = 0;
   int8 g;                 // Output bit
   int8 nxt;               // Return value
   short flag;

   nxt = FALSE;            // Reset next flag to false

   dowcrc = 0;             // Reset the dowcrc

   flag = ow_reset();

   if (flag||doneFlag)     // If no parts return false
   {
      lastDiscrep = 0;     // Reset the search
      return FALSE;
   }

   write_byte(0xF0);       // Send SearchROM command

   do
   {
      x = 0;
      if (read_bit() == 1)
      x = 2;
      delay_us(120);
      if (read_bit() == 1)
      x |= 1;   // And it's complement

      if (x == 3)                   // There are no devices on the one wire bus
      break;
      else
      {
         if (x > 0)                 // All devices coupled have 0 or 1
            g = x >> 1;             // Bit write value for search

         // If this discrepancy is before the last discrepancy on a previous
         // Next then pick the same as last time.
         else
         {
            if (m < lastDiscrep)
               g = ((Rom_Bit[n] & k) > 0);
            // If equal to last pick 1
            else
               g = (m == lastDiscrep);  // If not then pick 0

               // If 0 was picked then record position with mask k
               if (g == 0) discrepMarker = m;
         }

         // Isolate bit in Rom_Bit[n] with mask k
         if (g == 1)
         Rom_Bit[n] |= k;
         else
         Rom_Bit[n] &= ~k;

         write_bit(g);  // ROM search write

         m++;           // Increment bit counter m
         k = k << 1;    // and shift the bit mask k
         // If the mask is 0 then go to new ROM
         if (k == 0)
         {  // Byte n and reset mask
            ow_crc(Rom_Bit[n]);      // Accumulate the crc
            n++;
            k++;
         }
      }
   } while (n < 8);  // Loop through until through all ROM bytes 0-7

   if (m < (65||dowcrc))   // If search was unsuccessful then
      lastDiscrep = 0;     // reset the last Discrepancy to zero

   else  // Search was successful, so set lastDiscrep, lastOne, nxt
   {
      lastDiscrep = discrepMarker;
      doneFlag = (lastDiscrep == 0);
      nxt = TRUE; // Indicates search not yet complete, more parts remain
   }

   return nxt;
}


/******************************************************************************/
// Resets current state of a ROM search and calls Next to find the first device
// on the one wire bus.
int8 First(void)
{
   lastDiscrep = 0;
   doneFlag = FALSE;
   
   return Next(); // Call Next and return it's return value;
}

/******************************************************************************/
void FindDevices(void)
{
   int8 m;
   if(!ow_reset())
   {
      if(First())    // Begins when at least one part found
      {
         numROMs = 0;
      
         do
         {
            numROMs++;

            for (m=0;m<8;m++)
            {
               FoundROM[numROMs][m] = Rom_Bit[m];   // Identifies ROM no. on device
            }

            //printf("Device No.%u address ",numROMs);
         //printf(lcd_putc,"%u  no dev=",numROMs);
         //delay_ms(1000);
         
         printf(lcd_putc, "\f%X%X%X%X%X%X%X%X",
         FoundROM[numROMs][7],FoundROM[numROMs][6],FoundROM[numROMs][5], \
         FoundROM[numROMs][4],FoundROM[numROMs][3],FoundROM[numROMs][2], \
         FoundROM[numROMs][1],FoundROM[numROMs][0]);
                    
         delay_ms(1000);


            //printf("%X%X%X%X%X%X%X%X\n\r",
            //FoundROM[numROMs][7],FoundROM[numROMs][6],FoundROM[numROMs][5],
            //FoundROM[numROMs][4],FoundROM[numROMs][3],FoundROM[numROMs][2],
            //FoundROM[numROMs][1],FoundROM[numROMs][0]);
      

         } while (Next() && (numROMs<10));   // Continues until no additional
                                             // devices found.
      }
      else
         {
            printf(lcd_putc, "\fno ROM found");
         //delay_ms(500);
         }
   }
   else
         {
            printf(lcd_putc, "\fno ROM found2");
         //delay_ms(500);
         }
   //putc('\n'); putc('\r');
}


/******************************************************************************/
// Sends Match ROM command to bus then device address
int8 Send_MatchRom(void)
{
   int8 i;
   if (ow_reset()) return FALSE;          // 0 if device present
   write_byte(0x55);                      // Match ROM

   for (i=0;i<8;i++)
   {
      write_byte(FoundRom[numROMs][i]);   // Send ROM code
   }

   return TRUE;

/******************************************************************************/

void DisplayInformations(void)
{

         
         Read_DS_Temperature();
         


         printf(lcd_putc, "\nENG:\%3.1fC \EXT:%2.1fC", Temp[0], Temp[1]);

         

}

void Read_DS_Temperature(void)
{
   int8 i;
   signed int16 temperature;
   int8 scratch[9];
   signed int16 temp;
   float result=0;
   
   if (!ow_reset())     // If a device is present
      {
         write_byte(0xCC); // Skip Rom command
         write_byte(0x44); // Temperature convert command
         output_float(DQ);
         delay_ms(750);    // Max. conv. time is 750mS for 12 bit
         ow_reset();
 
         // Now get the device raw temperature data using Match ROM with the
         // addresses obtained with FindDevices().  Scale to deg. C, scaling is
         // 0.0625 (1/16) deg. C/bit with default 12 bit res. Could reduce res.
         // and therefore shorten conversion time if necessary.
         // Output the temperatures in whole degrees, apply rounding by adding
         // half denom.
   
         for (numROMs=1;numROMs<=4;numROMs++)
         {
            if (Send_MatchRom())
            {
               write_byte(0xBE); // Read scratch pad command
               dowcrc = 0;       // Reset the crc to start a new calculation
   
               for (i=0;i<=7;i++)
               {
                   scratch[i] = read_byte();
                   ow_crc(scratch[i]);     // Accumulate the crc
               }
   
               scratch[8] = read_byte();   // Received crc byte
               ow_reset();
   
               // If calculated crc from incoming bytes equal to crc byte
               // then data is valid. Calculate and output temperature.
               
               if (scratch[8] == dowcrc)
               {
               temp = make16(scratch[1],scratch[0]);
               result = (float) temp / 16.0; //0.1 deg C resolution
               //printf(lcd_putc,"\fT%i= %3.1f \uC", numRoms, result);
               Temp[numROMs - 1] = result;
               }
               else
            {
               printf(lcd_putc,"\fData error.");       // There was an error in the data
               delay_ms(1000);
            }
            }
         }

      }
      else
      {
         printf(lcd_putc,"\fSenzor Error!");
         delay_ms(1000);
      }
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 4:11 am     Reply with quote

It's a simple matter of code confusion.

On one hand you're utilizing the default case insensitive behaviour of CCS C (you get many errors, when activating #case for you code), on the other hand you have this:
Code:
int16 temp;
// and at another place
float Temp[4]; 

Decide, if you are going for #case or #nocase and correct your code respectively.
pyu



Joined: 04 Feb 2009
Posts: 51

View user's profile Send private message Yahoo Messenger

PostPosted: Mon Oct 12, 2009 3:55 am     Reply with quote

Thanks FvM.
It's working now!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group