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

[SOLVED] Manipulating large arrays

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



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

[SOLVED] Manipulating large arrays
PostPosted: Wed Aug 12, 2009 10:55 am     Reply with quote

Using the PIC18F2550 (Has 32k Flash; 2k SRAM; 256byte EEPROM) @ 8MHz INTOSC.

I have to:

1. store large arrays with each having a uniq ID.
2. access them
3. they are to be processed by the same bit banging routine

Hence, what I did was to create a function that would do the bit banging.
This function would lookup the ID against the address of arrays and assign a pointer to the address.
This pointer would then be used by the bit banging routine that does not need to worry about the real address of the array anymore.

Code:

#include <18F2550.h>

#fuses INTRC, NOWDT, PUT, BROWNOUT, NOLVP

#device CONST=ROM

#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <stdlib.h>

#include "Z:\\CMU\\Tukka\\norm\\c\\0.h"
#include "Z:\\CMU\\Tukka\\norm\\c\\1.h"

void main()
{
   unsigned int16 ID = 0, size = 0, counter = 0;
   
   const char *ptr = NULL; /* Points to memory address */
   
   int8 t = 0;

   setup_oscillator(OSC_8MHZ | OSC_INTRC); // 90% precision or 98%?
   
   for(ID = 0; ID < 2; ++ID)
   {
   switch(ID)
   {
      case 0:
               ptr = zero;
               size = sizeof(zero);
      break;

      case 1:
               ptr = one;
               size = sizeof(one);
      break;
   }

   printf("\r\nSize = %Lu bytes. Dump from %LX follows\r\n{", size, ptr); /* sizeof reports the correct size */
   
   for(counter = 0; counter < size; ++counter)
   {
      t = ptr[counter];

      printf("0x%X,", t);
   }

   printf("\b\b\r\n};\r\nDone.");
   }
}


The
Code:

#device CONST=ROM
did all the magic.

Here are snippets from,

#include "Z:\\CMU\\Tukka\\norm\\c\\0.h" :

const char zero[] =
{0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA
,0xD5,0x52,0xAD,0x55,0x54,0xCD,0x55,0x52
,0xA9,0xAB,0x54,0x95,0x9D,0xA9,0x8C,0xD5
,0x6A,0xAA,0xA5,0x52,0xA9,0x29,0xBA,0xDC
,0xC6,0x55,0x55,0x6A,0xA9,0x55,0x52,0x95
..


#include "Z:\\CMU\\Tukka\\norm\\c\\1.h" :

const char one[] =
{0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAD,0x53
,0x52,0xD5,0x52,0xB5,0x54,0xAA,0xC9,0xAA
,0xA9,0x58,0xAF,0x45,0xAB,0x27,0x4B,0x4B
,0x4A,0xAA,0xA6,0xA5,0x4A,0xBE,0x1D,0x34
,0x6D,0x54,0xB5,0x55,0x55,0x54,0xAA,0x92

This raised a few questions however that I have created a new thread for.

(Why can't I attach files in this forum?)


Last edited by vsmguy on Fri Aug 14, 2009 12:49 am; edited 3 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 12, 2009 11:01 am     Reply with quote

Quote:
** Error 97 "PCH_Test.c" Line 3(5,48): Must have a #USE DELAY before this #USE
*** Error 12 "PCH_Test.c" Line 25(24,28): Undefined identifier zero
*** Error 12 "PCH_Test.c" Line 26(30,34): Undefined identifier zero
*** Error 12 "PCH_Test.c" Line 30(24,27): Undefined identifier one
*** Error 12 "PCH_Test.c" Line 31(30,33): Undefined identifier one
*** Error 132 "PCH_Test.c" Line 35(70,73): STDOUT not defined (may be missing #USE RS232) ::
*** Error 132 "PCH_Test.c" Line 45(23,24): STDOUT not defined (may be missing #USE RS232) ::
*** Error 132 "PCH_Test.c" Line 48(32,33): STDOUT not defined (may be missing #USE RS232) ::

Your program is not complete. It doesn't compile.


Quote:
I had a look at the solution by PCM Programmer,

Post a link to this previous example.
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Wed Aug 12, 2009 8:45 pm     Reply with quote

PCM programmer wrote:

Your program is not complete. It doesn't compile.


Was missing a delay line. Does it compile now?


PCM programmer wrote:

Post a link to this previous example.


http://www.ccsinfo.com/forum/viewtopic.php?t=20955&start=3
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 12, 2009 9:09 pm     Reply with quote

Quote:
*** Error 12 "PCH_Test.c" Line 25(24,28): Undefined identifier zero
*** Error 12 "PCH_Test.c" Line 26(30,34): Undefined identifier zero
*** Error 12 "PCH_Test.c" Line 30(24,27): Undefined identifier one
*** Error 12 "PCH_Test.c" Line 31(30,33): Undefined identifier one

Does it compile now?

You're still missing the declarations for 'zero' and 'one'.
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 13, 2009 12:11 pm     Reply with quote

PCM programmer wrote:

You're still missing the declarations for 'zero' and 'one'.


They are very large arrays - around 400 bytes each.

I wanted to upload these to the forum but can't find anything to help me do that.

Should I upload the files to some filesharing site and post the link here?

Which filesharing site?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 1:02 pm     Reply with quote

Just post the declaration and the first line of initialization data
for each array. That will be enough.
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 13, 2009 4:54 pm     Reply with quote

Done!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 6:46 pm     Reply with quote

Read these explanations on 'const' arrays by Ttelmah:
http://www.ccsinfo.com/forum/viewtopic.php?t=38184
http://www.ccsinfo.com/forum/viewtopic.php?t=35864
http://www.ccsinfo.com/forum/viewtopic.php?t=34544
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 13, 2009 7:10 pm     Reply with quote

Extremely insightful. Will update the thread in a few hours.
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