; ------------------- Function Description ------------------- ; The interrupt output on the Key-unit is connected to the input ; for external interrupt 2 on P1.4. A LED in the LED-unit is ; connected to P4.0 to provide a visual indication of the ; interrupt initiated by pressing a key. ; -------------------------------------------------------------- ; --------- Declarations required for the Assembler ---------- CPU 80515 ; Select microcontroller INCLUDE STDDEF51 ; SFR definitions SEGMENT Code ; Code segment starts here ORG 0000H ; 1st. instruction, starts at address 0000H ; ------------------------------------------------------------- jmp START ; Jump to main program ; ------------------------------------------------------------- ; --------------- Enter the IV in the IVT --------------------- ORG 004BH ; IV-position for external interrupt 2 JMP ISR_INT2 ; Interrupt vector (IV) ; ------------------------------------------------------------- ; ************************************************************* ; * Main program, "Ext.Interrupt 2 from pressing a key * ; ************************************************************* START: CALL INIT_INT2 ; Initialise ext. Interrupt 2 ; *********************************************************** ; y d ; *********************************************************** MOV A,#11111111B ; Define bit pattern MOV P1,A ; Bit pattern to Port 1 JB P4.3, ST7 JMP START ST7: JB P4.7, ST6 ; pushnutton P4.7 for CW CPL P1.6 JMP ST1 ST6: JB P4.6, ST7 ; pushnutton P4.6 for ccw CPL P1.7 JMP ST2 ; CW ; ........................................................... ST1: JB P4.3, ST20 ; fault - switch off P4.3 JMP START ST20: JB P4.5, ST15 ; pushbutton STOP P4.5 JMP START ST15: JB P4.4, ST1 ; pushbutton START P4.4 MOV A,#10111110B MOV P1,A CALL TIMER2 CALL TIMER2 MOV A,#10111010B MOV P1,A CALL TIMERD CPL P1.0 CALL TIMER2 CALL TIMER2 ST3: MOV A,#10111001B MOV P1,A JB P4.3, ST11 ; fault - switch off P4.3 JMP ST13 ST11: JB P4.5, ST3 ; pushnutton STOP P4.5 ST13: MOV A,#10111111B MOV P1,A CALL TIMER2 CALL TIMER2 JMP START ;CCW ; .......................................................... ST2: JB P4.3, ST21 ; fault switch off P4.3 JMP START ST21: JB P4.5, ST16 ; pushnutton STOP P4.5 JMP START ST16: JB P4.4, ST2 ; tipkalo START P4.4 MOV A,#01111110B MOV P1,A CALL TIMER2 CALL TIMER2 MOV A,#01111010B MOV P1,A CALL TIMERL CPL P1.0 CALL TIMER2 CALL TIMER2 ST4: MOV A,#01111001B MOV P1,A JB P4.3, ST12 ; fault - switch off P4.3 JMP ST14 T12: JB P4.5, ST4 ; pushnutton STOP P4.5 ST14: MOV A,#01111111B MOV P1,A CALL TIMER2 CALL TIMER2 JMP START ; ********************************************************* ; ---------------------------------------------------------- ; TIMERD: MOV R1,#200 ; Counter for outer loop DELAY1: MOV R2, #200 DELAY2: MOV R3, #50 DELAY3: DJNZ R3, DELAY3 JB P4.3, ST31 ; fault - switch off P4.3 JMP ST70 ST31: JB P4.5, ST45 ; pushnutton STOP P4.5 ST70: MOV A,#01111111B MOV P1,A CALL TIMER2 CALL TIMER2 JMP START ST45: DJNZ R2, DELAY2 DJNZ R1, DELAY1 RET ; ---------------------------------------------------------- TIMERL: MOV R1,#100 ; Counter for outer loop DELAY4: MOV R2, #200 DELAY5: MOV R3, #50 DELAY6: DJNZ R3, DELAY6 JB P4.3, ST51 ; fault - switch off P4.3 JMP ST80 ST51: JB P4.5, ST65 ; pushbutton STOP P4.5 ST80: MOV A,#01111111B MOV P1,A CALL TIMER2 CALL TIMER2 JMP START ST65: DJNZ R2, DELAY5 DJNZ R1, DELAY4 RET TIMERINTERUPT: MOV R1,#100 ; Counter for outer loop DELAY7: MOV R2, #250 CPL P4.0 DELAY8: MOV R3, #200 DELAY9: DJNZ R3, DELAY9 JB P4.3, ST61 ; fault switch - off P4.3 JMP ST82 ST61: JB P4.5, ST75 ; pushnutton STOP P4.5 ST82: MOV A,#11111111B MOV P1,A ST75: DJNZ R2, DELAY8 DJNZ R1, DELAY7 RET ; ---------------------------------------------------------- ; Sub Routine , approx. 131ms ; ---------------------------------------------------------- ; 2 nested DJNZ loops TIMER2: MOV R7,#000H ; Counter for outer loop Z01: MOV R6,#000H ; Counter for inner loop Z00: DJNZ R6,Z00 ; 256*2µs (inner loop) DJNZ R7,Z01 ; 256* inner loop RET ; ---------------------------------------------------------- JMP $ ; Endless loop as "End" ; of the main program ; ************************************************************* ; ------------------------------------------------------------- ; Sub-routine for initialising external Interrupt 2 ; ------------------------------------------------------------- INIT_INT2: CLR EAL ; Global inhibit of interrupt acceptance SETB I2FR ; 0-1 edge initiates interrupt SETB EX2 ; Allow interrupt from ext.Int 2 SETB EAL ; Allow interrupt acceptance, global RET ; ------------------------------------------------------------- ; ISR for ext. Interrupt 2 ; ------------------------------------------------------------- ISR_INT2: CALL TIMERINTERUPT CLR IEX2 ; Reset interrupt request bit (*) JB P1.5, ST77 ; P1.5 ACKNOWLEDGE JMP ST78 ST77: PUSH 0000H ST78: RETI ; ------------------------------------------------------------- END