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

Dimming a LED using 8051.

Discussion in '8051/8951' started by ikelectro, Oct 1, 2014.

  1. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    I want to make a LED glow slowly. But haven't succeed yet. I learn only these command still now over one and half month : mov, add, clr, setb, djnz, lcall, cjne, rr, rl, swap, jnb, jb, ret, nop, jmp, sjmp, jz, jnz. So, is it possible to make a led dimmer with with these instruction?
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    I think that is most of them...

    The two you need are SETB and CLR.... these turn off / on an LED connected ( via a transistor ) to a micro pin..

    you then place the code in a forever loop with a variable delay between these two commands

    Code (asm):

    var1   equ   250     ; on time
    var2   equ   50     ; off time

    loop:
       mov   R0, #var1
       setb   P0.0
    on:
       djnz   R0, on     ; wait here for on time
       mov   R0, #var2
       clr    P0.0
    off:
       djnz   R0, off    ; wait here for off time
       jmp   loop

    end
     
    Something like this... To make the LED come on slowly... Increase var2 while decreasing var1..
     
    Last edited: Oct 2, 2014
    • Like Like x 2
  3. dengxinjun

    dengxinjun New Member

    Joined:
    Oct 5, 2014
    Messages:
    8
    Likes:
    0
    Why not use the C language to write? So convenient point
     

Share This Page