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

multidimensional array to functions arg

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







multidimensional array to functions arg
PostPosted: Mon Jun 02, 2008 6:00 am     Reply with quote

Hello

I have a problem.

I would like to pass a constant multidimensional array to a function but having trouble reading the array elements when passed. the code is:

Code:

// multi array to pass as arg to function
char MANUAL_bitmap[5][9] ={     {0b00000000,0b00000000,0b00011000,0b00011010,0b00011010,0b00011010,0b00011010,0b00011010,0b00000000},     /* 0x44*/
{0b00000000,0b00111111,0b01101101,0b01101101,0b01101101,0b01101101,0b01101101,0b01101101,0b00000000}, /* 0x43*/
{0b00000000,0b00000000,0b10000000,0b10011110,0b10110110,0b10110110,0b10110110,0b10011110,0b00000000},     /* 0x42*/ {0b00000000,0b00000000, 0b00000000,0b01110011,0b11011011,0b11011011,0b11011011,0b11011001,0b00000000},  /* 0x41*/
{0b00000000,0b00000000, 0b00000000,0b01100111,0b01101101, 0b01101101,0b01101101,0b11000111,0b00000000},   /* 0x40*/
      };



// function to use multi array
void displayOptions_178(char Invert, char ptr[5][9]){
char yMarker = 0, xMarker = 0;
char tmepUi8 = 0;

/* clear title section manul auto part */
clearSection_178();

for(xMarker = 0; xMarker<5;xMarker++)
   {
     wr_cmd(0x20);
     wr_cmd(0x44-xMarker);        // x address
     for(yMarker=0;yMarker<9;yMarker++)
        {
         wr_cmd(178+yMarker);          // y address   
         if(Invert == HIGHLIGHT_AUTO ) // highight manual
         // tmepUi8   = *(*(ptr + yMarker) + xMarker);
         // tmepUi8 = ptr[xMarker][yMarker];
            wr_data((char)~(ptr[xMarker][yMarker])); // yes invert 
         else
            wr_data((ptr[xMarker][yMarker]));       // no invert
        }   
    }
}

The wr_cmd and wr_data are for sending commands to a lcd driver and wr_data is a method to send the actual data.

The array that I try to send is a piece of a bitmap which i would like to display. However having trouble reading elements.

Can anyone help. I know there are alternatives, but need multidimensional array to work.

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 02, 2008 12:09 pm     Reply with quote

1. Post a little test program that shows how you are calling that function.
Show all variable declarations.

2. Post your PIC.

3. Post your compiler version.
XXX
Guest







PostPosted: Tue Jun 03, 2008 2:40 am     Reply with quote

Hi PCM Programmer

The compiler version is 4.062

PIC is a PIC18F8520


Code:


#include<18F8520.h>
#FUSES H4
#device adc=10
#device  high_ints = true;
#use delay(clock=40000000)
#use rs232(baud = 115000,xmit=PIN_C6,rcv=PIN_c7)



const char MANUAL_bitmap[5][9] ={     {0b00000000,0b00000000,0b00011000,0b00011010,0b00011010,0b00011010,0b00011010,0b00011010,0b00000000},     /* 0x44*/
{0b00000000,0b00111111,0b01101101,0b01101101,0b01101101,0b01101101,0b01101101,0b01101101,0b00000000}, /* 0x43*/
{0b00000000,0b00000000,0b10000000,0b10011110,0b10110110,0b10110110,0b10110110,0b10011110,0b00000000},     /* 0x42*/ {0b00000000,0b00000000, 0b00000000,0b01110011,0b11011011,0b11011011,0b11011011,0b11011001,0b00000000},  /* 0x41*/
{0b00000000,0b00000000, 0b00000000,0b01100111,0b01101101, 0b01101101,0b01101101,0b11000111,0b00000000},   /* 0x40*/
 };

// function to use multi array
void displayOptions_178(char ptr[5][9]){
char yMarker = 0, xMarker = 0;


for(xMarker = 0; xMarker<5;xMarker++)
   {

     for(yMarker=0;yMarker<9;yMarker++)
        {             
                  printf("%d\n\r" ptr[xMarker][yMarker]); // yes invert 
        }   
    }
}

void main(){
    displayOptions_178(MANUAL_bitmap);
    while(1);
}



I have modified the code so that it is a simple function that takes a mutidimensional array and prints the elements out to screen. However it does not work. Tried other ways but still doesnt work, probably its my understanding so any tips would be good. Please note that I would like to use const array if possible.


thanks
Ttelmah
Guest







PostPosted: Tue Jun 03, 2008 3:34 am     Reply with quote

For testing, get rid of 'high_ints=true'. This _must not_ be enabled, if you do not have a high priority interrupt handler enabled, but do have other interrupt handlers present. Because of the way the hardware works on the chip, if interrupt priorities are enabled (which this does), some interrupts _must_ be high priority. If you enable this, and don't have any high priority interrupts actually enabled, it can cause major problems...
Second, add the 'NOXINST' fuse. Though this should be the default, make sure...
The big one though, is to use the 'ROM' declaration, rather than the 'const' declaration. As it currently stands, you are passing the pointer in the call (which is not legal for a constant array, unless you have '#device CONST=ROM' selected, or use the ROM declaration), but the receiving routine, expects to get the pointer to the array...

Best Wishes
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