CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Data transformation problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Data transformation problem
PostPosted: Fri Jul 05, 2013 11:26 am     Reply with quote

Hi! I'm using MPlab v8.91, ccs v 4.134 and mdd stack v2012-06-22. In the beginning I thought I have problem with the port direction but it seems to be a data format problem. I don't know why but when I load the mdd stack it starts to add sign to usually unsigned variables. For example:
Code:

char dataBuff[10];

dataBuff[0]=0;
if(input(PIN..)) dataBuff[0]+=10;
if(input(PIN..)) dataBuff[0]+=50;

and after that I have -60 into dataBuff[0] which disturbs my program.
I tried to use unsigned char - no effect!
How can I fix this? How can I remove the sign?
Thanks!
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 05, 2013 11:32 am     Reply with quote

silly question but how are you reading/displaying the data?
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri Jul 05, 2013 12:07 pm     Reply with quote

I'm using simple add function to read the data :
Code:

char data=0;
if(input(PIN1)) data+=1;
if(input(PIN2)) data+=2;
if(input(PIN3)) data+=4;

This is because I'm not using port, but single pins.
I'm displaying data this way:
Code:

if(data>=128)
{
     output_high(PIN1);
     data-=128;
}
else
{
     output_low(PIN1);
}

if(data>=64)
{
     output_high(PIN1);
     data-=64;
}
else
{
     output_low(PIN1);
}


The problem is when data is <0 this function doesn't works.
May be I should add a second function in case data<0?!
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Jul 10, 2013 12:37 pm     Reply with quote

You do realise that an unsigned value can never be <0....
Characters are unsigned by default.
In CCS, all integers default to unsigned.

The defaults can be changed by a #type statement.
The MDD stack is Microchip code, and this, uses signed as the default for many types, so there will be a type statement setting this up.

You should switch to being explicit about your types. Load stdint.h, and use int8_t for a signed int8, and uint8_t for unsigned etc..

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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