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.

push button project using micro pro to control 2led light in 3mode

Status
Not open for further replies.

confidence

Newbie level 3
Joined
Jul 28, 2018
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
41
push botton project using mikroc pro to control 2led light in 3mode

good day everyone
pls can anyone help me out, i am working on a project with mikroc pro dat uses one push botton to control two led such that the initial state of both led is off,
when d botton is press ones, one led comes on.
when the button is pressed d second time, the second comes on
when pressed for the last time, both go off
 

Re: push botton project using mikroc pro to control 2led light in 3mode

Hi,

No question?
No problem?
Don't expect anybody does your job for free.

Please elaborate your post.

Write your ideas.
Post your flow chart, even a hand made is good.
Post your code.
Post how you tested your code.
Post your expectations and what you see instead.
What and how did you try to find the source of the problem? What are the results?

Klaus
 

Push button project using Mikroc pro to control 2 led light in 3 mode

am working on a design with mikroc that switches 2 led in 3 mode;10,01and 00 wit a push button.
but d code i write is only giving me on and off. i really dont knw the right command to use...here is the code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
anselc=0;
anseld=0;
trisd_bit=0;
trisc_bit=1;
portd.rd0=0;
portd.rd1=0;
 
//switch on only d0
if(portc.rc0==0){
 
portd.rd0=1;
portd.rd1=0;}
 
//on second press switch on only d1
 
if(portc.rc0==0){
 
portd.rd0=0;
portd.rd1=1;}
 
 
//on third press switch off both d0 and d1
 
if(portc.rc0==0){
 
portd.rd0=0;
portd.rd1=0;}
 
while(1);
}
}

 
Last edited by a moderator:

Re: Push button project using Mikroc pro to control 2 led light in 3 mode

You have nothing in loop and no interrupts used. It is too earlier to call this 'design'
 

Re: Push button project using Mikroc pro to control 2 led light in 3 mode

can u pls me with how to go about it
 

Re: push botton project using mikroc pro to control 2led light in 3mode

Start simpler - just get a single LED to flash at the rate you want (e.g. 1 second on and 1 second off). Getting started with your first program can be quite a learning curve.
There are a number of tutorials available but make sure that you select one that relates to your particular device (or family).
Once you have that working, then you can expand it to do what you want. As part of that later step, read up on finite state machines - while the concept might be a bit strange at first (start with pencil and paper - always a good place to start) it wil do what you want and, again, can be expanded up to some seriously advanced programming if necessary.
Susan
 
  • Like
Reactions: burai

    burai

    Points: 2
    Helpful Answer Positive Rating
Re: push botton project using mikroc pro to control 2led light in 3mode

Try this code.

Code:
void main() {
	ANSELC = 0x00;
	ANSELD = 0x00;

	TRISD = 0x00;
	TRISC = 0x01;

	PORTD = 0x00;

	while(1) { 
		
		if(PORTC.F0 == 0) { 
			Delay_ms(50);
			if(PORTC.F0 == 0) {
				if(++counter >= 3) {
					counter = 0;
				}
			}	
		} 
		 
		if(counter == 1) { 
			PORTD = 0x01;
		}		
		else if(counter == 2) { 
			PORTD = 0x02;
		}
		else if(counter == 0) {
			PORTD = 0x00;
		} 
	}
}
 

Re: push botton project using mikroc pro to control 2led light in 3mode

Debounce function - O.K.
Edge detection (key pressed anew) - missing
 

Re: push botton project using mikroc pro to control 2led light in 3mode

@FvM

In which code ?
 

Re: push botton project using mikroc pro to control 2led light in 3mode

Think about what happens when the button is released or continuously held down. I think you want to detect a transition (an edge) on PORTC.F0 rather than just it's logic state.

Hint: read it, store it, compare it with what you read next time, that way you can see if the logic state changed over time.

Brian.
 

Re: push botton project using mikroc pro to control 2led light in 3mode

I fixed it. It was a mistake as it was done { in a hurry.

Code:
void main() {
	ANSELC = 0x00;
	ANSELD = 0x00;

	TRISD = 0x00;
	TRISC = 0x01;

	PORTD = 0x00;

	while(1) { 
		
		if(PORTC.F0 == 0) { 
			Delay_ms(50);
			while(PORTC.F0 == 0);
				if(++counter >= 3) {
					counter = 0;
				}				
		} 
		 
		if(counter == 1) { 
			PORTD = 0x01;
		}		
		else if(counter == 2) { 
			PORTD = 0x02;
		}
		else if(counter == 0) {
			PORTD = 0x00;
		} 
	}
}
 

Re: push botton project using mikroc pro to control 2led light in 3mode

Better but not perfect. If button release involves bouncing, you'll get double counts.
 

Re: push botton project using mikroc pro to control 2led light in 3mode

Also which MCU are you using?
The above code will not work in may devices that use the older style of analog/digital selection register (i.e. ADCON1 or ANSx or ADxPCFGL vs ANSELx).
Also knowing which device you are using means we can suggest better ways if debouncing (and other operations) depending on what capabilities are built in.
Susan
 

using 2 push bottons to control 2led

am try to using 2 push botton to control a single led with mikroc such that when the button 1 is pressed ones, it on the first led for a time delay of 1s...when the button is pressed again for a debounced tym of 1s, it switches on d led 2 for a tym delay of 2s....same operation i need for d 2 push button, performing same operation on d led without any interuption.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top