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 support@ccsinfo.com

memcpy and const tables

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



Joined: 11 Sep 2003
Posts: 17
Location: Switzerland

View user's profile Send private message

memcpy and const tables
PostPosted: Wed Mar 28, 2007 7:51 am     Reply with quote

Hello,
I am developing an application with a graphical LCD, and am running into the problem of displaying bitmaps on my lcd.

I want to store my bitmaps in rom using a #rom statement. But I then cannot retrieve the correct data using memcpy. Here's my code:

Bitmap declaration and storage
Code:

#define  LOGO 0x0F000
...
#rom int8 LOGO = {0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xFF, 0xFF, 0xFF,
                         0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}


In main, after lcd initialisation etc...
Code:

   ...
   glcd_drawbitmap(90,30,LOGO,8,16);
   ...


The glcd_drawbitmap routine
Code:

void
glcd_drawbitmap(int x, int y, int32 bitmapAddress, int width, int height)
{
   int bitmapData[1024];
   int *bitmapPointer=bitmapData;
   int i,j,k;

   height=height>>3;
   memcpy(bitmapPointer, bitmapAddress, width*height);

   
   for(i=0;i<height;i++)
   {
      for(j=0;j<width;j++)
      {
         for(k=0;k<8;k++)
         {
            if(bit_test(*bitmapPointer,k))
               glcd_pixel(x+j,y+(i<<3)+k,ON);
            else
               glcd_pixel(x+j,y+(i<<3)+k,OFF);
         }

         bitmapPointer++;
      }
   }
}       


This will only output garbage (and always the same garbage) on my lcd, I suspect the memcpy to not copy the correct area of my flash into the bitmapData table. What am I doing wrong ? I searched the forum for memcpy and #rom, but nothing really helped me...

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 11:29 am     Reply with quote

Make a small test program where you test only the memcpy()
function. Study the function documentation. Look at the .LST file
to see what it's doing.

By a small program, I mean less than 6 lines of code in main().
Concentrate on fixing the memcpy() problem only. Don't write
to the LCD. Don't #include the LCD driver files. Use printf()
to a terminal window for output. Keep it very simple.

If you can't solve it, then post your test program. Be sure to post
all the #include, #use and #fuses statements. Also post your compiler
version.
me, sebdey
Guest







PostPosted: Thu Mar 29, 2007 12:43 am     Reply with quote

Thanks PCM,
but here I am not looking for a lesson but an answer from someone who could reduce my development time...

I have already solved my problem by other means, i.e. declaring the arrays as:

Code:

#define LOGO_ID   0
const int8 LOGO[16] = {0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xFF, 0xFF, 0xFF,
                               0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

#define BITMAP1_ID   1
const int8 BITMAP1[length] = {data...};

#define BITMAP2_ID   2
const int8 BITMAP2[length] = {data...};

...


and then reading them in my glcd_drawbitmap by using:

Code:

(...)
switch (bitmapID)
{
   case LOGO_ID:
      memcpy(bitmapPointer,LOGO, width*height);
      break;
   case BITMAP1_ID:
      memcpy(bitmapPointer,BITMAP1, width*height);
      break;
   (...)



But even if this is working, it's not what I want. If no one is willing to give me a short and quick answer, I don't want to lose time trying things that I already tried for hours.
I have done tests with memcpy and standard ram arrays and also with const rom arrays and it works, but no chance with a #rom memory definition... Maybe is this completely impossible and I should resolve it with a read_program_memory or my current solution...

Have a good day...
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Thu Mar 29, 2007 7:40 am     Reply with quote

Because CCS dosen't handle ROM pointers correctly ( yet? ), You have to fake it out and write your own routines.

This is geard towards PIC18s, it may work for you, but I don't know for sure because I don't know what chip you are using.


Code:

#define TBLPTRU 0xFF8
#define TBLPTRL 0xFF6
#define TABLAT   0xFF5

#byte   _TBLPTRU = TBLPTRU
#byte   _TBLPTRL = TBLPTRL
#byte   _TABLAT = TABLAT

void rom_to_ram_memcpy(int8 *ramptr, int8 *romptr, int16 numberofBytes);





Code:


#define  LOGO 0x01000
#rom int8 LOGO = { 0x12, 0x34 }
int8 bitMapData[ 16 ];

void main( void )
{



   int8 *bitMapPointer = bitMapData;

   rom_to_ram_memcpy( bitMapPointer, LOGO, 2 );



}


void rom_to_ram_memcpy(int8 *ramptr, int8 *romptr, int16 numberofBytes)
{

   char *_TBLPTR;
#locate _TBLPTR = TBLPTRL

//Setup ROM TABLE Pointer
   _TBLPTRU = 0x00;
   _TBLPTR = romptr;


   for (; numberofBytes-- ; ramptr++ ) {
#asm
      TBLRD   *+
#endasm

      *ramptr = _TABLAT;
   }
   

}
_sebdey
Guest







PostPosted: Thu Mar 29, 2007 8:53 am     Reply with quote

Thanks for your answer kevcon !

I will then have to see which method is the best for my project in terms of ease of use/implementation/scalability....

Btw, my fault, I forgot to mention that I am using 18F4620, and 3.235...

Have a good day/night/evening !
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