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

Problem with : Porting driver to ccs
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

Problem with : Porting driver to ccs
PostPosted: Fri Aug 05, 2011 7:46 am     Reply with quote

Hi guys trying to port a Arduino driver to CCS and facing the pointer to constant error .

Here the function being called
Code:

/*
 * scrolltextcolor()
 * Scrolls a text string from left to right
 * Simple function for the original ht1632_putchar method without MULTICOLOR and no background color
 * Original function by Bill Ho
 * scrolltextxcolor(y location, string ,  colorname (RANDOMCOLOR for random color), delaytime in milliseconds)
 */


void scrolltextxcolor(int y,char Str1[ ], byte color, int delaytime){ 
  int messageLength ;
   messageLength = strlen(Str1)+ 1;
  byte showcolor;
  int xa = 0;
  while (xa<1) {
    int xpos = X_MAX;
    while (xpos > (-1 * ( 6*messageLength))) {
      for (i = 0; i < messageLength; i++) {

        if (color==4){
          showcolor=rand()+1;
        }
        else
        {
          showcolor=color;
        }
        ht1632_putchar(xpos + (6* i),  y,Str1[i],showcolor);


      }
      delay_ms(delaytime);// reduce speed of scroll
      xpos--;
    }
    xa =1;
  }
}


Here the line in main() that get the error !!
Code:


 scrolltextxcolor(4,"HAPPy New year    ",RANDOMCOLOR,30);


Thanks for your help !!

PIC18F452
CCS 4.124


Last edited by mindstorm88 on Tue Aug 09, 2011 10:33 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 05, 2011 12:27 pm     Reply with quote

Quote:
#include <18F452.h>
#device PASS_STRINGS=IN_RAM
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)

Add the line shown in bold below, in that position. The compiler will then
copy the constant string to RAM and pass the RAM string to the function.
This is all handled internally by the compiler, if you add that #device line.
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Fri Aug 05, 2011 12:52 pm     Reply with quote

You got it right on !!!! now another problem appear according to the length of the string if i put
Code:

scrolltextxcolor(4,"PCM programmer is th",RANDOMCOLOR,30);

it works , but if i add 1 character or more as this
Code:

scrolltextxcolor(4,"PCM programmer is the Best",RANDOMCOLOR,30);

it freezes , it seems to be at this line
Code:

while (xpos > (-1 * ( 6*messageLength)))


Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 05, 2011 12:57 pm     Reply with quote

Quote:
int xpos = X_MAX;

In CCS, an 'int' is an unsigned 8-bit integer. In Arduino, it's a
signed 16-bit integer. In CCS, you need to declare it as 'signed int16'.

Arduino data types:
http://arduino.cc/en/Reference/Int

Also, my advice is don't do declarations of variables in mid-code. Move
them to the beginning of the function.
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Fri Aug 05, 2011 1:12 pm     Reply with quote

Thanks a lot, you've just proved again why this sentence needed to be printed !!!!! Wink

Code:

scrolltextxcolor(4,"PCM programmer is the Best",RANDOMCOLOR,30);
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 9:48 am     Reply with quote

PCM programmer wrote:
In Arduino, it's a
signed 16-bit integer.

Arduino data types:
http://arduino.cc/en/Reference/Int


I'm really mixed on whether 8bit compilers should default to 16bit int's. (signed or not)

I did read somewhere that the "int" should default to the architecture's int size, but C18, and apparently others do the same thing. 16bit ints are default on 8bit architectures.

This is nice for standardization, but it becomes really easy to overload a minimal-sized 8bit CPU with 16bit math everywhere.

