EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Question about PIC CCS compiler

Started by Bob March 15, 2004
I need to write a routine that Checksums the program memmory on a PIC
using the CCS compiler.
I want to declare a pointer to program space.
I thought that I could just declare a "const char * ptr" but the
compiler does not seem to like this.

Any one know how to get a pointer to program space?

Thanks,

Bob Weiman
On 15 Mar 2004 08:24:28 -0800, google.4.oracle@xoxy.net (Bob) wrote:

>I need to write a routine that Checksums the program memmory on a PIC >using the CCS compiler. >I want to declare a pointer to program space. >I thought that I could just declare a "const char * ptr" but the >compiler does not seem to like this. > >Any one know how to get a pointer to program space?
The problem is the PIC, not the compiler. There is no way to access program memory on 12 and 14 bit PIC cores. For example, code up something like unsigned char const array[5] = {1, 8, 4, 3, 6}; An see what it compiles to. Hint: it's a subroutine that returns the the specified value for the passed index. Not sure about 16 bit cores. I think there might be a way with those. Regards, -=Dave -- Change is inevitable, progress is not.
Dave Hansen wrote:
> > On 15 Mar 2004 08:24:28 -0800, google.4.oracle@xoxy.net (Bob) wrote: > > >I need to write a routine that Checksums the program memmory on a PIC > >using the CCS compiler.
> The problem is the PIC, not the compiler. There is no way to access > program memory on 12 and 14 bit PIC cores.
That must depend on the particular device. The 16F88, a newer 14-bit device, extends the EEPROM read/write interface to cover the flash code space as well. You can use it to checksum the program. I doubt you can use pointer syntax, though, for access. Thad
google.4.oracle@xoxy.net (Bob) wrote in message news:<aacb3d3a.0403150824.ccc5174@posting.google.com>...
> I need to write a routine that Checksums the program memmory on a PIC > using the CCS compiler. > I want to declare a pointer to program space. > I thought that I could just declare a "const char * ptr" but the > compiler does not seem to like this. > > Any one know how to get a pointer to program space? > > Thanks, > > Bob Weiman
On the older PICs you can't get to the program space. PICs use a Harvard architecture, which means program and data spaces are seperate. Later versions of PICs have a table read instruction that can be used to read a value from the program space. You might try looking at the READ_PROGRAM_MEMORY function (also called READ_EXTERNAL_MEMORY). On PICs that support table read instructions, these might work. Happy coding, Mark
Dave Hansen <iddw@hotmail.com> wrote in message
news:40560d6a.439733828@News.individual.net...
> On 15 Mar 2004 08:24:28 -0800, google.4.oracle@xoxy.net (Bob) wrote: > > >I need to write a routine that Checksums the program memmory on a PIC > >using the CCS compiler. > >I want to declare a pointer to program space. > >I thought that I could just declare a "const char * ptr" but the > >compiler does not seem to like this. > > > >Any one know how to get a pointer to program space?
Interesting that the XCSB compiler (structured PIC BASIC) supports pointers to program memory and a C compiler does not.
> > The problem is the PIC, not the compiler. There is no way to access > program memory on 12 and 14 bit PIC cores
This was correct some time ago but it changed with the 16F87x. These 14 bit PICs extend the data EEPROM read/write mechanism to cover the program flash. You can use this mechanism to read any program word. Newer PICs like the 16F818, 16F819 and 16F88 also have this facility. Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler
On Tue, 16 Mar 2004 04:46:39 -0000, "Sergio Masci"
<sergio@NO.SPAM.xcprod.com> wrote:

> >Dave Hansen <iddw@hotmail.com> wrote in message >news:40560d6a.439733828@News.individual.net... >> On 15 Mar 2004 08:24:28 -0800, google.4.oracle@xoxy.net (Bob) wrote: >> >> >I need to write a routine that Checksums the program memmory on a PIC >> >using the CCS compiler.
[...]
>> >Any one know how to get a pointer to program space? > >Interesting that the XCSB compiler (structured PIC BASIC) supports pointers >to program memory and a C compiler does not.
And what exactly can you do with such a pointer on a 16C711 or a 12C508? A ROM checksum? I don't think so. CCS does allow you to declare an array of constants or a string to be stored in program memory, as I posted before. But it gets implemented as a subroutine taking the index as a parameter and returning the value at the index. Neither C nor Basic is going to be able to support anything that can't be done in assembly.
> >> >> The problem is the PIC, not the compiler. There is no way to access >> program memory on 12 and 14 bit PIC cores > >This was correct some time ago but it changed with the 16F87x. These 14 bit >PICs extend the data EEPROM read/write mechanism to cover the program flash. >You can use this mechanism to read any program word. Newer PICs like the >16F818, 16F819 and 16F88 also have this facility.
Cool. Can you re-write program memory as well? Bootloader kinds of things? That would imply that PIC "Flash" is, in fact, EEPROM. I haven't had a chance to use these parts yet. There are, however, a lot more 16Cxx and 12Cxx parts available than 16Fxx or 12Fxx parts. Regards, -=Dave -- Change is inevitable, progress is not.
Dave Hansen <iddw@hotmail.com> wrote in message
news:40570a42.504471781@News.individual.net...

> > CCS does allow you to declare an array of constants or a string to be > stored in program memory, as I posted before.
You do not state this anywhere in your previous post and the OP said (with explicit reference to the CCS compiler) "I thought that I could just declare a "const char * ptr" but the compiler does not seem to like this" Given your incorrect general assertion that: "There is no way to access program memory on 12 and 14 bit PIC cores" I assumed you were talking about C compilers for the PIC in general. My comment was regarding a specific C compiler that according to the OP did not seem to support pointers to program memory. Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler
I have found the solution using (as Mark Hahn suggested) the
read_program_eeprom() routine. Reading program space is definitely
support on the F876.

Bob

The 2024 Embedded Online Conference