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

IF statament?

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



Joined: 09 Dec 2003
Posts: 13

View user's profile Send private message

IF statament?
PostPosted: Sun Jan 25, 2004 2:04 pm     Reply with quote

Only can evaluate a single expresion into the if statament, or i can to write this:

if ((0b0010==Sec.entero)||(0b0100==Sec.entero)||
(0b1101==Sec.entero)||(0b1011==Sec.entero))
output_high(Led1);

Thanks in advance
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sun Jan 25, 2004 4:54 pm     Reply with quote

What you wrote should work fine.
Bomba



Joined: 09 Dec 2003
Posts: 13

View user's profile Send private message

#use fixed_io()
PostPosted: Mon Jan 26, 2004 11:39 am     Reply with quote

yes this work well, the proble was using #use fixed_io(). I don't understand how to use this statament.

Thanks
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

Re: #use fixed_io()
PostPosted: Mon Jan 26, 2004 3:54 pm     Reply with quote

Bomba wrote:
yes this work well, the proble was using #use fixed_io(). I don't understand how to use this statament.

Thanks


From the manual:
Quote:

Syntax:
#use fixed_io (port_outputs=pin, pin?)

Elements:
port is A-G, pin is one of the pin constants defined in the devices .h file.

Purpose:
This directive affects how the compiler will generate code for input and output instructions that follow. This directive takes effect until another #use xxx_IO directive is encountered. The fixed method of doing I/O will cause the compiler to generate code to make an I/O pin either input or output every time it is used. The pins are programmed according to the information in this directive (not the operations actually performed). This saves a byte of RAM used in standard I/O.

Examples:
#use fixed_io(a_outputs=PIN_A2, PIN_A3)

Also See:
#use fast_io, #use standard_io



So if you have a line

#use fixed_io(c_output=PIN_C0, PIN_C1, PIN_C2, PIN_C3)

in your code (typically at the of your C module or in your header file) then the compiler will create the appropriate TRIS statements to make pins C0..C3 outputs and pins C4..C7 will be inputs. Those pins will stay that way until you re-issue the #use fixed_io, #use fast_io or #use standard_io, write your own set_tris_xxx statement or in some cases the built in compiler functions can override pin directions.

Personally I use #use fast_io() and set_tris_xxx() instead of #use fast_io().

Also, I don't know if it makes a difference with the CCS compiler but if I am mapping a port to a variable and then using that variable in an "if" statement I typically write it as

if ((my_mapped_port & 0b00001111) == 0b00001001) {
// do something here
}

This example line is masking off the upper four bits of the mapped port and then comparing the result to 0b00001001 so I am looking for a 1 on input 0 and input 3 at the same time.

You have done two things that may be confusing the compiler, first you have your constant value listed first (shouldn't matter but I can't recall ever seeing code done this way or trying it myself) and you aren't fully specifying the values to the full precision of the variable. In theory the compiler shouldn't care and should promote the constants to the appropriate data type for the comparison but you never know.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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