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

Pointers in 16F690

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



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat Mar 20, 2010 7:03 am     Reply with quote

This is covered in many posts here. A search should find a lot about it.

However, a series of basic things:
This comes about because of the architecture of the PIC. Historically, most 'commonly used processors, have the RAM, and ROM, sitting in the same address space. On the PIC, a different architecture is used. The Harvard architecture. This has separate address spaces for ROM, and RAM. Now the problem this introduces, is that 'address 100', in a normal (Von Neumann) architecture processor, always refers to just one location. On the Harvard architecture, there are two locations with this address - one in ROM, and one in RAM. Then, on the simpler PICs (most of the earlier ones), there is no method of actually reading data 'from' a specific location in the program memory. On these to provide 'constant' storage, a program has to be written, that returns the required byte, when given a particular number, with no ability to select data from a specific address directly.

There are a number of ways of getting (at least in part) the effect of using pointers, or of actually using them:

First one:
Have a single RAM buffer, use strcpy, to copy a ROM constant into the buffer, then use this with a standard pointer based function. Since the copied data is now in RAM, normal pointer functions can be used. Downside, a RAM buffer is needed.

Second:
The modern compilers have the ability to do this for you, with the option to pass strings in RAM. Same downside.

Third:
To give some of the same ability, with the least cost in RAM, and ROM, CCS has a 'shortcut' with regards to ROM constant strings.
Code:


void function(int8 chr) {
    //Do something, with just one character
}

//Call with
function("Test string");


Now, the call looks strange, since the function accepts a single character, but is being called with a string. What CCS have done, is if you hand a constant string to a function accepting a single integer, it _automaticall generates the code to call the function repeatedly with each character in turn from the string. This is the most 'code compact' solution. This is in fact what the string copy function does. It is an overloaded function, able to accept either a string address, or a single integer, and if called with the latter, automatically puts the characters passed 'in turn', into the output string.

Fourth:
CCS now allows a 'ROM' construct, that directly supports pointers (on chips with the abilities this needs). Downside, bulkier, and only works on reasonably recent compilers.

A search for 'create pointer to constant', asking for 'all' terms to be found, will return a lot more.

Best Wishes
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Sat Mar 20, 2010 7:34 am     Reply with quote

There is yet another method, but it only works on certain processors. It is available on the PIC16F690. That's what I call a "wormhole" between the ROM and data spaces, which you can access by using the read_program_eeprom command, or by writing your own routine. If space is really tight, you can load each ROM location with 14 bits rather than 8.

I've never found (never needed to find) a really elegant way to make this work, but it definitely is usable. It's not really a pointer operation, but you could write a function to make it look more normal.

Sorry if this method is actually involved in one of TTelmah's suggestions, but I don't think it was. It's not likely that the compiler would use it, given that it's not available on all the processors.
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