Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/07/11 05:14
Read: 1472 times


 
Msg Score: -1
 -1 Message Not Useful
#184124 - Speed control of running adancing LEDs
Hi Friends
Actually, I have a program in Assembly and want to include up/down buttons to change the speed of running.
I tried with calling differet delay routines but not getting success please suggest some idea.

Thank u for responding on my above problem through chat board. It is learned that such type of problems should not be raised throgh Chat board hence I shifted from chat board to 8052 forum. Now, I am with clear cut problem and well commented code. Please look into the code and we can modidify the code to run with UP/DN buttons.


;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;PROGRAM FOR DANCING LED
;With control of running or dancing speed
;Three speeds UP & DOWN; 
;Using three tactile switches at P0.0 & P0.1 for up & down buttons
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 

ORG 0000H 


L1 EQU P3.4   ;L1 to L11 are LEDs for dancing effect of light 
L2 EQU P3.1 
L3 EQU P3.0 
L4 EQU P1.7 
L5 EQU P1.6 
L6 EQU P1.5 
L7 EQU P1.4 
L8 EQU P1.3 
L9 EQU P1.2 
L10 EQU P1.1 
L11 EQU P1.0 


MOV R4,#03H  ;Selected count for three speeds
			
FNAUTO: MOV R3,#05 ;Selected count for five times play of same light effect 

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
D1: CALL DESGN1 ;nine different dancing patterns/ effect, called one by one
DJNZ R3,D1 
MOV R3,#05 

D2: CALL DESGN2 
DJNZ R3,D2 
MOV R3,#05 

D3: CALL DESGN3 
DJNZ R3,D3 
MOV R3,#05 

D4: CALL DESGN4 
DJNZ R3,D4 
MOV R3,#05 

D5: CALL DESGN5 
DJNZ R3,D5 
MOV R3,#05 

D6: CALL DESGN6 
DJNZ R3,D6 
MOV R3,#05 

D7: CALL DESGN7 
DJNZ R3,D7 
MOV R3,#05 

D8: CALL DESGN8 
DJNZ R3,D8 
MOV R3,#05 

D9: CALL DESGN9 
DJNZ R3,D9 
MOV R3,#05 
JMP FNAUTO 

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
		  ;Sub Routines for Nine patterns
;*******************************************
DESGN1: CLR L1 	;sub Routine for pattern1
SETB L2 
CLR L3 
SETB L4 
CLR L5 
SETB L6 
CLR L7 
SETB L8 
CLR L9 
SETB L10 
CLR L11 
CALL DELAY 
CLR L2 
SETB L1 
CLR L4 
SETB L3 
CLR L6 
SETB L5 
CLR L8 
SETB L7 
CLR L10 
SETB L9 
SETB L11 
CALL DELAY 
RET 

DESGN2: CALL CLEAR  ;Sub Routine for pattern2 
CLR L1 
CALL DELAY 
CALL CLEAR 
CLR L2 
CALL DELAY 
CALL CLEAR 
CLR L3 
CALL DELAY 
CALL CLEAR 
CLR L4 
CALL DELAY 
CALL CLEAR 
CLR L5 
CALL DELAY 
CALL CLEAR 
CLR L6 
CALL DELAY 
CALL CLEAR 
CLR L7 
CALL DELAY 
CALL CLEAR 
CLR L8 
CALL DELAY 
CALL CLEAR 
CLR L9 
CALL DELAY 
CALL CLEAR 
CLR L10 
CALL DELAY 
CALL CLEAR 
CLR L11 
CALL DELAY 
RET 

DESGN3: CALL CLEAR  ;Sub Routine for pattern3 
CLR L11 
CALL DELAY 
CALL CLEAR 
CLR L10 
CALL DELAY 
CALL CLEAR 
CLR L9 
CALL DELAY 
CALL CLEAR 
CLR L8 
CALL DELAY 
CALL CLEAR 
CLR L7 
CALL DELAY 
CALL CLEAR 
CLR L6 
CALL DELAY 
CALL CLEAR 
CLR L5 
CALL DELAY 
CALL CLEAR 
CLR L4 
CALL DELAY 
CALL CLEAR 
CLR L3 
CALL DELAY 
CALL CLEAR 
CLR L2 
CALL DELAY 
CALL CLEAR 
CLR L1 
CALL DELAY 
RET 

