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 messages

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



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

error messages
PostPosted: Tue Nov 23, 2010 2:06 am     Reply with quote

Hi
I reinstall the original version of CCS compiler and the problem " out of rom " solved.
But now there is a new error that I can't recognize why they occur.
This is the part of program that has errors with error message on top of the related line:
Code:

#include <stdlib.h>
#include <input.c>

char cmd[5];
int1 tz_flag,ts_flag,ds_flag,dt_flag,er_flag;
int1 tz11_flag,tz12_flag,tz13_flag,tz22_flag,tz23_flag,
tz33_flag;
extern int8 tzone11,tzone12,tzone21,tzone22,tzone31,tzone32;
extern float tcoe13,tcoe23,tcoe33;
extern int8 hour,min,sec;
extern int8 day,month,year,dow;
int1 ts_h_flag,ts_m_flag,ts_s_flag;
int1 ds_d_flag,ds_m_flag,ds_y_flag;
char pc_cmd[5];

communication(){

  if (kbhit())
      {
//*********************************         
      if(tz_flag){
       
         if(tz11_flag)
         {         
         tzone11=get_int();
         tz12_flag=1;
         tz11_flag=0;
         tzone32=tzone11;
         printf("%d",32);         
         }
         
         if(tz12_flag)
         {         
         tzone12=get_int();
         tz12_flag=0;
         tz22_flag=1;
         tzone21=tzone12;
         printf("%d",32);         
         }
         if(tz22_flag)
         {         
         tzone22=get_int();
         tz22_flag=0;
         tz13_flag=1;
         tzone31=tzone22;
         printf("%d",32);         
         }
         //************************
         if(tz13_flag)
         {         
         tcoe13=get_float();
         tz13_flag=0;
         tz23_flag=1;
         printf("%d",32);         
         }
         if(tz23_flag)
         {         
         tcoe23=get_float();
         tz33_flag=1;
         tz23_flag=0;
         printf("%d",32);         
         }
         if(tz33_flag)
         {         
         tcoe33=get_float();
         tz33_flag=0;         
         tz_flag=0;         
         printf("end");         
         }
       
         return tzone11,tzone12,tcoe13,tzone21,tzone22,tcoe23,
         tzone31,tzone32,tcoe33;
      } 
         
//*********************************             
         if(ts_flag)
         {
          if(ts_s_flag)
           {           
            sec=get_int();
            ts_s_flag=0;
            ts_m_flag=1;
            printf("%d",32);           
           }
          if(ts_m_flag)
           {           
            min=get_int();
            ts_m_flag=0;
            ts_h_flag=1;
            printf("%d",32);           
           } 
          if(ts_h_flag)
           {           
            hour=get_int();
            ts_h_flag=0;
            ts_flag=1;
            printf("end");             
           }
           ds1307_set_time(hour,min,sec);
         return hour,min,sec;
         };
//*********************************         
         if(ds_flag)
         {
          if(ds_d_flag)
          {
          day=get_int();
          ds_d_flag=0;
          ds_m_flag=1;
          printf("%d",32);         
          }
          if(ds_m_flag)
          {         
          month=get_int();
          ds_m_flag=0;
          ds_y_flag=1;
          printf("%d",32);         
          }
          if(ds_y_flag)
          {         
          year=get_int();         
          ds_y_flag=0;
          ds_flag=0;         
          printf("end");           
          }
         ds1307_set_date(day,month,year);
         return day,month,year;
         };
         if(dt_flag)
         {         
         get_string(pc_cmd,4);
         if(pc_cmd=="read")
         {
         data_sending();
         printf("date");
         ds1307_get_date(day,month,year,dow);
         year=year+2000;
         printf("%d/%d/%d",year,month,day);
         printf("time");
         ds1307_get_time(hour,min,sec);
         printf("%d:%d:%d",hour,min,sec);
         printf("end");
         dt_flag=0;         
         }
         };
         if(er_flag)
         {
         int16 counter=0;         
         for(counter=0;counter<10478;counter++)
         {
         eeprom_write(0,(counter*4));
         }
         er_flag=0;
         printf("end");         
         };
     
         if(!(tz_flag|ts_flag|ds_flag|dt_flag|er_flag) ){
          get_string(cmd,2);
      //}
      switch (cmd){
//*** Error 27 "H:\PIC\My sources\communication.c" Line 161(18,19): Expression must evaluate to a constant
        case "TZ":{       
        tz_flag=1;
        tz11_flag=1;
//*** Error 49 "H:\PIC\My sources\communication.c" Line 164(9,12): Expecting LVALUE such as a variable name  or  * expression
        cmd="";
        printf("ready");               
        break;
        };
//*** Error 51 "H:\PIC\My sources\communication.c" Line 168(9,13): A numeric expression must appear here
        case "TS":{       
        ts_flag=1;
        ts_s_flag=1;
//*** Error 49 "H:\PIC\My sources\communication.c" Line 171(9,12): Expecting LVALUE such as a variable name  or  * expression
        cmd="";
        printf("ready");         
        break;
        };
//*** Error 51 "H:\PIC\My sources\communication.c" Line 175(9,13): A numeric expression must appear here
        case "DS":{
       
        ds_flag=1;
        ds_d_flag=1;
//*** Error 49 "H:\PIC\My sources\communication.c" Line 179(9,12): Expecting LVALUE such as a variable name  or  * expression
        cmd="";
        printf("ready");         
        break;
        };
//*** Error 51 "H:\PIC\My sources\communication.c" Line 183(9,13): A numeric expression must appear here
        case "RD":{
       
        dt_flag=1; 
//*** Error 49 "H:\PIC\My sources\communication.c" Line 186(9,12): Expecting LVALUE such as a variable name  or  * expression     
        cmd="";
        printf("ready");         
        break;
        };
//*** Error 51 "H:\PIC\My sources\communication.c" Line 190(9,13): A numeric expression must appear here
        case "ER":{
       
        er_flag=1;
//*** Error 49 "H:\PIC\My sources\communication.c" Line 193(9,12): Expecting LVALUE such as a variable name  or  * expression
        cmd="";
        printf("ready");         
        break;
        }
      }}
}
//*** Error 43 "H:\PIC\My sources\communication.c" Line 199(1,2): Expecting a declaration
}
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Nov 23, 2010 2:59 am     Reply with quote

