View previous topic :: View next topic |
Author |
Message |
Guest
|
Signed int and if statement (basic problem) |
Posted: Thu Feb 25, 2010 12:53 pm |
|
|
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 |
|
|
Guest
|
|
Posted: Thu Feb 25, 2010 1:08 pm |
|
|
Action does not execute because it is 6000, which is not less than 5000 as in your "if" statement. |
|
|
Guest
|
|
Posted: Thu Feb 25, 2010 1:12 pm |
|
|
ahh sorry :S
I meant
Code: | if(variable > 5000) |
|
|
|
jaimechacoff
Joined: 14 Feb 2010 Posts: 24 Location: Santiago, Chile
|
|
Posted: Thu Feb 25, 2010 1:13 pm |
|
|
what is it value?, what are you trying to do? |
|
|
Guest
|
|
Posted: Thu Feb 25, 2010 1:17 pm |
|
|
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
|
|
Posted: Thu Feb 25, 2010 1:27 pm |
|
|
try int 32 .. maybe it will work |
|
|
jaimechacoff
Joined: 14 Feb 2010 Posts: 24 Location: Santiago, Chile
|
|
Posted: Thu Feb 25, 2010 1:30 pm |
|
|
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. |
|
|
|