(I've seen this before with C18 code not fitting code into a PIC18F where once the code was changed to be more explicitly 8bit, a HUGE amount of Program FLASH was reclaimed for more code.)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 2:42 pm     Reply with quote

It is in K&R.
It is bent more often than adhered to, since many 8bit chips have native 16bit operations.
If you look at the Intel chips the 8088, was an 8bit microprocessor, but deliberately written to emulate the 16bit architecture they were trying to launch at the same time....

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 3:04 pm     Reply with quote

Ttelmah wrote:
It is in K&R.
It is bent more often than adhered to, since many 8bit chips have native 16bit operations.
If you look at the Intel chips the 8088, was an 8bit microprocessor, but deliberately written to emulate the 16bit architecture they were trying to launch at the same time....



Irritating. I see a lot of waste on 8bit PIC's when C18 is used because programmers just take the default without looking any deeper.

I've recently been doing some stuff in Dynamic-C for the Rabbit's (OMG, don't get me started) and it's INT is signed-16 by default.

Bleah.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 10:40 am     Reply with quote

Ok another problem from my porting , i get an identifier problem when passing an array name to function, i can't see what's wrong !!

Code is not complete as it is really big !!

the problem is passing the my2font array !!

Here the first call :
Code:

scrolltextsizexcolor(1,"PCM programmer rocks    ",2,RANDOMCOLOR, 0,my2font,8,8,'G',0);


First function being called:
Code:

void scrolltextsizexcolor(int y,char Str1[ ], char size, byte color, byte secondcolor,  unsigned char fontname, int columncountfont, char rowcountfont, char oddeven, int delaytime){
    messageLength = strlen(Str1)+ 1;
   
  xa = 0;
  while (xa<1) {
    xpos = X_MAX;
    while (xpos > (-1 * ( columncountfont*size* messageLength))) {
      for (i = 0; i < messageLength; i++) {
        if (color==4){
          showcolor=rand()+1;
        }
        else
        {
          showcolor=color;}
          if (secondcolor==4){
        showsecondcolor=rand()+1;
      }
      else
      {
        showsecondcolor=secondcolor;
      }
        ht1632_putcharsizecolor(xpos + (columncountfont*size * i),  y,Str1[i],   size,   showcolor, showsecondcolor,  fontname,  columncountfont, rowcountfont,  oddeven);
       
      }
      delay_ms(delaytime);// reduce speed of scroll
      xpos--;
    }
    xa =1;
  }
}


Second Function called by the first , problem at compilation happen here !!!
Code:

void ht1632_putcharsizecolor(int x, int y,int8 c,  char size, byte color, byte secondcolor, unsigned char fontname,  int columncountfont, char rowcountfont, char oddeven)  //unsigned char fontname[][NCOLUMNS]
{

 // unsigned char dots, dots2,dots3;
  //byte cc,cc2, cc3, rr, g, t, t3, divisor;
 // byte maximumdrawfont, showcolor,showsecondcolor; //128 for the large fonts (=8x8 and 12x8), 64 for all smaller ones
  if  (rowcountfont<=7)
    maximumdrawfont=64;
  else
    maximumdrawfont=128;
  for (col=0; col<columncountfont*size ; col++) {
    // Addressing the right 8 lines because 'The Dot Factory' starts from the bottom, all others from top 
    if (rowcountfont <=8) {
      cc=col/size;
      dots = fontname[c][cc];  //***** Previous identifier must be a pointer******



      divisor=1;
    }


Part of the array used by the function
Code:

const char my2font[256][8]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},   // 0x00
{0x7E,0x81,0xA9,0x8D,0x8D,0xA9,0x81,0x7E},   // 0x01
{0x7E,0xFF,0xD7,0xF3,0xF3,0xD7,0xFF,0x7E},   // 0x02
{0x70,0xF8,0xFC,0x7E,0xFC,0xF8,0x70,0x00},   // 0x03
{0x10,0x38,0x7C,0xFE,0x7C,0x38,0x10,0x00},   // 0x04
{0x1C,0x5C,0xF9,0xFF,0xF9,0x5C,0x1C,0x00},   // 0x05



Last edited by mindstorm88 on Tue Aug 09, 2011 11:11 am; edited 1 time in total
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 10:50 am     Reply with quote

mindstorm88 wrote:
Ok another problem from my porting , i get an identifier problem when passing an array name to function , i can't see what's wrong !!

Code is not complete as it is really big !!



Then you should write a small example of the problem.

I find when I do that, I figure out the problem myself before I need to come here.

So write a small example... and see if that doesn't help.

What you're asking now is to debug your code for you... which we don't mind, but we have the requirement that you distill it down to something we can quickly digest. There's a lot of context missing (as you said, because your code is big) and we don't have time to go over it all. (we have to work to pay the bills)

But make a small example that shows your issue and we'll be happy to look at it.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 11:04 am     Reply with quote

bkamen wrote:
What you're asking now is to debug your code for you... which we don't mind, but we have the requirement that you distill it down to something we can quickly digest. There's a lot of context missing (as you said, because your code is big) and we don't have time to go over it all. (we have to work to pay the bills)

But make a small example that shows your issue and we'll be happy to look at it.

-Ben


I do understand Ben, even if I do a small part it won't compile !! I think it is just in the way the declaration of array is made between functions call !!!

If nobody sees it, i'll try to minimize it as much as possible for this function to be stand alone !!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 12:12 pm     Reply with quote

Your problem is "how to I pass a 2-dimensional array to a function in CCS ?"

Strip your program down to essentials. Get rid of everything except
what's needed to study the problem. This is called making a test program.

Here's an example:

If I run the test program below, I get the following output in the MPLAB
simulator:
Quote:

7E, 09, 09, 09, 7E,
7F, 49, 49, 49, 36,
3E, 41, 41, 41, 22,


Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void ht1632_putcharsizecolor(int8 fontname[3][5])
{
int8 dots;
int8 row;
int8 col;

for(row=0; row < 3; row++)
   {
    for(col=0; col < 5; col++)
       {
        dots = fontname[row][col]; 
        printf("%X, ", dots);
       }
     printf("\r");
   }
}

//==========================================
void main()
{
int8 ABCfont[3][5] =
{
0x7E, 0x09, 0x09, 0x09, 0x7E, // A
0x7F, 0x49, 0x49, 0x49, 0x36, // B
0x3E, 0x41, 0x41, 0x41, 0x22, // C
};

ht1632_putcharsizecolor(ABCfont);

while(1);
}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Aug 09, 2011 1:18 pm     Reply with quote

I don't know how critical it is to pass arrays by reference....

But I have found that designing so as to declare and access arrays in a global fashion saves a lot of code space and delay, so long as you keep your wits about you.
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Wed Aug 10, 2011 6:01 am     Reply with quote

PCM programmer wrote:
Your problem is "how to I pass a 2-dimensional array to a function in CCS ?"



That's exactly it !!

the goal is to be able to use the same function with 2-dimensional array of different size !!

is it possible ???

if the function is written this way :
Code:

void ht1632_putcharsizecolor(int8 fontname[3][5])

it means all array use by this function must be 3x5 ??
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Wed Aug 10, 2011 1:12 pm     Reply with quote

Here a strip down to 2 functions, the problem is still passing the array between function and the variable "rowcountfont" that change its value from one function to the other for no apparent reason !!! it start at main with a value of 8 , still 8 in the first function then 47 in the second tested in mplab sim !!

Code:

#include <18F452.H>
#device PASS_STRINGS=IN_RAM
#device adc=10
#fuses hs, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define RAND_MAX  3
#include <STDLIB.H>
#define Number_of_Displays 1
#define X_MAX (32*Number_of_Displays -1)
#USE FAST_IO (D)
#define CLK_DELAY delay_cycles(1)
#define RED    2

int8 my2font[3][8]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},   // 0x00
{0x7E,0x81,0xA9,0x8D,0x8D,0xA9,0x81,0x7E},   // 0x01
{0x7E,0xFF,0xD7,0xF3,0xF3,0xD7,0xFF,0x7E},   // 0x02
};

int16 i;
int8 xa ;
signed int16 xpos, messageLength ;
char col ;
int8 dots, cc, showcolor,showsecondcolor, divisor, columncountfont, rowcountfont;
char oddeven;
/*******************************************
* second function called by the first one
*******************************************/
void ht1632_putcharsizecolor(int8 x, int8 y,char c,  char size, int8 color, int8 secondcolor, int8 fontname[3][8],  int8 columncountfont, int8 rowcountfont, char oddeven)  {
    for (col=0; col<columncountfont*size ; col++) {
     
    if (rowcountfont <=8) {
      cc=col/size;
      dots = fontname[c][cc]; 

     printf("%X, ", dots);

      divisor=1;
    }
   
   printf("\r");
   
  }
}
/**************************************
* first function being called
***************************************/

void scrolltextsizexcolor(int8 y,char Str1[ ], char size, int8 color, int8 secondcolor,  int8 fontname, int8 columncountfont, int8 rowcountfont, char oddeven, int8 delaytime){
    messageLength = strlen(Str1)+ 1;
   
  xa = 0;
  while (xa<1) {
    xpos = X_MAX;
    while (xpos > (-1 * ( columncountfont*size* messageLength))) {
      for (i = 0; i < messageLength; i++) {
        if (color==4){
          showcolor=rand()+1;
        }
        else
        {
          showcolor=color;}
          if (secondcolor==4){
        showsecondcolor=rand()+1;
      }
      else
      {
        showsecondcolor=secondcolor;
      }
        ht1632_putcharsizecolor(xpos + (columncountfont*size * i),  y,Str1[i],   size,   showcolor, showsecondcolor,  fontname, columncountfont, rowcountfont, oddeven);
      }
      delay_ms(delaytime);// reduce speed of scroll
      xpos--;
    }
    xa =1;
  }
}


/***********************************************************************
 * MAIN
 ***********************************************************************/

void main() 
{
 while(1)
{
scrolltextsizexcolor(1,"\2\1 ",2,RED, 0,my2font,8,8,'G',0);
}
}

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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