|
|
View previous topic :: View next topic |
Author |
Message |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
PIC24 adding problems |
Posted: Tue Nov 27, 2012 4:59 am |
|
|
Hi All,
I am trying to change my font code from PIC18 to PIC24. It works fine on a PIC18. CCS v4.124, PIC24FJ256DA210
I have a array that contains my font information that looks like this, (I have only included the part that we need for this example as it is quite long and boring)
Code: |
const unsigned int8 font[] = {
0x00,
0x00,
0x21,0x00,
0x7A,0x00,
0x13,
0x00,
0x04,0x70,0x01,0x00,
0x07,0x83,0x01,0x00,
0x0C,0x96,0x01,0x00,
|
Then we have the following code
Code: |
unsigned int16 info_offset;
int chr_width;
int chr_bytes;
unsigned int16 chr_hight;
unsigned int16 chr_offset;
info_offset = (((unsigned int16)*textptr - 33) * 4) + 8;
chr_width = font[info_offset];
chr_offset = font[info_offset+2];
chr_offset = chr_offset << 8; //test 1
chr_offset = chr_offset + font[info_offset+1]; //test 2
|
So when I step though the code I get 256 at test one which is correct. At test 2 howerver I get 150, which is 0x96. It looks like it is not adding the 2 bytes together, it is just replacing it with the last read value.
If I change the last line of code to
Code: |
chr_offset = chr_offset + 0x96;
|
I get 406 like I expect. I can also do the following and it works fine
Code: |
temp = font[info_offset+1];
chr_offset = chr_offset + temp;
|
What am I doing wrong? This works fine in PIC18 and I did not think I would have any issues with porting this. How wrong I was :(
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Nov 27, 2012 5:12 am |
|
|
I'd try two separate things:
Code: |
chr_offset=make16(font[info_offset+2], font[info_offset+1]);
|
Take advantage of the CCS byte assembly operations.
Or:
Code: |
chr_offset = font[info_offset+2];
chr_offset = chr_offset << 8; //test 1
chr_offset = chr_offset + (unsigned int16)font[info_offset+1]; //test 2
|
I seem to remember this coming up a few weeks ago, with your compiler version not correctly looking 'at' the types of both numbers in such a sum, and since the second value is int8, it uses int8 arithmetic for the sum.
The make16 version should be more efficient, and get rid of the problem. Explicitly casting the second value to int16, should also solve the problem, or just swapping the two values over in the sum.
It is a bug with your compiler version.
Best Wishes |
|
|
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Tue Nov 27, 2012 9:09 pm |
|
|
Thanks Ttelmah, that did it. I actual completely forgot about make16.
Still quite strange that the code worked when compiled for PIC18.
Thanks again. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed Nov 28, 2012 2:22 am |
|
|
Yes, it was specific to PIC24, and a couple of compiler versions. There have been some other oddities with arithmetic on these chips as well.....
Best Wishes |
|
|
|
|
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
|