Continue to Site

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.

  • 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.

Dimming a LED using 8051.

Status
Not open for further replies.

ikelectro

Member
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?
 
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:
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:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top