DESGN4: CALL CLEAR ;Sub Routine for pattern4 
CLR L1 
CALL DELAY 
CALL CLEAR 
CLR L2 
CALL DELAY 
CALL CLEAR 
CLR L3 
CALL DELAY 
CALL CLEAR 
CLR L4 
CALL DELAY 
CALL CLEAR 
CLR L5 
CALL DELAY 
CALL CLEAR 
CLR L6 
CALL DELAY 
CALL CLEAR 
CLR L7 
CALL DELAY 
CALL CLEAR 
CLR L8 
CALL DELAY 
CALL CLEAR 
CLR L9 
CALL DELAY 
CALL CLEAR 
CLR L10 
CALL DELAY 
CALL CLEAR 
CLR L11 
CALL DELAY 
CALL CLEAR 
CLR L11 
CALL DELAY 
CALL CLEAR 
CLR L10 
CALL DELAY 
CALL CLEAR 
CLR L9 
CALL DELAY 
CALL CLEAR 
CLR L8 
CALL DELAY 
CALL CLEAR 
CLR L7 
CALL DELAY 
CALL CLEAR 
CLR L6 
CALL DELAY 
CALL CLEAR 
CLR L5 
CALL DELAY 
CALL CLEAR 
CLR L4 
CALL DELAY 
CALL CLEAR 
CLR L3 
CALL DELAY 
CALL CLEAR 
CLR L2 
CALL DELAY 
CALL CLEAR 
CLR L1 
CALL DELAY 
RET 

DESGN5: CALL CLEAR ;Sub Routine for pattern5 
CLR L1 
CLR L11 
CALL DELAY 
CALL CLEAR 
CLR L2 
CLR L10 
CALL DELAY 
CALL CLEAR 
CLR L3 
CLR L9 
CALL DELAY 
CALL CLEAR 
CLR L4 
CLR L8 
CALL DELAY 
CALL CLEAR 
CLR L5 
CLR L7 
CALL DELAY 
CALL CLEAR 
CLR L6 
CALL DELAY 
CALL CLEAR 
CLR L7 
CLR L5 
CALL DELAY 
CALL CLEAR 
CLR L8 
CLR L4 
CALL DELAY 
CALL CLEAR 
CLR L9 
CLR L3 
CALL DELAY 
CALL CLEAR 
CLR L10 
CLR L2 
CALL DELAY 
CALL CLEAR 
CLR L11 
CLR L1 
CALL DELAY 
CALL CLEAR 
RET 

DESGN6: CALL ALLON ;Sub Routine for pattern6 
CALL DELAY 
CALL CLEAR 
CALL DELAY 
RET 

DESGN7: CALL ALLON ;Sub Routine for pattern7
SETB L1 
CALL DELAY 
CALL ALLON 
SETB L2 
CALL DELAY 
CALL ALLON 
SETB L3 
CALL DELAY 
CALL ALLON 
SETB L4 
CALL DELAY 
CALL ALLON 
SETB L5 
CALL DELAY 
CALL ALLON 
SETB L6 
CALL DELAY 
CALL ALLON 
SETB L7 
CALL DELAY 
CALL ALLON 
SETB L8 
CALL DELAY 
CALL ALLON 
SETB L9 
CALL DELAY 
CALL ALLON 
SETB L10 
CALL DELAY 
CALL ALLON 
SETB L11 
CALL DELAY 
RET 