You can not use strings in a case!

case "HS": // Will NOT work.

You can use something like

Code:

if (strcmp(cmd, "HS") == 0)
{
}
else if (strcmp(cmd, "TS") == 0)
{
}
...


You can NOT assign strings at run time:-

cmd=""; // Will NOT work you need to use string functions

strcpy(cmd, "");

Look at the help for string functions, search google.
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Tue Nov 23, 2010 3:03 am     Reply with quote

Key here, is that a 'string', is an _array_ of characters, not a data type in it's own right in C. You cannot for example have:
if (fred=="message")

You need to call the strcmp function to compare the arrays.

So, switch statements, and variable assignments can't use strings (there is an exception for variable _initialisation_, where just as for filling an array with a sequence of numbers, you can intialise a character array.

Get a basic C book. This is a 'fundamental' bit of C.

Best Wishes
mojsa2000



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

PostPosted: Tue Nov 23, 2010 7:19 am     Reply with quote

Hi
thanks my friends
I did this way to compare strings:
Code:

char codes[5][3]={"TZ","TS","DS","RD","ER"};

get_string(cmd,2);
     
     
        if ((strcmp(cmd[0], codes[0][0])|strcmp(cmd[1], codes[0][1]))== 0){





              };

is it legal?
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Nov 23, 2010 9:02 am     Reply with quote

It would work but it is wrong. You are trying to do char comparrison but using strings.

What you are trying to do is this
Code:

char codes[5][3]={"TZ","TS","DS","RD","ER"};

