free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
namita
Mon May 12 2008, 09:12PM
 User Offline
Registered Member #7804
Joined: Mon May 12 2008, 09:00PM

Posts: 3
Thanked 0 times in 0 posts
hi everyone. i am working on a project RGB lighting system.
i have an LED array, LED driver(transistor), PWM generator and logic for color sequence is through microcontroller.
the microcontroller can generate the 3 PWM channels for red, green, blue for varying duty cycle..
it operates in single and multimode.there is an error in the code as there is some flickering observed in the lighting system.
the code is in assembly language for 89c52.
i have not made the code but have been asked to modify the code so that the flickering observed is removed.
could anyone please help me in identifying the problem in the code. i know that i need to increase the switching frequency but am not able to figure out where in the code it needs to be done.
looking for some replies.
code is attached here.

Back to top


namita
Mon May 12 2008, 09:13PM
 User Offline
Registered Member #7804
Joined: Mon May 12 2008, 09:00PM

Posts: 3
Thanked 0 times in 0 posts
starting address of program
CODE:
         org 0000h
          sjmp main
          org 000Bh
          ljmp delay2
          org 001Bh
          ljmp delay4
          org 0030h
main:      mov p2,#00h
          mov p1,#0ffh
          mov p0,#00h
;display on lcd:RGB lighting and Selected mode
          acall display
          setb psw.3
          setb psw.4
          mov r1,#0
          mov r2,#0
          mov r0,#0
          mov r3,#0
          mov r4,#0
          mov r5,#0
          acall display
          clr p1.4
          clr p1.5
          clr p1.6
;for selecting modes
again:     jnb P1.0, red
          jnb p1.2, multimode3
          sjmp again
;for single mode:red
red:       acall display1
          setb psw.3
          setb psw.4
          mov r1,#0
          mov r2,#0
          mov r0,#1
          mov r3,#0
          mov r4,#0
          mov r5,#0
          ljmp multimode8
;for single mode:green
green:     acall display2
          setb psw.3
          setb psw.4
          mov r0,#0
          mov r2,#0
          mov r1,#1
          mov r3,#0
          mov r4,#0
          mov r5,#0
          sjmp multimode8
;for single mode:blue
blue:      acall display3
          setb psw.3
          setb psw.4
          mov r0,#0
          mov r1,#0
          mov r2,#1
          mov r3,#0
          mov r4,#0
          mov r5,#0
          sjmp multimode8
;continuation for single mode
again2:    jnb p1.3,freeze1
          jnb p1.2, multimode3
          jnb p1.1, multimode4
          ljmp red2
;continuation for multimode
again5:    jnb p1.3,freeze2
          jnb P1.0, red
          jnb p1.2, multimode3
          jnb p1.1, multimode5
          ljmp red1
;for multimode
multimode3:acall display4
          setb psw.3
          setb psw.4
          mov r1,#0
          mov r2,#0
          mov r0,#0
          mov r3,#0
          mov r4,#0
          mov r5,#0
          ljmp multimode8
;for Freeze:single-mode
freeze1:   acall display5
          setb psw.3
          setb psw.4
          mov r4,#1
          ljmp red2
;for freeze:multimode
freeze2:   acall display5
          setb psw.3
          setb psw.4
          mov r5,#1
          ljmp red1
;for speed-up:single-mode
multimode4:acall display6
          setb psw.3
          setb psw.4
          mov r3,#1
          ljmp multimode7
;for speed-up:multimode
multimode5:acall display7
          setb psw.3
          setb psw.4
          mov r1,#0
          mov r2,#0
          mov r0,#0
          mov r3,#1
          mov r4,#0
          mov r5,#0
          mov b,#00
          ljmp multimode7
;declaring initials values
multimode8:clr p2.0
          clr p2.1
          clr p2.2
          clr psw.3
          clr psw.4
          mov r0,#0
          mov r1,#0
          mov r2,#0
          mov r3,#250
          mov a,r3
          mov r4,a
          mov r5,#0
          mov r6,#0
          mov r7,#1
          setb psw.3
          clr psw.4
          mov r0,#0
          mov r1,#0
          mov r2,#0
          mov r3,#230
          mov a,r3
          mov r4,a
          mov r5,#0
          mov r6,#0
          mov r7,#5
          clr psw.3
          setb psw.4
          mov r0,#0
          mov r1,#0
          mov r2,#0
          mov r3,#200
          mov a,r3
          mov r4,a
          mov r5,#0
          mov r6,#0
          mov r7,#11
          mov b,r3
          setb psw.3
          setb psw.4
          cjne r0,#0,red2
          cjne r1,#0,red2
          cjne r2,#0,red2
          acall red1
