****** ** LOCK_2.ASM (68HC11) ** ** Comination lock. ** ** Combination is $0F $70 ** ** When S7 at zero, user keys in number on the lower switches. ** When ready, user switches S7 to 1 and back to zero. Number on 7 ** lower switches read. If in agreement, goes to second number. ** If wrong, returns to start again. ** ** This is functionally the same as LOCK_1 except subroutines are ** used. ** ** P. H. Anderson, MSU, 6 Feb 93 ******* PSCT EQU $C000 DSCT EQU $D000 IDSCT EQU $D300 REG_BASE EQU $1000 STACK_TP EQU $0045 PORTB EQU $04 PORTC EQU $03 DDRC EQU $07 ORG PSCT LDS #STACK_TP LDY #REG_BASE CLR DDRC,Y * portc configured as input FIRST BCLR PORTB,Y %11111111 BSET PORTB,Y %00000001 * prompt for first number BSR JOG LDAA #$0F * code BSR TST_NUM TSTA BEQ FIRST SECOND BCLR PORTB,Y %11111111 BSET PORTB,Y %00000010 * prompt for second BSR JOG LDAA #$70 * code BSR TST_NUM TSTA BEQ FIRST SUCCESS BSET PORTB,Y $FF * light all LEDs SWI * Subroutines. TST_NUM * code number is passed in A. if switches match code * then non zero is returned in A. uses memory location TEMP STAA TEMP * save the code LDAA PORTC,Y * get switches ANDA #$7F * examine lower 7 bits only CMPA TEMP BNE NOT_CORRECT BRA CORRECT NOT_CORRECT CLRA * return zero RTS CORRECT CLRA INCA * return non zero RTS JOG * waits for 0 to 1 to 0 transition on S7. * nothing is passed to subroutine, nothing is returned. * no registers are used. WAIT_1A BRCLR PORTC,Y %10000000 WAIT_1A BSR DELAY WAIT_1B BRSET PORTC,Y %10000000 WAIT_1B BSR DELAY RTS DELAY * delays. nothing passed. nothing returned. X register used. PSHX * to debounce switch LDX #$FFFF T1 DEX BNE T1 PULX RTS ORG DSCT TEMP RMB 1