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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/10/11 11:39
Read: times


 
#184150 - Surely not secret, at least for my seniors
Responding to: ???'s previous message
Actually code is running fine on the Simulator,today I was busy with PCB designing and planned day after tomorrow to join you with final code.
But now I am uploading for your further suggestions to write code more smartly with ROM saving ideas.
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;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
;Idea2
;i. we should write three delay sub routines
;ii.use three switches, Mode, UP, DN consuming three port pins.
;iii. Mode switch will be SPDT
;iv. Delay sub rotine will be call only after inspecting the correspnding
;	registers of the switches
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 

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 
	MODE EQU P3.3	; Mode switch will act as program switch
	UP EQU P3.5		;For speed up
	DN EQU P3.7		;For speed down

	;----------------------------------------------------------------------------
	MODCHK: 
			JNB MODE, UPCHK	;Check, if MODE switch is Position (ON/OFF)
			JNB UP, DNCHK	;Check, if UP switch is pressed
			JNB DN, MODCHK	;Check, if DOWN switch is pressed
			JB MODE, FNAUTO	;IF MODE SWICTH IS TOGGLED START FUNCTION		
	
	UPCHK:	JB UP, DNCHK
			ACALL   DBDEL 	    ;DEBOUNCE KEY DELAY
	RELEASE:JNB UP,RELEASE 	   ;WAIT FOR KEY TO RELEASE
        	ACALL   DBDEL 	    ;DEBOUNCE KEY DELAY
	INCR: 	INC R4				; Set the delay rotine number			
			CJNE R4,#02H,MODCHK ;CHECK THE PRGRAM SWITCHES
			AJMP MODCHK			;Check, if MODE switch is Position (ON/OFF)
	
	DNCHK:	JB DN, MODCHK		;Check, if DOWN switch is pressed
			ACALL   DBDEL       ;DEBOUNCE KEY DELAY
	RELEASE1:JNB DN,RELEASE1    ;WAIT FOR KEY TO RELEASE
        	ACALL   DBDEL           ;DEBOUNCE KEY DELAY
	DECR: 	DEC R4
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&										
FNAUTO: MOV R3,#05	;Selected count for five times play of same light effect 

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

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

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

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

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

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

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

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

D9: CALL PATTERN9 
DJNZ R3,D9 
MOV R3,#05 
JMP FNAUTO 
	
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
				   ;Sub Routines for Nine patterns
;*******************************************
PATTERN1: 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 

PATTERN2: 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 

PATTERN3: 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 

PATTERN4: 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 

PATTERN5: 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 

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

PATTERN7: 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 

PATTERN8: 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 

PATTERN9: 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 button is pressed then R4 should be increased & compare with the normal 
; speed value as #03.
; Accordingly it shoud select the appropriate delay constants forever till the reset or 
; on any other button press.
;****************************************************** 
DELAY:
		CJNE R4,#00H, CHK1
		JUMP DELAY0
CHK1:	CJNE R4,#01H, CHK2
		AJMP DELAY1
CHK2:	CJNE R4,#02H,CRCHK	;IF NOT EQUAL CHECK CARRY
		JUMP DELAY2

DELAY0:
		MOV R0,#0FFH
		MOV R1,#0FFH 
	INLOP: MOV R2,#0FFH 
		DJNZ R2,$ 
		DJNZ R0,INLOP 
		RET 

DELAY1:
		MOV R0,#0FFH
		MOV R1,#0FFH 
	INLOP1:DJNZ R1,$ 
		DJNZ R0,INLOP1 
		RET 
CRCHK:	MOV A,#02H
		SUBB A,R4
		JC LIMIT
LIMIT:	MOV R4,#02H
		JUMP DELAY2

DELAY2:
		MOV R0,#0FFH
		DJNZ R0,$ 
		RET
DBDEL:
        MOV     DPTR,#65536-4000 ;INITIALISE DPTR
DB10:
        INC     DPTR            ;INCREMENT DPTR
        MOV     A,DPL           ;GET DPL IN ACC
        ORL     A,DPH           ;OR IT WITH DPH IF RESULT IS
        JNZ     DB10            ;NOT ZERO THEN INCREMENT AGAIN
        RET                     ;ELSE RETURN
  

END 



...insert code here
 



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