;declaring initials values for speed-up
multimode7:clr psw.3
          clr psw.4
          mov r0,#0
          mov r1,#0
          mov r2,#0
          mov r3,#160
          mov a,r3
          mov r4,a
          mov r5,#0
          mov r6,#0
          mov r7,#1
          setb psw.3
          clr psw.4
          mov r0,#0
          mov r1,#0
          mov r2,#0
          mov r3,#110
          mov a,r3
          mov r4,a
          mov r5,#0
          mov r6,#0
          mov r7,#11
          mov b,r3
          clr psw.3
          setb psw.4
          mov r0,#0
          mov r1,#0
          mov r2,#0
          mov r3,#130
          mov a,r3
          mov r4,a
          mov r5,#0
          mov r6,#0
          mov r7,#5
          setb psw.3
          setb psw.4
          cjne r0,#0,red2
          cjne r1,#0,red2
          cjne r2,#0,red2
          acall red1
level1:    setb psw.3
          clr psw.4
          inc r2
          dec r3
          inc r5
          sjmp red2
level2:    setb psw.3
          clr psw.4
          inc r3
          dec r2
          inc r6
          sjmp red2
;for varying duty cycle in single mode
red2:      setb psw.3
          clr psw.4
          mov a,r2
          subb a,r0
          cjne a,#0,singles
          mov a,r3
          subb a,r1
          cjne a,#0,singlec
          mov r0,#0
          mov r1,#0
          setb psw.3
          setb psw.4
          cjne r4,#0,red2
          setb psw.3
          clr psw.4
          mov a,r4
          subb a,r5
          cjne a,#0,level1
          mov a,r4
          subb a,r6
          cjne a,#0,level2
          setb psw.3
          setb psw.4
          cjne r3, #0,multimode9
          ljmp multimode8
multimode9:ljmp multimode7
singles:   setb psw.3
          setb psw.4
          cjne r0, #0, red2s
          cjne r1, #0, green2s
          cjne r2, #0, blue2s
          ljmp red2
singlec:   setb psw.3
          setb psw.4
          cjne r0, #0, red2c
          cjne r1, #0, green2c
          cjne r2, #0, blue2c
          ljmp red2
red2s:     jnb P1.0,greenn
          setb psw.3
          clr psw.4
          setb p2.0
          inc r0
          sjmp delay3
red2c:     jnb P1.0,greenn
          setb psw.3
          clr psw.4
          clr p2.0
          inc r1
          sjmp delay3
green2s:   jnb P1.0, bluee
          setb psw.3
          clr psw.4
          setb p2.1
          inc r0
          sjmp delay3
green2c:   jnb P1.0, bluee
          setb psw.3
          clr psw.4
          clr p2.1
          inc r1
          sjmp delay3
blue2s:    jnb P1.0, redd
          setb psw.3
          clr psw.4
          setb p2.2
          inc r0
          sjmp delay3
blue2c:    setb psw.3
          clr psw.4
          clr p2.2
          inc r1
          sjmp delay3
delay3:    mov tmod,#10
          mov tl1,#0eeh
          mov th1,#0ffh
          setb tr1
again4:    jnb tf1,again4
          clr tr1
          clr tf1
          ljmp again2
redd:      ljmp red
bluee:     ljmp blue
greenn:    ljmp green
;for varying duty cycle in multimode:red
red1:      clr psw.3
          clr psw.4
          mov a,r2
          subb a,r0
          cjne a,#0,reds
          mov a,r3
          subb a,r1
          cjne a,#0,redc
          mov r0,#0
          mov r1,#0
          setb psw.3
          setb psw.4
          cjne r5,#0,red1
          clr psw.3
          clr psw.4
          mov a,r4
          subb a,r5
          cjne a,#0,levelr1
          mov a,r4
          subb a,r6
          cjne a,#0,levelr2
          mov r5,#0
          mov r6,#0
          mov r2,#0
          cjne r7,#0,addr
          mov a,r4
          subb a,#5
          mov r3,a
          mov r4,a
          subb a,b
          cjne a,#0,red1
          mov r7,#11
          sjmp red1
