??? 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 |