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

Pointers and a data array - help please

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



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

Pointers and a data array - help please
PostPosted: Mon Aug 20, 2007 12:22 am     Reply with quote

Hi, im following an example for sending voice hex data over spi. Code in example is with different compiler, so I need to know its equivalent to CCS. MP Lab is coming up with errors for accessing each byte and the function line:

Code:

unsigned int Sound_Pointer;
Sound_Pointer = 0;
while(Sound_Pointer < sound1_size) {
while(!input(DREQ)){
            }
            spi_write(sound1[Sound_Pointer]);
            Sound_Pointer++;
}



..........


Code:

#define sound1_size 12106
//I AM HAVING PROBLEMS WITH THE FOLLOWING LINE
static unsigned char code sound1[12106] = {
   0x52, 0x49, 0x46, 0x46, 0x0E, 0x2E, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20,
   0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11, 0x2B, 0x00, 0x00, 0x22, 0x56, 0x00, 0x00,
   0x02, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0xBA, 0x2D, 0x00, 0x00, 0x56, 0x01, 0x54, 0x01,
   0x58, 0x01, 0x56, 0x01, 0x54, 0x01, 0x5D, 0x01, 0x5D, 0x01, 0x4E, 0x01, 0x50, 0x01, 0x4F, 0x01,
   0x49, 0x01, 0x4A, 0x01, 0x46, 0x01, 0x45, 0x01, 0x48, 0x01, 0x53, 0x01, 0x4F, 0x01, 0x51, 0x01,

…………

};
Ttelmah
Guest







PostPosted: Mon Aug 20, 2007 4:10 am     Reply with quote

A couple of comments:
1) Remember that in CCS,an integer is 8bit. To access an array of 12000 elements, you need to use an int16.
2) The array is huge. What PIC do you have?. As it stands, the array needs to be copied to RAM (the default behaviour). Has you chip got 12K of RAM?. I can't think of any PIC18 (or even less so, a PIC16), that has this much RAM. If the array is only going to be used without changes, then declare it as 'const', so it'll be stored in ROM. The code looks as though it is written for a chip with more RAM resources than the PIC.

Best Wishes
uni_student



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Aug 20, 2007 11:59 pm     Reply with quote

Quote:
What PIC do you have?.


Yeah voice data is huge, that array is only for saying "one". Am using a PIC18F452. Yep i have made it a const now, and after a few other mods finally got it working.

Quote:
Remember that in CCS,an integer is 8bit. To access an array of 12000 elements, you need to use an int16.


It didnt work with "int16" but i managed to find some other example with a similar array size and they used "unsigned long int".

Thanks for your help, definately another big step forward for me, Cheers
Ttelmah
Guest







PostPosted: Tue Aug 21, 2007 4:29 am     Reply with quote

int16, should work, provided you are not using a _very_ old compiler.
These alternatives for the use of 'long' etc., were added a few years ago, and are preferred, since it makes it obvious just what 'length' the integer is. Given that CCS has the default int, as 8bits, and a 'long' as 16, while most compilers use int16 as the default (which is the ANSI definition), while CCS's approach, is the way that K&R originally assumed the sizes would be done, using 'named' sizes, avoids problems with migration latter...

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