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 support@ccsinfo.com

Signed int and if statement (basic problem)

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








Signed int and if statement (basic problem)
PostPosted: Thu Feb 25, 2010 12:53 pm     Reply with quote

Hi,

My problem is:

Code:

signed int16 variable;

variable = 6000;

if(variable < 5000)  {
Action
}


Action does not execute because of signed variable. It executes if i add 32767 to a value.
Casting, both on variable and value, does not help.

I do realize that it might be very basic stuff and my lack of experience is the cause of the problem but ...

Why is that ? How can I solve my problem.

Thank you Very Happy
Guest








PostPosted: Thu Feb 25, 2010 1:08 pm     Reply with quote

Action does not execute because it is 6000, which is not less than 5000 as in your "if" statement.
Guest








PostPosted: Thu Feb 25, 2010 1:12 pm     Reply with quote

ahh sorry :S

I meant

Code:
if(variable > 5000)
jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Thu Feb 25, 2010 1:13 pm     Reply with quote

what is it value?, what are you trying to do?
Guest








PostPosted: Thu Feb 25, 2010 1:17 pm     Reply with quote

Value is number 5000 and 6000.

What im trying to do it readable at very first post.
Sorry for bad explanation.
husam



Joined: 17 Feb 2010
Posts: 10
Location: jordan

View user's profile Send private message

PostPosted: Thu Feb 25, 2010 1:27 pm     Reply with quote

try int 32 .. maybe it will work
jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Thu Feb 25, 2010 1:30 pm     Reply with quote

this has worked for me:

Code:

#include <18F4550.h>
#use delay (clock=20000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP

#define red PIN_B5
#define green PIN_A5

signed int16 value = -2;
signed int16 variable = -5;

void main(){

if (variable > value){
   output_low(green);
   delay_ms(500);
   output_high(green);
}
else{
   output_low(red);
   delay_ms(500);
   output_high(red);
}

}


test this with your chip.
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