addr:      clr psw.3
          clr psw.4
          mov a,r4
          add a,#5
          dec r7
          mov r3,a
          mov r4,a
          sjmp red1
reds:      clr psw.3
          clr psw.4
          inc r0
          setb p2.0
          ljmp green1
redc:      clr psw.3
          clr psw.4
          inc r1
          clr p2.0
          ljmp green1
levelr1:   clr psw.3
          clr psw.4
          inc r2
          dec r3
          inc r5
          ljmp red1
levelr2:   clr psw.3
          clr psw.4
          inc r3
          dec r2
          inc r6
          ljmp red1
;for varying duty cycle in multimode :green
green1:    setb psw.3
          clr psw.4
          mov a,r2
          subb a,r0
          cjne a,#0,greens
          mov a,r3
          subb a,r1
          cjne a,#0,greenc
          mov r0,#0
          mov r1,#0
          setb psw.3
          setb psw.4
          cjne r5,#0,green1
          setb psw.3
          clr psw.4
          mov a,r4
          subb a,r5
          cjne a,#0,levelg1
          mov a,r4
          subb a,r6
          cjne a,#0,levelg2
          mov r5,#0
          mov r6,#0
          mov r2,#0
          cjne r7,#0,addg
          mov a,r4
          subb a,#5
          mov r3,a
          mov r4,a
          subb a,b
          cjne a,#0,green1
          mov r7,#11
          sjmp green1
addg:      setb psw.3
          clr psw.4
          mov a,r4
          add a,#5
          dec r7
          mov r3,a
          mov r4,a
          sjmp green1
greens:    setb psw.3
          clr psw.4
          inc r0
          setb p2.1
          ljmp blue1
greenc:    setb psw.3
          clr psw.4
          inc r1
          clr p2.1
          ljmp blue1
levelg1:   setb psw.3
          clr psw.4
          inc r2
          dec r3
          inc r5
          ljmp green1
levelg2:   setb psw.3
          clr psw.4
          inc r3
          dec r2
          inc r6
          ljmp green1
;for varying duty cycle in multimode :blue
blue1:     clr psw.3
          setb psw.4
          mov a,r2
          subb a,r0
          cjne a,#0,blues
          mov a,r3
          subb a,r1
          cjne a,#0,bluec
          mov r0,#0
          mov r1,#0
          setb psw.3
          setb psw.4
          cjne r5,#0,blue1
          clr psw.3
          setb psw.4
          mov a,r4
          subb a,r5
          cjne a,#0,levelb1
          mov a,r4
          subb a,r6
          cjne a,#0,levelb2
          mov r5,#0
          mov r6,#0
          mov r2,#0
          cjne r7,#0,addb
          mov a,r4
          subb a,#5
          mov r3,a
          mov r4,a
          subb a,b
          cjne a,#0,blue1
          mov r7,#11
          sjmp blue1
addb:      clr psw.3
          setb psw.4
          mov a,r4
          add a,#5
          dec r7
          mov r3,a
          mov r4,a
          sjmp blue1
levelb1:   clr psw.3
          setb psw.4
          inc r2
          dec r3
          inc r5
          ljmp blue1
levelb2:   clr psw.3
          setb psw.4
          inc r3
          dec r2
          inc r6
          ljmp blue1
blues:     clr psw.3
          setb psw.4
          inc r0
          mov ie,#82h
          setb p2.2
          ljmp again5
bluec:     clr psw.3
          setb psw.4
          inc r1
          mov ie,#88h
          clr p2.2
          ljmp again5
delay2:    setb psw.3
          setb psw.4
          mov tmod,#01
          mov tl0,#003h
          mov th0,#0fdh
          setb tr0
again1:    jnb tf0,again1
          clr tr0
          clr tf0
          reti
