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.

help with mikroC plz

Status
Not open for further replies.

janosandi

Full Member level 4
Joined
Jan 23, 2010
Messages
210
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,788
hello Guys
how can i write this code in mikroC:

if portB.0 = 0 & portB.B1 = 0 & portB.B2 = 0 then do something

Or

if portB.0 = 0 or portB.B1 = 0 or portB.B2 = 0 then do something

& how can i use DO statement to keep in sub function? like

do portc.0 = 1 until portb.b0 = 1

thx for help guys
 

Logical & should looks like this:
Code:
if (portB.B0 == 0 && portB.B1 == 0 && portB.B2 == 0)
{


}
But the correct way is to check does it equal to 0 or not:
Code:
if (!portB.B0 && !portB.B1 && !portB.B2)
Because PORTB.B2 == PORTB & (1<<2) which can be 0 or (1<<2)
 

& how can i use DO statement to keep in sub function? like

do portc.0 = 1 until portb.b0 = 1

do
{
<<your code goes here>>
}while(portb.b0 == 0); // or you could use 'while(!portb.b0);'

Brian.
 
Logical & should looks like this:
Code:
if (portB.B0 == 0 && portB.B1 == 0 && portB.B2 == 0)
{


}
But the correct way is to check does it equal to 0 or not:
Code:
if (!portB.B0 && !portB.B1 && !portB.B2)
Because PORTB.B2 == PORTB & (1<<2) which can be 0 or (1<<2)

what about Or ?
thx for your reply

- - - Updated - - -

do
{
<<your code goes here>>
}while(portb.b0 == 0); // or you could use 'while(!portb.b0);'

Brian.

thx Brian
if im using timer interrupt so how it works with do loop?
is there any priority for the loop or it ignores the interrupt ?
 

if (portB.B0 == 0 || portB.B1 == 0 || portB.B2 == 0) -< OR logic
interrupt is calling interrupt because it interrupts main programm. PIC doesn't support interrupt priorities.
 

if (portB.B0 == 0 || portB.B1 == 0 || portB.B2 == 0) -< OR logic
interrupt is calling interrupt because it interrupts main programm. PIC doesn't support interrupt priorities.

thx for reply but how can i cancel the do loop ? like for emergency stop like:

do {
PORTD = 2;
}
while(PORTB.B1 == 1);
}
i have 3 do loops with three conditions i want to cancel them all when emergency pressed
 

perform 'brake' command
or like this:
Code:
char cnt = 3;
do {
PORTD = 2;
cnt--;
}
while(PORTB.B1 && cnt);
 

perform 'brake' command
or like this:
Code:
char cnt = 3;
do {
PORTD = 2;
cnt--;
}
while(PORTB.B1 && cnt);

thx Mr
you mean by changing cnt later it can cancel the do statement ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top