"Bob" <google.4.oracle@xoxy.net> wrote in message
news:aacb3d3a.0403170732.3821f6c7@posting.google.com...
> I need to write a checksum routine for the HiTech C Compiler to run on
> the PIC F876. (I have a working checksum routine for the CCS compiler
> using the read_program_eerom() compiler routine to access the program
> space)
>
> When I try to access program code space, the PIC reboots.
> Can anyone tell me why this does not work (or what will work)?
>
> Bob Weiman
>
> Here is my code:
>
> typedef unsigned int uint16;
>
> uint16 Calc_checksum(void)
> {
> const char * ptr;
> uint16 ui16Checksum;
> uint16 ui16Count;
>
> ui16Checksum = 0;
> ptr = (char *) 0;
> for(ui16Count = 0; ui16Count < END_OF_PROG_SPACE; ui16Count++)
> {
> CLRWDT(); // Reset the watchdog
> ui16Checksum += *ptr;
> ptr++;
> }
> return(ui16Checksum);
> }
You need to use the FLASH_READ macro to access program space. This code will
try and read the code at location zero in the program space ... which is
reset ... and so will restart again and again and again ad infinitum. If you
run MPLAB with the simulator you can see what is going on.
Andrew
Reply by Bob●March 17, 20042004-03-17
I need to write a checksum routine for the HiTech C Compiler to run on
the PIC F876. (I have a working checksum routine for the CCS compiler
using the read_program_eerom() compiler routine to access the program
space)
When I try to access program code space, the PIC reboots.
Can anyone tell me why this does not work (or what will work)?
Bob Weiman
Here is my code:
typedef unsigned int uint16;
uint16 Calc_checksum(void)
{
const char * ptr;
uint16 ui16Checksum;
uint16 ui16Count;
ui16Checksum = 0;
ptr = (char *) 0;
for(ui16Count = 0; ui16Count < END_OF_PROG_SPACE; ui16Count++)
{
CLRWDT(); // Reset the watchdog
ui16Checksum += *ptr;
ptr++;
}
return(ui16Checksum);
}