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

pointer to array problem

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



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

pointer to array problem
PostPosted: Fri Mar 13, 2009 2:08 am     Reply with quote

I have a ccs c program to display several bitmaps , it depends on variable size . No matter I wrote the pointer ptr1 assign to several variables using Malab IDE sim to stimulate program NO correct array items comes out , so anyone help me solve this problems ????

....

Code:
const int8  Logo[] =
{
.......
};

const int8 touch_me[]=
{
0xFF,0x3F,0x30,0xCF,0xEC,0x30,0xFF,0x7F,0xB0,0xDF,0xEC,0x30,0x18,0x61,0xB0,0xD8,
0x0C,0x30,0x18,0x61,0xB0,0xD8,0x0C,0x30,0x18,0x61,0xB0,0xD8,0x0F,0xF0,0x18,0x61,
0xB0,0xD8,0x0F,0xF0,0x18,0x61,0xB0,0xD8,0x0C,0x30,0x18,0x61,0xB0,0xD8,0x0C,0x30,
0x18,0x7F,0xBF,0xDF,0xEC,0x30,0x18,0x3F,0x1F,0x8F,0xEC,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x61,0xBF,0xC0,0x00,0x00,0x00,0x73,0xBF,0xC0,0x00,
0x00,0x00,0x7F,0xB0,0x00,0x00,0x00,0x00,0x6D,0xB0,0x00,0x00,0x00,0x00,0x61,0xBF,
0xC0,0x00,0x00,0x00,0x61,0xBF,0xC0,0x00,0x00,0x00,0x61,0xB0,0x00,0x00,0x00,0x00,
0x61,0xB0,0x00,0x00,0x00,0x00,0x61,0xBF,0xC0,0x00,0x00,0x00,0x61,0xBF,0xC0,0x00,
};

void ShowBMP(int16 x,y,width,high,int8 size)
{
int8 *ptr1,k;
 int8 i,j,l;
 int16 addr;
k=0;         
 addr=y*0x30+x+0x1000;   

switch (size)
{
  case 1: ptr1 = touch_me;break;
  case 2: ptr1=Logo;break;
  ......
}

 for(i=0;i<high;i++)     
    {
    SdCmd(0x46);         
     SdData(addr);
    SdData(addr>>8);
    SdCmd(0x4c);         
    SdCmd(0x42);         

    for(j=0;j<width;j++)
        {
       
        SdData(ptr1+k);   
        k=k+1;
        }
     addr=addr+0x30;     
     }
}

main()
{
   ......
  ShowBMP(0,0,6,24,1);
.....
}
Ttelmah
Guest







PostPosted: Fri Mar 13, 2009 4:00 am     Reply with quote

Read the manual, and the readme.txt.
Note the comments about _const_ arrays.

By default, pointers, point to the RAM. Const arrays are in the ROM. This is a big difference/consequence of the PIC's Harvard memory architecture.

Now, depending on how 'late' your compiler is, you can construct pointers to ROM, by a number of routes. Each imposes a significant overhead.
1) Declare the arrays as ROM, not const. This tells the compiler to add the extra code to support pointers. Downside, sightly larger, and accesses are slower.
2) Select 'PASS_STRINGS_IN_RAM', or #device CONST=READ_ONLY. This involves a significant RAM overhead, but makes the CONST arrays behave like ANSI (read only), and copies them into RAM as necessary, allowing pointers.
3) Select CONST=ROM. Makes stuff declared as const, behave like it is declared as ROM. Downside is the space/speed, and it'll apply to all const declarations.
Remember also, that your pointers may need to be declared as pointers to constants.

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