Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

led blink program

Status
Not open for further replies.

sahu

Member
I have to make a very simple program for led blinking .
Using buttons 1 and 6 lead me.When the button is pressed for a small time , then Led 1 should
be blinking.
This code is part 2 of the LED blink.
part 1- Lead 5 & 6
part 2- LED 1,2,3 & 4 blinking with batton scan
As long as the button is not pressed until the LED blinks 5-6

But when the button is pressed more then 2 sec & unpressed,led1 blink 12sec . ofter 12 sec part
1 agen run.
But when the button is agen pressed more then 10 sec & unpressed during 12 sec of led1 blinking
.led 1 off & led2 blinking 15 sec ,
But when the button is agen pressed more then 2 sec & unpressed,during 15 sec led3 blink & led2 off.
But when the button is agen pressed more then 2 sec & unpressed,during 15 sec led4 blink & led3 off.
now when the button is agen pressed more then 2 sec & unpressed part 1 agen run.
i has try but not get sessss


C:
if(RA4 ==0)
     {  led1 = 1;
     led2 = 0;
     led3 = 0;
       led4=0;
   //   tcnt++;
   
   tcnt=tcnt+1;
 
   if(tcnt == 2)
   {   sp++;
     if(sp>=1 )
      {  led1 = 0;
     led2 = 1;
     led3 = 0;
       led4=0;
     //tcnt=tcnt+1;
     }
 
if(sp==3 )  {led1 = 0;
     led2 = 0;
     led3 = 1;
       led4=0;
     //tcnt=tcnt+1;
   }
   tcnt =0;sp=0;
     }


if(RA4 =1)
{ led5=~led5;
led6=~led6;}
 
Last edited by a moderator:
Do you have any debounce code on it? and can you please use code tags I REALLY hate code not in a tidy box!
 
I think maybe that is why you have problems but I cant be sure. Look up debounce methods
 
There are hundreds of debounce examples online. Including my own, which detects various length presses. It works for a short press and a long press, but can easily be modified to any number of periods.
 
Pl give it me

We are not here to give you code and do your homework for you.

Also, please write in full, English sentences with correct spelling. I can understand the language barrier but I can barely understand you. Use a translator if you're having trouble. https://translate.google.com/
 
I'm kinda vexed here!!!

The last project you were doing was a complex power switching circuit with complex C code!!
Do I take it you didn't understand that code atall????

I thought that you were VERY conversant with C!!
 
I'm kinda vexed here!!!

The last project you were doing was a complex power switching circuit with complex C code!!
Do I take it you didn't understand that code atall????

I thought that you were VERY conversant with C!!

I expect a majority of that code was simply copy and paste.

EDIT: Ian Rogers which thread was that in?
 
Whoops! Another user!! Shivu... Nearly the same...
Caught me out as well so I had to scrub alot of my reply :D, but yes if he does a little bit of reading I would help.
 
now i get that
C:
#define start porta.b0
#define led1  portb.b0
#define led2  portb.b1
#define led3  portb.b2
#define led4  portb.b3
int x0,x1,x2,x3;

void main() {
porta=0x00;
portb=0xff;
trisa=0xff;
trisb=0x00;
x0=1;x1=0;x2=0;x3=0;



while(1){


if((start==1)&&(x0==1)){
delay_ms(200);
x0=0;x1=1;led4=1;led1=0;
}

if((start==1)&&(x1==1)){
delay_ms(200);
x1=0;
delay_ms(200);
x2=1;led1=1;led2=0;
}

if((start==1)&&(x2==1)){
delay_ms(200);
x2=0;
delay_ms(200);
x3=1;led2=1;led3=0;
}
 
Last edited by a moderator:
I think maybe that is why you have problems but I cant be sure. Look up debounce methods
I think you can rule out switch bounce for most of the code. I say this because if you have to press the switch as per OP "button is pressed more then 2 sec" then I would assume the bounce would have settled long before the switch is released, sorta built in debounce. Copy?
 
I think you can rule out switch bounce for most of the code. I say this because if you have to press the switch as per OP "button is pressed more then 2 sec" then I would assume the bounce would have settled long before the switch is released, sorta built in debounce. Copy?
Even if its pressed for 2 seconds that wont stop the bounce, also I doubt he is pressing this long, it seemed strange to mention lengh of press unless you have been told about bounce?

You could be right but either way he is going to need a debounce in there, information is scant as normal :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top