1. 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.
    Dismiss Notice

8051 led blink problem

Discussion in '8051/8951' started by aashishelectrotech, Jun 8, 2014.

  1. aashishelectrotech

    aashishelectrotech New Member

    Joined:
    Jun 8, 2014
    Messages:
    1
    Likes:
    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 blin, LED glows continuously and dimmer.

    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. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
  3. Jon Wilder

    Jon Wilder Active Member

    Joined:
    Oct 22, 2010
    Messages:
    865
    Likes:
    82
    Location:
    Fresno, CA
    First off...you're schematic shows the port pin sourcing LED current. 8051 pins cannot source that kind of current. They can, however, sink it.

    Connect the cathode end of the LED (i.e. the minus end - ) to pin P1.0. Then connect a resistor to the anode of the LED (i.e. the +) end. Connect the opposite end of the resistor to +5V.

    Then, if you're coding in C, this function should do it -

    Code (text):


    void main(void)
    {
            P1 = 0b00000001;
            while(1)
            {
                    for(int i = 0; i < 50,000; i++);
                    P1 = P1 ^ 0b00000001;
            }
    }
     
    If you're coding in assembly -

    Code (text):


            org    0x0000            ;reset vector  
            ajmp    START

    ;space reserved for interrupt vectors

            org    0x0100
    START:        mov    P1, #00h
    MAIN:        xrl    P1,#0b00000001        ;toggle LED
                        mov    R1, #FFh        ;delay loop
                        mov    R0, #FFh
    LOOP1:       djnz    R1, LOOP1
                        djnz    R2, LOOP1
                        ajmp    MAIN            ;loop to main

     
     
    Last edited: Jul 2, 2014

Share This Page