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.

[PIC] How to pause a LED while executing other line

Status
Not open for further replies.

VoltVolt

Junior Member level 1
Junior Member level 1
Joined
Sep 15, 2013
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
124
Hi,
I'm using PIC16F877A with HITECH C
What I'm try to do is to make my LED on while I can execute the next line instruction.

Scenario:
first program(check resistance to determine the LED on or not)
LED blink

second program

What I want is to execute the second program while checking the resistance to determine the LED on or not...

Part of my code:

resistance = (100000 * voltage) / (5 - voltage);

void main1(){
if (resistance <= 50000) {
RD0 = 1;
DelayMs(1000);
} else if (resistance >= 50000) {
RD1 = 1;
DelayMs(1000);
}
}

void main2(){}

void main(void){
main1();
main2();
}

I appreciate if anyone could help... Thx...
 

I presume the LED is controlled by the uC.

It is not clear what you want to happen. The LED turns OFF when the 'next' line of code is finished? You want the LED to blink as it executes a line of code?

What is RD0? RD1?

main1 and main2 are terrible names to use - make the names representative of what they are doing

Why check resistance? You should have a global variable or function that says whether the LED is on or off.
 

I presume the LED is controlled by the uC.

It is not clear what you want to happen. The LED turns OFF when the 'next' line of code is finished? You want the LED to blink as it executes a line of code?

What is RD0? RD1?

main1 and main2 are terrible names to use - make the names representative of what they are doing

Why check resistance? You should have a global variable or function that says whether the LED is on or off.

What I actually want is make the LED on while I can still able execute other functions.

RD0 and DD1 are the ports that connected to both LED... Which LED on is determine by the resistance measured...

My tasks is to check the resistance and judge which LED to turn on...
 

What I actually want is make the LED on while I can still able execute other functions.

RD0 and DD1 are the ports that connected to both LED... Which LED on is determine by the resistance measured...

My tasks is to check the resistance and judge which LED to turn on...

Hi,

As i understand from your explanation :

You want to measure a resistance and Turn on appropriate LED. (For Example : RD0) , while you are measuring it again (and determine which LED you want to turn on), you want RD0 stays ON. correct?

if it's that your problem , actually there is no problem. In microcontrollers when you use a port ( or only a pin of a port) as output and write a value to it, it will hold that value unless you change it.

so your routine will be like this :

1) measure resistance
2) Turn on appropriate LED for example RD0 : RD0=1
3) Wait for another measurement (RD0 is 1)
4) measure resistance again ( RD0 is still 1)
5) Turn on appropriate LED , this time for Example RD1 : RD0=0 (turn RD0 OFF) , RD1=1 (Turn RD1 ON)

hope it helps,
Good Luck!
 

maybe I didnt have enough coffee this morning



RD0, RD1 = 0
Loop
1) wait to measure resistance
2) measure resistance
3) Turn on appropriate LED, turn off other LED



BTW in your original code, for the second if, it would never be 50,000 as the first if is <= 50,000.
Code:
if (resistance <= 50000) {
RD0 = 1;
DelayMs(1000);
} else if (resistance >= 50000) {
RD1 = 1;
DelayMs(1000);
}

so, it should be..............
Code:
if (resistance <= 50000) {
RD0 = 1; RD1 = 0;
} else {
RD0 = 0; RD1 = 1;
}
DelayMs(1000);


or
Code:
RD0 = 0; RD1 = 0;
if (resistance <= 50000) {
RD0 = 1; 
} else {
RD1 = 1;
}
DelayMs(1000);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top