get_string(cmd,2);
     
     
        if ((cmd[0] == codes[0][0]) && (cmd[1] == codes[0][1])){

But you can do
Code:

char codes[5][3]={"TZ","TS","DS","RD","ER"};

get_string(cmd,2);
     
     
        if (strcmp(cmd, codes[0]) == 0){


The second only works if get_string reads 2 chars in to cmd and THEN null terminates cmd making it in to a string!
mojsa2000



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

PostPosted: Tue Nov 23, 2010 12:18 pm     Reply with quote

Hi again
I'm confused. I have a very big problem with the Rom vacancy.
I have made my project and when I decided to add a communication protocol to it, I couldn't.
I tried more and more and I couldn't. I said "I couldn't", not "its impossible to solve". I browsed all of posts about this
problem and they didn't usefull for me. I separated the Main to some functions and call them but it didn't fix.



Code:
CCS PCM C Compiler, Version 4.084, 35966               23-Nov-10 17:18

               Filename: the_final.lst

               ROM used: 7165 words (87%)
                         Largest free fragment is 737
               RAM used: 174 (47%) at main() level
                         224 (61%) worst case
               Stack:    7 worst case (5 in main + 2 for interrupts)


but when added the communication protocol these error and warnings occur.why?????


protocol:

Code:

#include <stdlib.h>
#include <input.c>

char cmd[5];
int1 tz_flag,ts_flag,ds_flag,dt_flag,er_flag;
int1 tz11_flag,tz12_flag,tz13_flag,tz22_flag,tz23_flag,
tz33_flag;
extern int8 tzone11,tzone12,tzone21,tzone22,tzone31,tzone32;
extern float tcoe13,tcoe23,tcoe33;
extern int8 hour,min,sec;
extern int8 day,month,year,dow;
int1 ts_h_flag,ts_m_flag,ts_s_flag;
int1 ds_d_flag,ds_m_flag,ds_y_flag;
char pc_cmd[5];
char codes[5][3]={"TZ","TS","DS","RD","ER"};

communication(){

  if (kbhit())
      {
//*********************************         
      if(tz_flag){
       
         if(tz11_flag)
         {         
         tzone11=get_int();
         tz12_flag=1;
         tz11_flag=0;
         tzone32=tzone11;
         printf("%d",32);         
         }
         
         if(tz12_flag)
         {         
         tzone12=get_int();
         tz12_flag=0;
         tz22_flag=1;
         tzone21=tzone12;
         printf("%d",32);         
         }
         if(tz22_flag)
         {         
         tzone22=get_int();
         tz22_flag=0;
         tz13_flag=1;
         tzone31=tzone22;
         printf("%d",32);         
         }
         //************************
         if(tz13_flag)
         {         
         tcoe13=get_float();
         tz13_flag=0;
         tz23_flag=1;
         printf("%d",32);         
         }
         if(tz23_flag)
         {         
         tcoe23=get_float();
         tz33_flag=1;
         tz23_flag=0;
         printf("%d",32);         
         }
         if(tz33_flag)
         {         
         tcoe33=get_float();
         tz33_flag=0;         
         tz_flag=0;         
         printf("end");         
         }
       
         return tzone11,tzone12,tcoe13,tzone21,tzone22,tcoe23,
         tzone31,tzone32,tcoe33;
      }
         
//*********************************             
         if(ts_flag)
         {
          if(ts_s_flag)
           {           
            sec=get_int();
            ts_s_flag=0;
            ts_m_flag=1;
            printf("%d",32);           
           }
          if(ts_m_flag)
           {           
            min=get_int();
            ts_m_flag=0;
            ts_h_flag=1;
            printf("%d",32);           
           }
          if(ts_h_flag)
           {           
            hour=get_int();
            ts_h_flag=0;
            ts_flag=1;
            printf("end");             
           }
           ds1307_set_time(hour,min,sec);
         return hour,min,sec;
         };
//*********************************         
         if(ds_flag)
         {
          if(ds_d_flag)
          {
          day=get_int();
          ds_d_flag=0;
          ds_m_flag=1;
          printf("%d",32);         
          }
          if(ds_m_flag)
          {         
          month=get_int();
          ds_m_flag=0;
          ds_y_flag=1;
          printf("%d",32);         
          }
          if(ds_y_flag)
          {         
          year=get_int();         
          ds_y_flag=0;
          ds_flag=0;         
          printf("end");           
          }
         ds1307_set_date(day,month,year);
         return day,month,year;
         };
         if(dt_flag)
         {         
         get_string(pc_cmd,4);
         if(pc_cmd=="read")
         {
         data_sending();
         printf("date");
         ds1307_get_date(day,month,year,dow);
         year=year+2000;
         printf("%d/%d/%d",year,month,day);
         printf("time");
         ds1307_get_time(hour,min,sec);
         printf("%d:%d:%d",hour,min,sec);
         printf("end");
         dt_flag=0;         
         }
         };
         if(er_flag)
         {
         int16 counter=0;         
         for(counter=0;counter<10478;counter++)
         {
         eeprom_write(0,(counter*4));
         }
         er_flag=0;
         printf("end");         
         };
     
         if(!(tz_flag|ts_flag|ds_flag|dt_flag|er_flag) ){
          get_string(cmd,2);
      //}
       
        if ((strcmp(cmd[0], codes[0][0])|strcmp(cmd[1], codes[0][1]))== 0){       
        tz_flag=1;
        tz11_flag=1;
        strcpy(cmd,"");
        printf("ready");               
        break;
        };
        if ((strcmp(cmd[0], codes[1][0])|strcmp(cmd[1], codes[1][1]))== 0){       
        ts_flag=1;
        ts_s_flag=1;
        strcpy(cmd,"");
        printf("ready");         
        break;
        };
        if ((strcmp(cmd[0], codes[2][0])|strcmp(cmd[1], codes[2][1]))== 0){
       
        ds_flag=1;
        ds_d_flag=1;
        strcpy(cmd,"");
        printf("ready");         
        break;
        };
        if ((strcmp(cmd[0], codes[3][0])|strcmp(cmd[1], codes[3][1]))== 0){
       
        dt_flag=1;       
        strcpy(cmd,"");
        printf("ready");         
        break;
        };
        if ((strcmp(cmd[0], codes[4][0])|strcmp(cmd[1], codes[4][1]))== 0){
       
        er_flag=1;
        strcpy(cmd,"");
        printf("ready");         
        break;
        }
     }
}
}


error&warning:

Code:
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@I2C_WRITE_1)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@I2C_READ_1)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (bcd2bin)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (bin2bcd)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@delay_ms1)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@SFTOI)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@MULFF)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@DIVFF)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@ADDFF)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@ITOF)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@DIV1616)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@DIV88)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (eeprom_read)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@FTOSD)
>>> Warning 216 "the_final.c" Line 376(0,1): Interrupts disabled during call to prevent re-entrancy:  (@DIV3232)
*** Error 71 "the_final.c" Line 376(0,1): Out of ROM, A segment or the program is too large    read_daily_vi
  Seg 01800-01FFF, 0011 left, need 0059
  Seg 00000-00003, 0000 left, need 0059
  Seg 00004-0004D, 0000 left, need 0059
  Seg 0004E-007FF, 0008 left, need 0059
  Seg 00800-00FFF, 000B left, need 0059
  Seg 01000-017FF, 0004 left, need 0059
