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.

[SOLVED] Blinking LED simple program

Status
Not open for further replies.

sahu

Advanced Member level 2
Advanced Member level 2
Joined
Oct 9, 2009
Messages
519
Helped
68
Reputation
130
Reaction score
63
Trophy points
1,308
Location
Uttar pradesh (INDIA)
Visit site
Activity points
3,927
Dear All
Plz guied me I need a simple program for LED1 to LED8.

task_1
when S1 unpressed ;

{LED=11111110;}
(HOLD IT for 2sec)

{LED=11111101;}
(HOLD IT for 2sec)

{LED=11111011;}
(HOLD IT for 2sec)

{LED=11110111;}
(HOLD IT for 2sec)


{LED=11101111;}
(HOLD IT for 2sec)
Repeat this function every time till S1 unpressed .

task_2
but when S1 pressed for 1time within 1sec

{LED=11111110;}
(HOLD IT for 20sec)
& ofter 20 sec exit form task_2 & Repeat this function task_1

but when S1 pressed for 2time within 1sec

{LED=11111101;}
(HOLD IT for 20sec)
& ofter 20 sec exit form task_2 & Repeat this function task_1


but when S1 pressed for 3time within 1sec

{LED=11111011;}
(HOLD IT for 20sec)
& ofter 20 sec exit form task_2 & Repeat this function task_1


but when S1 pressed for 4time within 1sec

{LED=11101111;}
(HOLD IT for 20sec)
& ofter 20 sec exit form task_2 & Repeat this function task_1
 

"if / else"solve this issue and update dummy register every switch pressed and copy the dummy valve to LED

Which MCU is using
 


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
32
33
34
35
36
37
38
39
40
41
42
43
44
if(sw_pressed)
{
   count++;
  switch(count)
  {   case 1:   LED=11111110;
                  delay(20sec);
      break ;
     
      case 2:   LED=11111101;
                  delay(20sec);
      break ;  
      case 3:   LED=11111011;
                  delay(20sec);
      break ;
     case 4:   LED=11110111;
                  delay(20sec);
                  count=0;
      break ;
      
 
 
}
 
else
{
     {LED=11111110;}
delay(2sec);
 
{LED=11111101;}
delay(2sec);
 
{LED=11111011;}
delay(2sec);
 
{LED=11110111;}
delay(2sec);
 
 
{LED=11101111;}
delay(2sec);
 
 
 
}

 
  • Like
Reactions: sahu

    sahu

    Points: 2
    Helpful Answer Positive Rating

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
32
33
34
35
36
37
38
39
40
41
42
43
44
if(sw_pressed)
{
   count++;
  switch(count)
  {   case 1:   LED=11111110;
                  delay(20sec);
      break ;
     
      case 2:   LED=11111101;
                  delay(20sec);
      break ;  
      case 3:   LED=11111011;
                  delay(20sec);
      break ;
     case 4:   LED=11110111;
                  delay(20sec);
                  count=0;
      break ;
      
 
 
}
 
else
{
     {LED=11111110;}
delay(2sec);
 
{LED=11111101;}
delay(2sec);
 
{LED=11111011;}
delay(2sec);
 
{LED=11110111;}
delay(2sec);
 
 
{LED=11101111;}
delay(2sec);
 
 
 
}


thank u boooos
 


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
32
33
34
35
36
37
38
39
40
41
42
43
44
if(sw_pressed)
{
   count++;
  switch(count)
  {   case 1:   LED=11111110;
                  delay(20sec);
      break ;
     
      case 2:   LED=11111101;
                  delay(20sec);
      break ;  
      case 3:   LED=11111011;
                  delay(20sec);
      break ;
     case 4:   LED=11110111;
                  delay(20sec);
                  count=0;
      break ;
      
 
 
}
 
else
{
     {LED=11111110;}
delay(2sec);
 
{LED=11111101;}
delay(2sec);
 
{LED=11111011;}
delay(2sec);
 
{LED=11110111;}
delay(2sec);
 
 
{LED=11101111;}
delay(2sec);
 
 
 
}


it have some some problem .
when press sw mcu inter count mode & hold there till delay time .if agen i press sw during hold time mcu not goes next counter mode . it goes when delay time complete there .
whats wrong with me .
 

Use switch as external Interrupt and which delay function you are using?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top