DESGN8: CALL ALLON ;Sub Routine for pattern8 
SETB L11 
CALL DELAY 
CALL ALLON 
SETB L10 
CALL DELAY 
CALL ALLON 
SETB L9 
CALL DELAY 
CALL ALLON 
SETB L8 
CALL DELAY 
CALL ALLON 
SETB L7 
CALL DELAY 
CALL ALLON 
SETB L6 
CALL DELAY 
CALL ALLON 
SETB L5 
CALL DELAY 
CALL ALLON 
SETB L4 
CALL DELAY 
CALL ALLON 
SETB L3 
CALL DELAY 
CALL ALLON 
SETB L2 
CALL DELAY 
CALL ALLON 
SETB L1 
CALL DELAY 
RET 

DESGN9: CALL ALLON ;Sub Routine for pattern9
SETB L11 
SETB L1 
CALL DELAY 
CALL ALLON 
SETB L10 
SETB L2 
CALL DELAY 
CALL ALLON 
SETB L9 
SETB L3 
CALL DELAY 
CALL ALLON 
SETB L8 
SETB L4 
CALL DELAY 
CALL ALLON 
SETB L7 
SETB L5 
CALL DELAY 
CALL ALLON 
SETB L6 
CALL DELAY 
CALL ALLON 
SETB L5 
SETB L7 
CALL DELAY 
CALL ALLON 
SETB L4 
SETB L8 
CALL DELAY 
CALL ALLON 
SETB L3 
SETB L9 
CALL DELAY 
CALL ALLON 
SETB L2 
SETB L10 
CALL DELAY 
CALL ALLON 
SETB L1 
SETB L11 
CALL DELAY 
RET 
;********************************************************
	    ;Sub routine for OFF all the LEDs
;********************************************************
CLEAR: SETB L1	;Sub routine for OFF all the LEDs
SETB L2 
SETB L3 
SETB L4 
SETB L5 
SETB L6 
SETB L7 
SETB L8 
SETB L9 
SETB L10 
SETB L11 
RET 
;*******************************************************
 	;Sub routine for ON all the LEDs
;********************************************************
ALLON: CLR L1 ;Sub routine for ON all the LEDs
CLR L2 
CLR L3 
CLR L4 
CLR L5 
CLR L6 
CLR L7 
CLR L8 
CLR L9 
CLR L10 
CLR L11 
RET 
;****************************************************
; My idea was that delay sub routine poll the switches in each cycle
; If UP butn is pressed then R4 should be increased & compare with normal 
; speed value as #03.
; Accordingly it should select the appropriate delay constants forever
;till the reset or  on any other button press.
; But I am failing here that it works in first cycle of execution and after that it is not working !
;****************************************************** 

DELAY: 
JNB P0.0, CHECK ;check for UP button press
NOP 
;JB P0.0,NOR_DEL 
JNB P0.1,CHECK1 
NOP 
;JB P0.1,NOR_DEL 

CHECK:													 
INC R4											; 
MOV A,#03H 
SUBB A,R4     ;Compare contents of R4 with #03 i.e nomal speed value				
JZ NOR_DEL   ; if equal run with normal delay parameters
JC INCR      ; If R4>03 then check whether it is #04
JNC DECR 
CHECK1: 
DEC R4 
MOV A,#03H 
SUBB A,R4 
JZ NOR_DEL 
JC INCR 
JNC DECR 


NOR_DEL:MOV R0,#0FFH 
MOV R1,#0FFH 
INLOP: MOV R2,#01H 
DJNZ R2,$ 
DJNZ R1,$ 
DJNZ R0,INLOP 
RET 


INCR: 
     CJNE R4,#04H,NXT1 ;check whether it is #04
     MOV R0,#80h  ;if it is #04 take the delay constant as #80h in R0        MOV R1,#0FFH 	  ;ie. we have decreased the delay time or increased  ;dancing speed 
		AJMP INLOP 

NXT1: 	CJNE R4,#05H,NXT2  				;check whether it is #05
		MOV R0,#01H   					;if it is #05 take the delay constant as #01h in R0 and #80h in R1 
		MOV R1,#80H 					;ie. further decreased the delay time or increased the dancing speed
		AJMP INLOP 