delay4:    setb psw.3
          setb psw.4
          mov tmod,#10
          mov tl1,#0d0h
          mov th1,#0ffh
          setb tr1
again7:    jnb tf1,again7
          clr tr1
          clr tf1
          reti
;for lcd display
display:   mov dptr,#initial
c2:        clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz send_dat
          inc dptr
          sjmp c2
send_dat:  mov dptr,#data1
d2:        clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main2
          sjmp d2
main2:     mov dptr,#initial1
c1:        clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat6
          inc dptr
          sjmp c1
dat6:      mov dptr,#data6
d6:        clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main3
          sjmp d6
main3:     ret
com:       mov p0,a
          clr p2.4
          clr p2.5
          setb p2.6
          acall delay
          clr p2.6
          ret
dataw :    mov p0,a
          setb p2.4
          clr p2.5
          setb p2.6
          acall delay
          clr p2.6
          ret
delay:     mov r3,#250
here:      djnz r3,here
          ret
display1:  mov dptr,#initial1
c8:        clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat2
          inc dptr
          sjmp c8
dat2:      mov dptr,#data2
d8:        clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main5
          sjmp d8
main5:     ret
display2:  mov dptr,#initial1
c9:        clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat3
          inc dptr
          sjmp c9
dat3:      mov dptr,#data3
d9:        clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main6
          sjmp d9
main6:     ret
display3:  mov dptr,#initial1
c10:        clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat4
          inc dptr
          sjmp c10
dat4:      mov dptr,#data4
d10:        clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main7
          sjmp d10
main7:     ret
display4:  mov dptr,#initial1
c11:        clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat5
          inc dptr
          sjmp c11
dat5:      mov dptr,#data5
d11:        clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main8
          sjmp d11
main8:     ret
display5:  mov dptr,#initial1
c12:        clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat7
          inc dptr
          sjmp c12
dat7:      mov dptr,#data7
d12:        clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main9
          sjmp d12
main9:     ret
display6:  mov dptr,#initial1
c13:       clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat8
          inc dptr
          sjmp c13
dat8:      mov dptr,#data8
d13:       clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main10
          sjmp d13
main10:     ret
display7:  mov dptr,#initial1
c14:       clr a
          movc a,@a+dptr
          acall com
          acall delay
          jz dat9
          inc dptr
          sjmp c14
dat9:      mov dptr,#data9
d14:       clr a
          movc a,@a+dptr
          acall dataw
          acall delay
          inc dptr
          jz main11
          sjmp d14
main11:     ret
;define bytes for lcd display
          org   600h
initial:   db   38h,0ch,01h,06h,80h,0
data1:     db  "RGB Lighting.....",0
initial1:  db   38h,0ch,06h,0c0h,0
data6:     db  "  select mode    ",0
data2:     db  "    s1 mode red  ",0
data3:     db  "  s1 mode green  ",0
data4:     db  "   s1 mode blue  ",0
data5:     db  "   multi mode    ",0
data7:     db  "      Freeze     ",0
data8:     db  "   speed-up s1   ",0
data9:     db  "   speed-up m1   ",0
          end
 


[ Edited Tue May 13 2008, 02:36PM ]
Back to top


Ajay
Tue May 13 2008, 02:44PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
you might need to adjust the timer values.. can you explain what do you mean by flickering exactly?

and please comment your code properly otherwise it will be hard to understand the code and make changes into it.

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


namita
Tue May 13 2008, 03:51PM
 User Offline
Registered Member #7804
Joined: Mon May 12 2008, 09:00PM

Posts: 3
Thanked 0 times in 0 posts
flickering means when the color of LED's changes from red to green to blue there is not a smooth transition but the change in color is visible. the change in color from red to green and then to blue after a ferw seconds should be such that we are not able to detect when the transition to next color took place. it should be that smooth a transition but in this code this is not happening. we are able to detect that color is changing.
i have not made this code and that's why it is causing a problem. i have been asked to sort out the problem in the code.
i feel that the frequency is less than 100 hz and is between 50-80 Hz and i need to increase it and keep it between 100 to 1 Khz. then the flickering will be removed.
i don't know where in the code do i make the changes.

i hope u got some clarity
Back to top


 

Jump:     Back to top