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

Strange v 4.047 compiler problem with PIC18F...

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



Joined: 10 Aug 2007
Posts: 2

View user's profile Send private message

Strange v 4.047 compiler problem with PIC18F...
PostPosted: Thu Jul 24, 2008 4:01 pm     Reply with quote

Following is a code snippet from a program I am working on:
Code:
#include "4550.h"
#include <math.h>

/* Keeps track of how many times Timer1 has overflowed */
#int_TIMER1
void T1_isr(){
   ++T1overflows;
}
/* Keeps track of how many times Timer3 has overflowed */
#int_TIMER3
void T3_isr(){
   ++T3overflows;
}

/* Timer1 will be incremented on each instruction cycle (Fosc/4)= TINS. We will
zero Timer1 one on the first H-L transition we see, then we will compute
the pulse width on the next H-L transition. Timer1 is a 16-bit counter so will
overflow when it reaches 65535. Since Timer1 will overflow we will keep track of
the number of times the overflow occurs using the Timer1 ISR.

We will then determine the control error and speed up or slow down accordingly.
*/
#int_EXT2 // Vertical axis
void  EXT2_isr(void){
   ++vMotorTicks;
   if(vMotorTicks % 2){
      set_timer1(0);
   }
   else{
     valuea = get_timer1();
     vServiceFlag = 1;
     T1overflows = 0;
   }
}

/* Timer3 will be incremented on each instruction cycle (Fosc/4)= TINS. We will
zero Timer3 one on the first H-L transition we see, then we will compute
the pulse width on the next H-L transition. Timer3 is a 16-bit counter so will
overflow when it reaches 65535. Since Timer3 will overflow we will keep track of
the number of times the overflow occurs using the Timer3 ISR.

We will then determine the control error and speed up or slow down accordingly.
*/
#int_EXT1 // Horizontal axis
void  EXT1_isr(void){
   ++hMotorTicks;
  if(hMotorTicks % 2){
      set_timer3(0);
   }
  else{
 
  }
}

/* Responds to a change on portB and sets the appropriate switch */
#int_RB
void  RB_isr(void){
   int current;
   static int last = 0;

   current = input_b();
   
   if ((!bit_test(current,4))&&(bit_test(last,4))){
      h_right = 1;
   }
   if ((!bit_test(current,5))&&(bit_test(last,5))){
      h_center = 1;
   }
   if ((!bit_test(current,6))&&(bit_test(last,6))){
      v_down = 1;
   }
   
   last = current;
}

void setLight(short st){
   int state;
   if(st)
      state = 0x22;
   else
      state = 0x23;
   printf("%c", state);
}

void clearLCD(){
   printf("%c", 0x21);
}

void setColor(int color){
   printf("%c%c", 0x24, color); // set color
}

void setXY(int x, long y){
   printf("%c%c%c", 0x25, x ,y);
}

void selectFont(int font){
   printf("%c%c", 0x2B, font);
}

void putIcon(int x, long y, int icon){
   setXY(x, y);
   printf("%c%c", 0x57, icon);
}

void boxFill(int x1, long y1, int x2, long y2, int color){
   setXY(x1, y1);
   setColor(color);
   printf("%c%c%c", 0x43, x2, y2);
}

void textDirection(int dir){
   int direction;
   
   if(dir == 0)
      direction = 0x60;  // North
   if(dir == 1)
      direction = 0x61;  //East
   if(dir == 2)
      direction = 0x62;  //South
   if(dir == 3)
      direction = 0x2F;  //West
   printf("%c", direction);
}

void myPrintf(int x, long y, char* data, int color){
   setColor(color);
   setXY(x, y);
   printf("%c%s%c", 0x2D, data, 0);
}

void myPrintf(int x, long y, int data, int color){
   char txtBuffer[50] = {};

   setColor(color);
   sprintf(txtBuffer, "%d", data);
   myPrintf(x, y, txtBuffer, color);
}

void myPrintf(int x, long y, long data, int color){
   char txtBuffer[50] = {};
   
   setColor(color);
   sprintf(txtBuffer, "%ld", data);
   myPrintf(x, y, txtBuffer, color);
}

.
.
.


When I compile the complete program, I get the following

*** Error 165 "4550.c" Line 137(30,35): No overload function matches
1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Mon Aug 18 17:43:19 2008

The text that is highlighted is the word color in this function
Quote:
void myPrintf(int x, long y, int data, int color){
char txtBuffer[50] = {};

setColor(color);
sprintf(txtBuffer, "%d", data);
myPrintf(x, y, txtBuffer, color);
}

Now if I comment out any function below the INT_RB function and above the function that errors, the program compiles fine. It's almost like I have reached some internal boundary. When the program does compile I am using < 10% RAM and <15% ROM.

Any ideas as to what is happening???
Guest








PostPosted: Thu Jul 24, 2008 4:44 pm     Reply with quote

Do you really want this to call myPrintf or printf?


void myPrintf(int x, long y, int data, int color){
char txtBuffer[50] = {};

setColor(color);
sprintf(txtBuffer, "%d", data);
myPrintf(x, y, txtBuffer, color); <<< - Should this be printf???
}

This happens 2 places...

Steve H.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jul 24, 2008 5:29 pm     Reply with quote

I don't have v4.047 but couldn't reproduce the error in v4.038, 4.057 and 4.074. This might have to do with specific compiler settings not visible here, for example what compilation mode do you have selected (#device CCS3, CCS4 or ANSI)?

Please post a small but complete test program that we can copy/paste into our compiler. Remove everything from your original program so you have left only the 3 overloaded functions and a main(). You should be able to reduce it to a maximum 30 lines of code.

An unrelated hint. Replacing:
Code:
 char txtBuffer[50] = {};
by
Code:
 char txtBuffer[50];
will save 100 bytes of code as the array initialization can be skipped.
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