8051 led blink problem

Discussion in 'Embedded Systems and Microcontrollers' started by aashishaac, May 23, 2014.

  1. aashishaac

    Thread Starter New Member

    May 10, 2014
    8
    0
    Hi I am aashish, I am a pure beginner to 8051 microcontrollers and want to Blink a LED with it (as my first test).


    But at the end the LED did not blink :mad::mad:, I performed the following steps,
    1. Generate Hex file from keil uVision
    2. Flash the AT89S52 with this hex file using a 8051 programmer.
    3. Connect a LED to AT89S52 on breadboard to test my work.


    Please have a look at the word document : https://drive.google.com/file/d/0B5NYQC3oiHcHcjh2a3RBOW5famc/edit?usp=sharing to see the detailed steps that I have followed along with the connection of LED to AT89S52 on breadboard to test my work


    So where I was wrong? my program is incorrect/incomplete?? Or Does the AT89S52 not have an on chip clock? Whether I have to connect an external crystal?? Or anything I am missing….??


    Please help me I am in a great need of it. Please help.


    Thanks in advance.
     
  2. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Did you check out Ian Rogers' 8051 tutorial #1 ? He detailed how to blink the LED with ASM and C.

    8051 tutorial 1

    The RST in the schematic you linked was left unconnected. I remember you have to connect that pin to ground in order for it to work.

    Allen
     
  3. Arm_n_Legs

    Active Member

    Mar 7, 2007
    183
    10
    The reset (RST) is not connected. Connect the RST to a 10uF cap. The other end of the cap connect to Vcc.

    I think this IC does not hv an internal oscillator. You may need to connect up the crystal with 2 external caps.
     
  4. Fibonacci

    New Member

    May 23, 2014
    25
    5
    Change to an Arduino IDE. It´s so easy.
     
  5. aashishaac

    Thread Starter New Member

    May 10, 2014
    8
    0
    Thanks all of you for your fruitful replies........

    Can any body please ensure me that whether my program is correct ?

    And please send me a sample LED hookup circuit diagram

    Thanks in advance
     
  6. aashishaac

    Thread Starter New Member

    May 10, 2014
    8
    0
    I changed the circuit to this,
    [​IMG]
    but the same problem persists....LED glows but not blink.

    For a while I thought that if my AT89S52 IC is damaged but if it were it was not and even now get program correctly.

    So what is the matter ? Please help me, I am in a great need of it for my project.
    Thanks in advance
     
  7. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,804
    833
    Where did you get the value of 1275 used in your second for loop? Are you sure that the loop takes 1ms to execute?

    If it's much less, then your delay will be wrong. If it's too short, the LED will appear to be always on, but dimmer. The dimness is caused by a PWM effect resulting in 1/2 power to the LED.

    If you are sure of this value, then I got nothing.
     
  8. aashishaac

    Thread Starter New Member

    May 10, 2014
    8
    0
    Thanks for your reply djsfantas, I am suffering from exactly that you have written : the LED will appear to be always on, but dimmer.

    Actually sir,I am an absolute beginner to 8051/52 and I was mt very first test just after purchasing the IC and its programmer, I a got the 1275 in a tutorial by just goggling AT89S52 led blink.

    I am not sure to this value, please guide me with the suitable value and/or good program to blink led.

    Thanks in advance. Please help me, I am in a great need of it

    Thanks......Waiting for your reply........
     
  9. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    I simulated your hardware and it was working on Proteus. I am not sure if P1.0 is able to source the LED so I connected it as sinking.

    The code I used was from http://www.electro-tech-online.com/articles/basic-8051-tutorial-1.667/

    Code ( (Unknown Language)):
    1. [COLOR=#000000] [/COLOR]
    2. [COLOR=#000000]        org [/COLOR][COLOR=#FF0000]0[/COLOR][COLOR=#000000]   [/COLOR][COLOR=#666666]; Reset vector[/COLOR]
    3. [COLOR=#000000]sjmp [/COLOR][COLOR=#0000FF]Start[/COLOR]
    4. [COLOR=#000000]        org [/COLOR][COLOR=#FF0000]30H[/COLOR][COLOR=#000000]    [/COLOR][COLOR=#666666]; Code starts here[/COLOR]
    5. [COLOR=#0000FF]Start[/COLOR][COLOR=#339933]:[/COLOR]
    6. [COLOR=#000000]    [/COLOR][COLOR=#00007F]setb[/COLOR][COLOR=#000000]    P1[/COLOR][COLOR=#339933].[/COLOR][COLOR=#000000]0    [/COLOR][COLOR=#666666]; Set LED pin ( turn off LED )[/COLOR]
    7. [COLOR=#000000]    acall    delay[/COLOR]
    8. [COLOR=#000000]    clr    P1[/COLOR][COLOR=#339933].[/COLOR][COLOR=#000000]0    [/COLOR][COLOR=#666666]; Clear LED pin ( turn on LED )[/COLOR]
    9. [COLOR=#000000]    acall    delay[/COLOR]
    10. [COLOR=#000000]    sjmp    [/COLOR][COLOR=#0000FF]Start[/COLOR][COLOR=#000000]    [/COLOR][COLOR=#666666]; do it again ( Forever loop )[/COLOR]
    11. [COLOR=#000000]delay[/COLOR][COLOR=#339933]:[/COLOR]
    12. [COLOR=#000000]    [/COLOR][COLOR=#00007F]mov[/COLOR][COLOR=#000000] R2[/COLOR][COLOR=#339933],[/COLOR][COLOR=#000000]#[/COLOR][COLOR=#FF0000]225[/COLOR][COLOR=#000000]   [/COLOR][COLOR=#666666]; 2 clock cycles (call) = 2[/COLOR]
    13. [COLOR=#000000]    [/COLOR][COLOR=#00007F]mov[/COLOR][COLOR=#000000] R1[/COLOR][COLOR=#339933],[/COLOR][COLOR=#000000]#[/COLOR][COLOR=#FF0000]0[/COLOR][COLOR=#000000]   [/COLOR][COLOR=#666666]; 2 clock cycles (loading) = 2[/COLOR]
    14. [COLOR=#000000]    d1[/COLOR][COLOR=#339933]:[/COLOR][COLOR=#000000] djnz R1[/COLOR][COLOR=#339933],[/COLOR][COLOR=#000000]d1   [/COLOR][COLOR=#666666]; 2 * 256 clock cycles *225 = 115200[/COLOR]
    15. [COLOR=#000000]    djnz R2[/COLOR][COLOR=#339933],[/COLOR][COLOR=#000000]d1    [/COLOR][COLOR=#666666]; 2 * 225 clock cycles = 450[/COLOR]
    16. [COLOR=#000000]    [/COLOR][COLOR=#00007F]ret[/COLOR][COLOR=#000000]     [/COLOR][COLOR=#666666]; 2 clock cycles (return) = 2[/COLOR]
    17. [COLOR=#000000]    end[/COLOR]
    Sorry, I dont know how to use 8051 C yet.

    Allen
     
  10. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,804
    833
    One way to check the value is experimental. Try increasing it by a factor of 10. I.e., change it to 12750. Then observe the results and tune the value until the desired time is met.

    I am not familiar with the 8051, but am a programmer. Often the language will have a built in delay function so that you don't have to code your own as you have done? I would check to see if there is such a function available.

    One of the difficulties in using hard coded loops for timing is that it is dependent on the specific type of chip and it's clock speed.
     
  11. aashishaac

    Thread Starter New Member

    May 10, 2014
    8
    0
    thanks for your reply djsfantasi and absf, I don't think that proteus is a good and reliable software, because the hardware and code what I am suffering from is running well in proteus, also with and without crystal, connecting/ not connecting reset circuitry etc has no effect on its simulation ????

    One thing I have to say that I am a regular user of Atmega16, 328 i.e., AVR microcontrollers, and I never got such a problem, it does not require a reset circuitry and has inbuilt clock source so no need of external crystal also, but for 8051 I am getting tired now, but I will never giveup (it is my habit)

    Please guide me more (like a teacher), I really need it

    Thanks in advance........waiting for your fruitful replies
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    A simulator makes certain assumptions about your circuit. These include it has proper power, proper decoupling, proper reset signals, and the like. It also assumes the hardware was built the same as you drew in the simulator.

    My rule of thumb here is "if it can't sim then you can't win." That means if it doesn't work in the simulator it cannot work on the real hardware.

    Note the reverse is not true: a circuit may not correctly simulate but work perfectly fine. This is due to the limits of any simulator.

    Summation: don't give up on the simulator.
     
    absf likes this.
  13. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,804
    833
    I did some research and the examples I found used a much smaller value in the loop for a 1ms delay. Exactly opposite of what I would expect. See this link http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm

    The delay depends on the clock speed and compiler. Some compilers may optimize the loop out of existence, since it's doing nothing.

    The article also describes the process I alluded to, to time a large value, calculate a better value and repeat the test, and then divide to get the specific value.

    First, I would use a very large value for the loop; perhaps 32767 as it's the largest positive integer and see what the delay is by timing with a watch. I would set the delay call to 1000.

    Note that if the optimizer removes the "do nothing" loop, this should have no effect. Then, you may have to insert some operation with the index within the loop.

    If the large value results in a 12second delay (I am making the numbers up in this example), then reduce the value and re-time until it results in an even 10 second delay.

    Since you are calling delay for a 1 second delay, delaying for 10 seconds means that your value is 10 times too large. So divide it by 10 and test again.

    Understand?

    Since your simulator works and the observed behavior is that the delay is not happening, I suspect the compiler. If it turns out that is the case, try my suggestion of inserting an operation within the loop. For example, define an integer k just within the function and in the inner loop, add "k=j-1;". Of course this will also affect your timing value, and you'll have to retune its value.
     
  14. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    One problem may be that the circuit requires the port pin to SOURCE the LED current.

    That and looking at Ch. 27 DC Electrical Characteristics says (as I read it) that it sources squat but does sink up to 26ma.

    Turn the LED around. Connect its anode to +5 through the resistor. Connect the cathode to P0.0 and make '0' = ON.

    Avoid pictorial diagrams as shown in #2. Schematic diagrams like yours in #5 are much better.

    Good luck.
     
    Last edited: Jun 5, 2014
  15. aashishaac

    Thread Starter New Member

    May 10, 2014
    8
    0
    Great thanks for your replies, but even now I could not get the LED blink,

    Try 1 : Mr. djsfantasi I read your link http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm and implemented the

    delay_1s() // timer of 1 sec
    {
    int d;
    for(d=0;d<=20;d++)
    {
    TMOD=0x01;
    TL0=0xFD;
    TH0=0x04B;
    TR0=1; // start timer.
    while(TF0==0); // run until TF turns to 1
    TR0=0; // stop timer
    TF0=0; // reset the flag
    }
    } - See more at: http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm#sthash.knwYMAxT.dpuf
    Code ( (Unknown Language)):
    1.  
    2. delay_1s() // timer of 1 sec
    3. {
    4. int d;
    5. for(d=0;d<=20;d++)
    6. {
    7. TMOD=0x01;
    8. TL0=0xFD;
    9. TH0=0x04B;
    10. TR0=1; // start timer.
    11. while(TF0==0); // run until TF turns to 1
    12. TR0=0; // stop timer
    13. TF0=0; // reset the flag
    14. }
    15. }
    16. delay_1s()                                         // timer of 1 sec
    17. {
    18. int d;
    19.     for(d=0;d<=20;d++)
    20.     {
    21.     TMOD=0x01;
    22.     TL0=0xFD;
    23.     TH0=0x04B;
    24.     TR0=1;                                              // start timer.
    25.     while(TF0==0);                                 // run until TF turns to 1
    26.     TR0=0;                                            // stop timer
    27.     TF0=0;                                           // reset the flag
    28.     }
    29. } - See more at: http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm#sthash.knwYMAxT.dpuf
    30.  
    but the LED does not glow any more.

    Try 2 : Mr. djsfantasi I tried 32767in my for loop but no effect LED dimmer and not flashing, I tried adding "k=j-1;" to the inner for loop but no effect.

    Try 3 : Mr. absf asm code I tried the asm code and the circuit [http://www.electro-tech-online.com/attachments/switch-png.85572/switch.png] [​IMG] from the tutorial, but LED not even lightup.

    Try 4 : Mr. JohnInTX tried sourcing and sinking LED not not helpful.


    I am using Arduino and AVR Atmega microcontrollers but never got such type of problem ????

    Please help me, I am not giving up now because I know that I am making a mistake either in my code,and/or in wiring but....... Huh!

    I know and experienced also ''Try again and again and You will get success at last" .......... but just waiting that successful last.

    Thanks in advance........waiting for your fruitful replies


    delay_1s() // timer of 1 sec
    {
    int d;
    for(d=0;d<=20;d++)
    {
    TMOD=0x01;
    TL0=0xFD;
    TH0=0x04B;
    TR0=1; // start timer.
    while(TF0==0); // run until TF turns to 1
    TR0=0; // stop timer
    TF0=0; // reset the flag
    }
    } - See more at: http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm#sthash.knwYMAxT.dpuf
     
  16. aashishaac

    Thread Starter New Member

    May 10, 2014
    8
    0
    So, have you all stopped replying me .........????????:mad::mad:

    Please don't do this, can anybody take some pain to the needful and experiment by his/her own on AT89S52 on breadboard.

    Please help me.:mad::mad::mad:
     
  17. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Can you attach your compiled HEX file here? So I can try it out on my 8051 SBC? My 8051 SBC is called EMC32 from a Canadian company. It uses external memories.

    Allen
     
  18. manikantaraju2547

    New Member

    Feb 6, 2015
    1
    0
    i too had a similar problem , i did this and it worked. you have tot connect pin number 31 to Vcc. this makes the IC select internal ROM. next also try grounding your reset pin, dont leave it floating. hope this helps
     
Loading...