View previous topic :: View next topic |
Author |
Message |
Bomba
Joined: 09 Dec 2003 Posts: 13
|
IF statament? |
Posted: Sun Jan 25, 2004 2:04 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Sun Jan 25, 2004 4:54 pm |
|
|
What you wrote should work fine. |
|
![](templates/subSilver/images/spacer.gif) |
Bomba
Joined: 09 Dec 2003 Posts: 13
|
#use fixed_io() |
Posted: Mon Jan 26, 2004 11:39 am |
|
|
yes this work well, the proble was using #use fixed_io(). I don't understand how to use this statament.
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
Re: #use fixed_io() |
Posted: Mon Jan 26, 2004 3:54 pm |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
|