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 11:14
Read: 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            01/01/70 00:00      
   Duplicate Posting            01/01/70 00:00      
      This is just an inadequately understood homework problem            01/01/70 00:00      
   Design your code, make it pretty.            01/01/70 00:00      
   RE: please suggest some idea            01/01/70 00:00      
      I totally agree with ANDY            01/01/70 00:00      
         Very unhelpful comments            01/01/70 00:00      
            Thank you sir            01/01/70 00:00      
               While analysing the problem            01/01/70 00:00      
               Translation into assembler task of programmer.            01/01/70 00:00      
   'subb' instruction            01/01/70 00:00      
      Yes, debounce is definitely good to have.            01/01/70 00:00      
         Got Success !            01/01/70 00:00      
            What is the final code?            01/01/70 00:00      
               homework is done..            01/01/70 00:00      
               Surely not secret, at least for my seniors            01/01/70 00:00      
               Teacher will know            01/01/70 00:00      
                  Don't worry            01/01/70 00:00      
                     What code?            01/01/70 00:00      
                     You must show your effort.            01/01/70 00:00      
                        yes, it's another "gimmee", yet nobody sees it            01/01/70 00:00      
                           what's the problem            01/01/70 00:00      
                              Why ever source current for driving LEDs?            01/01/70 00:00      
                              true enough, but is that what he did?            01/01/70 00:00      
                           I think everybody saw that?            01/01/70 00:00      
                              Cleverness            01/01/70 00:00      
                                 Stange !            01/01/70 00:00      
                                    because it is            01/01/70 00:00      
                                    Yes, often very obvious when copied code turned in            01/01/70 00:00      
                              I agree with Andy            01/01/70 00:00      
                                 the key word is 'help'            01/01/70 00:00      
                                    May not be an achievement for you            01/01/70 00:00      
                                       So ... where's the evidence of your struggle?            01/01/70 00:00      
                                    problem can be outside            01/01/70 00:00      
                                    This is certainly correct!            01/01/70 00:00      
   About sinciarity            01/01/70 00:00      

Back to Subject List