View previous topic :: View next topic |
Author |
Message |
yossihagag1978
Joined: 04 Apr 2013 Posts: 20
|
checksum calculation as shown in mplabx |
Posted: Sun Dec 08, 2024 8:17 am |
|
|
Hi
I am trying to calculate the checksum as shown in mplabx with 2 diffrenet pic's
One 18lf46k22 ant the other is 16lf1789. I am using Pcm compiler v5.008
With 18lf46k22 I succeeded (I attached the code below).
With 16lf1789 I did not success and don’t know why !!!!
Pic 18lf46k22 checksum ad shown in mplabx calculation Working :
int16 calc_pic_18_ checksum ()
{
int16, temp, Checksum;
int32, address;
For (address=0 ; address <getenv("Program_memory"); address+=2 )
{ temp= read_program_eeprom(address);
Checksum += (int8) temp ;
Checksum += (int8) (temp>>8) ;
}
For (address=0x300000 ; address <0x30000D; address+=2 )
{ temp= read_program_eeprom(address);
Checksum += (int8) temp ;
Checksum += (int8) (temp>>8) ;
}
return (Checksum);
}
Pic 16lf1789 checksum ad shown in mplabx calculation Not Working :
Using Pcm compiler v5.008
int16 calc_pic_16_ checksum ()
{
int16, temp, Checksum, temp1, temp2;
int32, address;
For (address=0 ; address <getenv("Program_memory"); address++ )
{
read_program_memory (address,&temp,2);
Checksum += temp ;
}
read_program_memory (0x8007,&temp1,2);
read_program_memory (0x8008,&temp2,2);
Checksum += temp1 ;
Checksum += temp2 ;
return (Checksum);
} |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Sun Dec 08, 2024 9:08 am |
|
|
Why are you not calculating it the same way??????
The PIC16 has 14bit data. I assume you have to do the same as for
the PIC18, and sum the LSB then the MSB, not perform a 16bit addition. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9251 Location: Greensville,Ontario
|
|
Posted: Sun Dec 08, 2024 4:26 pm |
|
|
I wondered about the calculations but at +3*C here, decided to remove the sheet of ice in the driveway......
It'd also be interesting to see WHAT the checksum values are !
Seeing those might show what's wrong... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Mon Dec 09, 2024 10:51 am |
|
|
The MPLAB description says it is a sum of the bytes. Not a sum of the words,
which is what is being done on the PIC16 version...... |
|
|
|