|
|
View previous topic :: View next topic |
Author |
Message |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
PIC18 -> PIC24 code issue? |
Posted: Wed Nov 09, 2016 7:07 pm |
|
|
Dear CCS fanatic
I am having a strange bug with the SHT21 driver code (exactly the same as here ---> https://www.ccsinfo.com/forum/viewtopic.php?p=205819#205819) running on the 24FJ128GA010.
The same driver and main program on the PIC18F26K80 work perfect. (Under testing for 2 weeks)
Code: |
#include <24FJ128GA010.h>
#FUSES XT,PR_PLL,NOPROTECT,NOJTAG,NOWDT,NOOSCIO
#use delay(clock=32M)
#build (STACK=512)
#use rs232(baud=9600,UART1,ERRORS)
#use i2c(Master,fast,i2c1)
#include "sht21.c"
void main()
{
delay_ms(1000);
sht21_init();
while(true)
{
sht21_both(tent_temp,tent_hum);
printf("#:%3.2f,%3.2f*\n\r",tent_temp,tent_hum);
delay_ms(2000);
}
} |
When it reach a certain humidity range (55%+) it turns NEGATIVE and erroneous. I've tested 4 sht21 modules it work fine on the PIC18.
Is there something that I missed in the PIC24 that would make it act funny , (default int size?)?
_________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 09, 2016 8:44 pm |
|
|
In PCH, int8 and int16 are unsigned integers by default. In PCD, they are
signed by default. That's undoubtedly causing the problem.
Fix the problem by editing the driver for PCD. Everywhere it has int8 or
int16, change it to:
unsigned int8 variable_name;
and
unsigned int16 variable_name; |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Thu Nov 10, 2016 3:21 pm |
|
|
PCM programmer wrote: | In PCH, int8 and int16 are unsigned integers by default. In PCD, they are
signed by default. That's undoubtedly causing the problem.
Fix the problem by editing the driver for PCD. Everywhere it has int8 or
int16, change it to:
unsigned int8 variable_name;
and
unsigned int16 variable_name; |
Bingo!
Curious... is there a logic reason why they don't keep the same standard between PCH and PCD ? _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri Nov 11, 2016 3:01 am |
|
|
ELCouz wrote: | Curious... is there a logic reason why they don't keep the same standard between PCH and PCD ? |
Because PCH was a non-standard oddity in many ways, especially types. I mean int is eight bit, and unsigned? What's that about? We do know what that is really about - it makes sense considering the hardware environment - but for programmers coming from a PC environment it makes little sense and is a big culture shock creating loads of pitfalls. Maybe PCD simply allowed an opportunity to implement a more "conventional" compiler.
To be honest we simply don't know, but PCM/H are certainly quirky, to say the least. PCD is that bit more "ordinary". |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Nov 11, 2016 4:47 am |
|
|
CCS elected to keep to the original wording in K&R. They say here that the default 'int' should be the native type for the processor.
This was common in the early compilers, so you had ones that had (for instance) a 12bit native int (even some really strange sizes like 11bit on one computer I met).
So CCS made the default int for the PIC12, 16 & 18, 8bit.
Not actually that strange, except in that more and more chips were using 16bit as their native type, as things moved on....
The PIC24/30 are 16bit chips, and their native type is signed. So CCS switched for these.
When ANSI launched, the committee decided that the 'costs' of using non standard sizes, were more than the efficiency downsides, so a standard was decided. If you select ANSI, the default CCS sizes are then common between the chips, with the compiler then switching to signed 16bit as the default int. |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
|
|
|
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
|