 |
 |
View previous topic :: View next topic |
Author |
Message |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Wed Jul 15, 2009 12:54 pm |
|
|
I'd just pass the array to the function as a pointer. Don't bother to dimension it at all. But make sure that the amount of memory needed is actually available, and not being used for anything else! Though in fact this version of the code does define the arrays, which makes sure they exist properly. Or have I missed some vital point which requires doing it the hard way?
This compiled fine for me:
Code: |
byte message2[ROW_HEIGTH][MAX_MESSAGE_SIZE];
byte MESSAGE_BUFFER_TEMP[ROW_HEIGTH][LED_MARTIX_8X8];
void init_buffer (char *array)
{
char row,col;
for (row=0;row<ROW_HEIGTH;row++)
for (col=0;col<LED_MARTIX_8X8;col++)
*(array + row * ROW_HEIGTH + col) =0xFF;
}
main()
{
init_buffer(MESSAGE_BUFFER_TEMP);
init_buffer(message2);
}
|
|
|
 |
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Wed Jul 15, 2009 12:56 pm |
|
|
PCM programmer wrote: | The test program shown below displays the following output:
Code: | #include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define NUM_ROWS 2
#define NUM_COLS 3
void myfunc(char array[NUM_ROWS][NUM_COLS])
{
int8 row, col;
for(row=0; row < NUM_ROWS; row++)
{
for(col = 0; col < NUM_COLS; col++)
printf("%c ", array[row][col]);
printf("\n\r");
}
}
//======================================
void main(void)
{
int8 data[NUM_ROWS][NUM_COLS] = { {'1', '2', '3'},
{'A', 'B', 'C'} };
myfunc(data);
while(1);
}
|
|
In the past using other compilers the function call could be declared as:
Code: |
void myfunc(char array[][NUM_COLS])
|
In other words the umber of rows do not need to be specified. But I find with the CCS compiler this does not work, the number of rows need to be explicitly specified. |
|
 |
diogoc
Joined: 12 Feb 2008 Posts: 19
|
|
Posted: Wed Jul 15, 2009 1:09 pm |
|
|
I have tested every test programs in this thread and no one works.
Code: |
int message[16][16];
void init (int array[16][16])
{
int row,col;
for (row=0;row<16;row++)
for (col=0;col<16;col++)
array[row][col]=0;
}
void main(void)
{
init(message);
}
|
with the code above it compile but i discover that my pic resets on init function.
Code: |
int message[16][16];
void init (int (*array)[16])
{
int row,col;
for (row=0;row<16;row++)
for (col=0;col<16;col++)
array[row][col]=0;
}
void main(void)
{
init(message);
}
|
the code above is the standard use in C but the compiler give an error.
I use dspic30f6012a on a board build by me.
my compiler is V4.088
maybe is more one bug in that compiler.
I have found a solution by increment a pointer to a 2d array...
thanks anyway |
|
 |
|
|
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
|