View previous topic :: View next topic |
Author |
Message |
DerWolf
Joined: 30 Jan 2010 Posts: 8
|
PIC24FV32KA304 |
Posted: Mon Jan 20, 2014 4:46 pm |
|
|
Hello,
i do have a other point switching from a PIC 18 to a PIC24. I know that the PIC24 is 16bit and the PIC18 is 8 bit. But i would have expected that a int8 is still read as a 8bit variable but it seems not. Is this correct?
I just wrote a simple dummy:
Code: |
int8 response;
printf("response = 170;\n\r");
response = 170;
if (response == 170)
printf("170 OK\n\r");
if (response == 0xAA)
printf("AA OK\n\r");
if (response == 0xFFAA)
printf("FFAA OK\n\r");
if (response == -86)
printf("-86 OK\n\r");
printf("response = 0xAA;\n\r");
response = 0xAA;
if (response == 170)
printf("170 OK\n\r");
if (response == 0xAA)
printf("AA OK\n\r");
if (response == 0xFFAA)
printf("FFAA OK\n\r");
if (response == -86)
printf("-86 OK\n\r"); |
and the result is:
response = 170;
FFAA OK
-86 OK
response = 0xAA;
FFAA OK
-86 OK |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 20, 2014 5:08 pm |
|
|
The PCD and PCM/PCH manuals for June 2012 say:
PCD:
Quote: | Note: All types, except char, by default are signed; however, [they] may be preceded by unsigned or signed (Except int64 may only be signed). |
PCM/PCH:
Quote: | unsigned - Data is always positive. This is the default data type if not specified |
|
|
|
DerWolf
Joined: 30 Jan 2010 Posts: 8
|
|
Posted: Mon Jan 20, 2014 5:39 pm |
|
|
but if i change the declaration of response to short it is reacting in the same way even it is now defined as unsigned.
regards
A. Wolf |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 20, 2014 5:54 pm |
|
|
I don't have the PCD compiler, so I can't run any tests.
There is a problem. CCS changed the latest PCD manual. They appear
to have copied and pasted the "Basic and Special Types" section from
the PCW (PCM/PCH) manual into the PCD manual.
For example, in both of the current Nov. 2013 manuals, CCS
claims that a 'short' is an 'int1'.
But in the June 2012 manuals, the PCD version says a 'short' is an 'int8'.
The PCW manual says it's an 'int1'. That's the way it was and the way
it worked, for a long time.
So I don't know if CCS has done a major change to PCD, or if it's just a
mistake due to laziness in the manual preparation. I can't help anymore
on this thread because I don't have PCD, so I'm going to quit responding. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Jan 21, 2014 2:09 am |
|
|
If you want to be compatible with PIC18 code, you need to use the TYPE statement, and force the use of unsigned by default.
Personally I've got into the habit of including 'stdint.h', and using uint8 in any code I want to be portable between the chips. Much easier....
Best Wishes |
|
|
|