Led blinking not working in breadboard

Discussion in 'Embedded Systems and Microcontrollers' started by PY01A0080, Jun 1, 2013.

  1. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    Hi,
    i try the very simple led blinking code with 8051.
    it's working well in Proteus and in a development card for 8051 but not in breadboard.
    can someone explain me the reason please, i don't understand or i don't the see obvious default in my breadboard.

    thank you
     
  2. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Please post the schematic you followed to make the connections on your breadboard.

    Chances are you're missing a connection. Either that, or you put too much voltage into it and destroyed it.

    We need a lot more details before we can really answer your question.

    Regards,
    Matt
     
  3. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    Ok so here is the code:

    Code ( (Unknown Language)):
    1. #include <stdio.h>
    2. #include <reg52.h>
    3.  
    4. sbit led1 = P1^0;
    5. sbit led2 = P1^1;
    6.  
    7. void delay(unsigned int msec)  // Function to provide time delay in msec.
    8. {
    9. int i,j ;
    10. for(i=0;i<msec;i++)
    11. for(j=0;j<1275;j++);
    12. }
    13.  
    14. void main()
    15. {
    16. while(1)
    17. {
    18. if(led1 == 1)
    19. {
    20. led1 = 0;
    21. led2 = 1;
    22. delay(50);
    23. }  
    24.  
    25. else{
    26. led1 = 1;
    27. led2 = 0;
    28. delay(50);
    29. }
    30. }
    31. }
    The proteus diagram is attached.
    With the breadboard i put the:
    +5Vdc to pin(40)
    Ground to pin (20)
    the crystal (11.0592 Mhz) between pins (18) and (19)
    i connected two 33pF to the crystal like in the proteus image.
    and that's all, nothing else.


    Other thing i tried different time delay too.

    it happens nothing.
    Thank you
     
  4. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Is that the exact code you're using?

    In your delay function you forgot a semicolon:

    Code ( (Unknown Language)):
    1. void delay(unsigned int msec)  // Function to provide time delay in msec.
    2. {
    3.    int i,j ;
    4.    for(i=0;i<msec;i++)[B][COLOR=Red];[/COLOR][/B]  [COLOR=Red]<==[/COLOR]
    5.    for(j=0;j<1275;j++);
    6. }
     
  5. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    I think that missing semicolon is correct, it makes a nested loop. Also with the semicolon using two different variables wouldn´t make much sense.

    You are missing the current limiting resistors on those leds, so they might already be toast.
     
  6. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    I tried with resistors for led and it's not working
     
  7. LDC3

    Active Member

    Apr 27, 2013
    920
    160
    Actually, to have a nested loop, the semicolon should be located after the 2nd 'for' statement.

    Code ( (Unknown Language)):
    1. void delay(unsigned int msec)  // Function to provide time delay in msec.
    2. {
    3.    int i,j ;
    4.    for(i=0;i<msec;i++)
    5.    for(j=0;j<1275;j++); [COLOR="Red"];[/COLOR]
    6. }
    7.  
     
  8. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Oops, you're right. I take it one millisecond is 1275 cycles?

    LCD3, you do not want two semicolons on the same row. The OP had it programmed correctly.
     
  9. LDC3

    Active Member

    Apr 27, 2013
    920
    160
    I'm not familiar with the language he is using. Sorry.
     
  10. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    i didn't burn my leds without resistors.
    but ok now i have resistors to protect leds but still there is nothing.
    what could be the problem?
    the circuit is very simple.
     
  11. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    How do you know your LEDs aren't burnt out? Did you test them to make sure?

    Also, check that you have pin 9 connected to ground (it's reset when held high, so you should connect it to ground through a pull-down resistor, if you're using a switch, or directly to ground if you don't want to reset it. Also check that pin 31 is connected to 5v as well.
     
  12. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    I checked leds with my multimeter and they are good.
    i connected the pin 9 directly to ground and the pin 31 to 5V
    as you mentioned but nothing, leds are off and i have :
    5V in pin 40 and 31
    0V at pin 1 and 2 for leds
    5V at pin 18
    1.38V at pin 19

    so is there a problem with my breadboard which is new....
     
  13. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    What do you mean you have "0V at pin 1 and 2 for leds"?

    You should not have 5v at pin 18. Check your ground connections. If you connected ground to 5V and vice versa, you probably fried your chip.
     
  14. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    I mean Led are connected to P1.0 and P1.1 which are pin 1 and 2, there is 0V, leds are off.

    i have 5V at pin18 where one of the crystal's pin is connected.

    i did not connected 5V to the ground
     
  15. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Are you able to light the leds without the delays etc.?
     
  16. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Make sure your chip isn't backwards. Could you please post a photo of your setup?

    Also, how are you loading your code onto the chip?
     
  17. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    please the photo.
    i use a programmer for 8051to load the code in hex file
    but as i said , it's working with the development board.
     
  18. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    This isn't a solution, but I need to ask--what is the purpose of the black wire?
     
  19. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    The black wire is used to connect the ground to the cathode of leds and the pin 9
    tell me if u need more details
     
  20. LDC3

    Active Member

    Apr 27, 2013
    920
    160
    It's hard to tell if the capacitors near the crystal are one on each side of the crystal. Should there also be a resistor with the crystal?
     
Loading...