output to port.fx

General discussion on mikroC.
Post Reply
Author
Message
chipfryer
Posts: 4
Joined: 19 Feb 2011 23:43

output to port.fx

#1 Post by chipfryer » 20 Feb 2011 00:07

Driving me crazy- how do you do this:

if(condition) { PORTA.i = 1; } ELSE { PORTA.i =0; }
i++;

ie I want to loop through each of the pins on portA and turn them on or off depending on the condition which uses data in array

Thanks

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: output to port.fx

#2 Post by tihomir.losic » 22 Feb 2011 11:58

Hello,

the syntax of the if statement is:

Code: Select all

if (expression) statement1 [else statement2]
If expression evaluates to true, statement1 executes. If expression is false, statement2 executes.
The expression must evaluate to an integral value; otherwise, the condition is ill-formed. Parentheses around the expression are mandatory.

The else keyword is optional, but no statements can come between if and else.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

chipfryer
Posts: 4
Joined: 19 Feb 2011 23:43

Re: output to port.fx

#3 Post by chipfryer » 23 Feb 2011 01:43

Thanks but it's not the IF statement I need help with- it is the PORTA command: how to scroll through each pin using the variable i

balazs
Posts: 37
Joined: 20 Mar 2010 14:53

Re: output to port.fx

#4 Post by balazs » 23 Feb 2011 12:35

In the first place if your i++ is in an endless loop your i will be very high in matter of us.
You should write something like this:

Code: Select all

void main(){
int i=0;
while(1){
if(condition)
 { PORTA.i = 1;} 
ELSE
 { PORTA.i =0;}
    i++;
    Delay_ms(500);
    if(i>7)i=0;
}
}
your condition can be a button press for example.
Regards Balazs.

chipfryer
Posts: 4
Joined: 19 Feb 2011 23:43

Re: output to port.fx

#5 Post by chipfryer » 23 Feb 2011 22:33

No the ONLY problem I have is with the PORTA.i line! This does not compile.
I want to change i (using the loop) to scroll through the pins of PORTA. IF's DO's and all other coding is fine.

Thanks.

Post Reply

Return to “mikroC General”