arocholl



Joined: 14 Dec 2008
Posts: 21

View user's profile Send private message

PostPosted: Tue Nov 23, 2010 12:47 pm     Reply with quote

Wayne_ wrote:
You can not use strings in a case!


Yes, you can with CCS v4.1xx, see http://www.ccsinfo.com/content.php?page=V4.1xx , they extended beyond standard C for that.

Probably the user was working with a 4.1xx version and working fine. After he reinstalled an older version, it didn't compile anymore.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Nov 23, 2010 2:01 pm     Reply with quote

Hey, I've always wanted to use "strings" in a case statement in C -- thanks for pointing out that enhancement in 4.1xx !

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Nov 24, 2010 2:43 am     Reply with quote

arocholl wrote:
Wayne_ wrote:
You can not use strings in a case!


Yes, you can with CCS v4.1xx, see http://www.ccsinfo.com/content.php?page=V4.1xx , they extended beyond standard C for that.

Probably the user was working with a 4.1xx version and working fine. After he reinstalled an older version, it didn't compile anymore.


Well spotted Smile
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Nov 24, 2010 2:52 am     Reply with quote

Code:

return tzone11,tzone12,tcoe13,tzone21,tzone22,tcoe23,
         tzone31,tzone32,tcoe33;

This is not possible in standard C and I doubt CCS has implemented it somehow. Don't know why the compiler is not complaining. Your code works because these are globals anyway.

In fact the function itself is flawed, your function header does not specify a return yet in some parts it exits the function with returns + parameters and in others it does not. I think you are just lucky the compiler is ignoring the values after the return statements.

I am sure you know why you are getting the interrupts disabled warnings.

To fix the out of ROM you need to use a different chip or reduce the amount of rom you are using.

Move some consts to ram.
Remove duplicated functions.

You have some space left but not enough for your code.
The last piece you posted has a lot of duplication:-
strcpy(cmd, "");
printf("ready");

I am sure a little re-arranging of this part can reduce that.
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