Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with" if Condition" in C language

Status
Not open for further replies.
Question about if condition in" C" language

Hi guys,
Can we call a function in condition of if in another function?
for example
MemRead1 is first function,TX_byte is second
Code:
unsigned int MemRead1(unsigned char SlaveAddress,unsigned char command1)
{
  //some statements
...
...
if(TX_byte(SlaveAddress)){
do sth;
}
do sth
...
...
}
I hope ,I had a good explanation of my question.
Thanks in advance.;-)
 

Re: Question about if condition in" C" language

are you talking about
if(TX_byte(SlaveAddress))
If TX_byte(SlaveAddress) returns some value like 0 or 1 and if the value is 1 i.e., true then the if condition is executed.
 
Re: Question about if condition in" C" language

Yes you can call a second function within the first function. Make sure the second function to be called is written above the first function. Or make sure that you've declared the functions at the beginning of your code.
 
Re: Question about if condition in" C" language

I have declared function at the beginning of codes but i think second function doesn't return any thing.
 

Re: Question about if condition in" C" language

By "doesn't return any thing", do you mean that you get a zero as the result? Or that it's not a function, but a procedure?
 

Re: Question about if condition in" C" language

I did not get result in simulation,so I test program by toggle a pin of port
like this :
Code:
if (TX_byte(Slaveaddress)){
PORTD.0=~PORTD.0;
goto repeat;
}
but i didn't see any thing in oscilloscope of Proteus
 

Re: Question about if condition in" C" language

Post the code for the function TX_byte. And mention the value of Slaveaddress.
 

Re: Question about if condition in" C" language

Code:
unsigned char Tx_byte(unsigned char Tx_buffer)
{
 unsigned char Bit_counter;
unsigned char Ack_bit;
unsigned char bit_out;
for(Bit_counter=8;Bit_counter>=1;Bit_counter--)
{
if(Tx_buffer&0x80==1)
bit_out=1;
else
bit_out=0;
send_bit(bit_out);
Tx_buffer<<=1;
}
Ack_bit=Receive_bit();
return Ack_bit;
}
SlaveAddress=0x5A;send_bit(),Receive_bit() are function
 

Re: Question about if condition in" C" language

Hi fizo741,

the condition

if(Tx_buffer&0x80==1)

will be always false. I guess that what you meant is

if(Tx_buffer&0x80==0x80)

or simply

if(Tx_buffer&0x80)

Regards

Z
 
Re: Question about if condition in" C" language

Hi my friends,
Thanks for your guides,
actually it is an example program i want to use,in TX_byte() function i want to send one time SlaveAddress,SlaveAddress is 8 bit as i said before 0x5A, and Msb should send first and then other bits.It is like sending 8 bits one by one.
I've corrected my program,but again i do not see any thing in oscilloscope at proteus.
when i debuged, i had this error:
[coff]Could not load source file!
I do not know why?!Do you have any idea:idea:
Do you think it's because of goto:?:
 
Last edited:

Re: Question about if condition in" C" language

You can "dry run" the code.

What are the functions send_bit() and Receive_bit() ? Are they library functions? If so, what do they do? If no, then can you post the code for these functions?
 

Tahmid ,Have you read codes?I didn't understand what do you mean by "dry run" code:!:
 

Nobody help me:cry:

I just want to understand where is the problem?
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top