NXT2: 	CJNE R4,#06H,NXT3 			;check whether it is #06 i.e for maximum speed
LAST: 	MOV R0,#01H 				;if it is #05 take the delay constant as #01h in R0 and #81h in R1 
		MOV R1,#01H  				;further decreased the delay time or increased the dancing speed
		AJMP INLOP 

NXT3: 	MOV A,#06H 					; If some pressees more UP button the last speed
		SUBB A, R4 					; should remai valid
		CJNE A,#00H,NXT2 			
		AJMP LAST 

DECR:  								; MUST REQUIRED RST BUTTON TO AVOID CRASH 
		CJNE R4,#02H, NXT4 			; Similarly we have tried for decreasing the dancing speed.
		MOV R0,#36H 				;Speed- 
		AJMP INLOP 

NXT4:   CJNE R4,#01H, NXT5 
		MOV R0,#80H 				;Speed-- 
		AJMP INLOP
		 
NXT5: 	CJNE R4,#00H, NXT5 
		MOV R0,#0FFH 				;Speed--- 
		AJMP NXT5 


END 



List of 36 messages in thread
TopicAuthorDate
Speed control of running adancing LEDs      Rajesh Kumar      10/07/11 05:14      
   Duplicate Posting      Michael Karas      10/07/11 06:56      
      This is just an inadequately understood homework problem      Richard Erlacher      10/07/11 09:51      
   Design your code, make it pretty.      David Prentice      10/07/11 07:02      
   RE: please suggest some idea      Andy Neil      10/07/11 07:15      
      I totally agree with ANDY      Erik Malund      10/07/11 08:12      
         Very unhelpful comments        Per Westermark      10/07/11 09:19      
            Thank you sir      Rajesh Kumar      10/08/11 02:00      
               While analysing the problem      Maunik Choksi      10/08/11 02:30      
               Translation into assembler task of programmer.      Per Westermark      10/08/11 03:20      
   'subb' instruction      Stefan KAnev      10/08/11 11:53      
      Yes, debounce is definitely good to have.      Per Westermark      10/08/11 12:11      
         Got Success !      Rajesh Kumar      10/10/11 01:16      
            What is the final code?      David Prentice      10/10/11 04:21      
               homework is done..      Stefan KAnev      10/10/11 05:11      
               Surely not secret, at least for my seniors      Rajesh Kumar      10/10/11 05:39      
               Teacher will know      Andy Neil      10/10/11 05:40      
                  Don't worry      Rajesh Kumar      10/10/11 05:49      
                     What code?      Andy Neil      10/10/11 06:15      
                     You must show your effort.        David Prentice      10/10/11 07:09      
                        yes, it's another "gimmee", yet nobody sees it      Richard Erlacher      10/10/11 07:22      
                           what's the problem      Erik Malund      10/10/11 08:03      
                              Why ever source current for driving LEDs?      Per Westermark      10/10/11 08:15      
                              true enough, but is that what he did?      Richard Erlacher      10/10/11 22:23      
                           I think everybody saw that?      Andy Neil      10/10/11 08:03      
                              Cleverness      Per Westermark      10/10/11 08:17      
                                 Stange !      Rajesh Kumar      10/10/11 11:29      
                                    because it is      Erik Malund      10/10/11 12:48      
                                    Yes, often very obvious when copied code turned in      Per Westermark      10/10/11 13:02      
                              I agree with Andy      David Prentice      10/10/11 08:24      
                                 the key word is 'help'      Erik Malund      10/10/11 08:35      
                                    May not be an achievement for you      Rajesh Kumar      10/10/11 11:08      
                                       So ... where's the evidence of your struggle?      Richard Erlacher      10/10/11 22:31      
                                    problem can be outside      Stefan KAnev      10/10/11 11:12      
                                    This is certainly correct!      Richard Erlacher      10/10/11 22:29      
   About sinciarity      Maunik Choksi      10/11/11 02:58      

Back to Subject List