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

assembly code for led

Discussion in '8051/8951' started by Parth86, Dec 19, 2013.

  1. Parth86

    Parth86 Member

    Joined:
    Dec 25, 2011
    Messages:
    546
    Likes:
    5
    I have one switch and one LED. the positive edge of switch is connected to port pin PO.1 and negative edge is connected to port pin PO.2 and LED is connected to output the positive edge of motor is connected to port pin P1.1 and negative edge is connected to P1.2

    if switch is on then LED is on
    if switch is of then LED is of
    I am trying to make assembly code please check out code
    Code (text):
    org    o h
    main:
              jb P0.1,  on
              jb P0.2,  on      ; switch is closed
            jnb P0.1, off       ; switch is open
            jnb P0.2, off
            sjmp main
    ON:
            setb P1.1         ;    led on
              clr  P1.2
            sjmp main
    OFF:
              clr P1.1           ; led off
              clrP1.2
               sjmp main
    end
           
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    That's the code I gave you for the motor!!
    If you have one LED connected to P1.1
    And one switch on P0.1
    Code (asm):

    org    o h
    main:
          jb P0.1,  on      ;   switch is closed
          jnb P0.1, off     ;   switch is open
          sjmp main
    OFF:
          setb P1.1         ;    led off
          sjmp main
    ON:
          clr P1.1           ; led on
          sjmp main
    end
     
    circuit1.PNG
    You need to sink the LED on Port 1 ( not sure if they are open collectors.. )
     
  3. Parth86

    Parth86 Member

    Joined:
    Dec 25, 2011
    Messages:
    546
    Likes:
    5
    let me clear one thing
    the positive edge of LED is connected to port pin P1.1 and negative edge is connected to P1.2
    so why you are using only one pin P1.1 why you are not using P1.2
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK

    Why on earth would you want to use TWO pins to light an LED????

    Some pins on the micro can't supply 5v.... All pins can sink current... the pins on a 8051 can only sink / source less than 10mA.... I think only Port 0 can supply as well as sink...
     
  6. Parth86

    Parth86 Member

    Joined:
    Dec 25, 2011
    Messages:
    546
    Likes:
    5
    it means i need to connect one pin to controller and other pin to ground
     
  7. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
    I can think of one reason why you want to connect both legs of the LED to the 8051. In case someone wants to connect more LEDs to less number of pin on the 8051. In the attached schematic, I can connect 8 LED to 5 I/O pins. With a little more thought, you can connect even more LEDs to the same amount of pins.

    Though I've never tried out whether it would work, this was mentioned in one of the Ap notes in microchips " Bag of Tricks". Only problem is that only 4 LEDs can be switched on at the same time....

    Allen
     

    Attached Files:

  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Hi Allen!! No I don't think the chip is capable of sinking that much current on a single pin...
     
  9. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
    Yep, you're probably right. So this arrangement is only for "one LED at a time" use.

    Cheers to your whisky and Merry Xmas.

    Allen
     

Share This Page