![]() Simple Combination LockA simple project with no 'real' functionality
This project was done as part of one of my subjects at uni. All it does is display the following text across the display and waits for the PIN to be entered. To enter the PIN you set the left 3 of the DIP switches and then toggle the 4th up then down (like an ENTER key) you do this twice to achieve a 6 bit code. The code is compared to one hard coded internally and if it matches the 'accepted' text is scrolled across, then it return to the first one. If it doesn't match then it says 'denied'. The following circuit should give some idea of the setup.
![]()
The text that gets scrolled across looks something like this:
BTW: If you can't work out what it displays then, here is what it says as a 'string'... "E n t E r P I n ." Source Code This is what the source code looks like:
;********************************************************************** ; This file is a basic code template for assembly code generation * ; on the PICmicro PIC16F84. This file contains the basic code * ; building blocks to build upon. * ; * ; If interrupts are not used all code presented between the ORG * ; 0x004 directive and the label main can be removed. In addition * ; the variable assignments for 'w_temp' and 'status_temp' can * ; be removed. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PICmicro data sheet for additional * ; information on the instruction set. * ; * ; Template file assembled with MPLAB V3.99.18 and MPASM V2.15.06. * ; * ;********************************************************************** ; * ; Filename: dslab7.asm * ; Date: 18-Oct-1999 * ; File Version: A * ; * ; Author: Wesley Moore * ; Company: N/A * ; * ; * ;********************************************************************** ; * ; Files required: None * ; * ; * ; * ;********************************************************************** ; * ; Notes: None * ; * ; * ; * ; * ;********************************************************************** list p=16F84 ; list directive to define processor #include <p16F84.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***** VARIABLE DEFINITIONS temp EQU 0x0C ; temp variable pincode EQU 0x0D ; the PIN delaytemp1 EQU 0x0E delaytemp2 EQU 0x0F delaytemp3 EQU 0x010 count EQU 0x011 entry EQU 0x012 ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location retfie ; return from interrupt ; table1 ADDWF PCL, F ; Jump RETLW 0x086 ; E RETLW 0x0AB ; n RETLW 0x087 ; t RETLW 0x086 ; E RETLW 0x0AF ; r RETLW 0x0FF ; space RETLW 0x08C ; P RETLW 0x0F9 ; I RETLW 0x0AB ; n RETLW 0x07F ; dp RETLW 0x00 ; null char ; table2 ADDWF PCL, F RETLW 0x088 ; A RETLW 0x0C6 ; C RETLW 0x0C6 ; C RETLW 0x086 ; E RETLW 0x08C ; P RETLW 0x087 ; t RETLW 0x086 ; E RETLW 0x0A1 ; d RETLW 0x00 ; \0 ; table3 ADDWF PCL, F RETLW 0x0A1 ; d RETLW 0x086 ; E RETLW 0x0AB ; n RETLW 0x0F9 ; I RETLW 0x086 ; E RETLW 0x0A1 ; d RETLW 0x00 ; \0 ; main bsf STATUS, RP0 ; Set page bit clrf TRISB ; All outputs bcf STATUS, RP0 ; Clear page bit ; 7-seg on PORTB, dp on bit 7 seg a on bit 0 MOVLW b'00111111' MOVWF pincode ; Main loop, while PIN is wrong say ENTER PIN CLRF count ; char count MOVLW b'10000000' MOVWF entry ; first entry flag set main_loop MOVF count, W CALL table1 ANDLW 0x0FF ;test if at end of message BTFSC STATUS, Z GOTO disp_done MOVWF PORTB ; Display char CALL del500ms ; delay INCF count, F BTFSC PORTA, 0 ; Enter key, switch 5 GOTO main_loop ; MOVF PORTA, W MOVWF temp MOVLW 0x03A ; Debounce switch CALL del_xW ; delay of ~ 30 ms BTFSC entry, 7 ; first or second press of enter ? GOTO first MOVLW b'00001110' ANDWF temp, F ; mask RLF temp, F ; shift left 1 bit RLF temp, W ; shift left 1 bit IORWF entry, F MOVF entry, W CLRF count SUBWF pincode, W BTFSS STATUS, Z GOTO denied ; accepted MOVF count, W CALL table2 ANDLW 0x0FF ;test if at end of message BTFSC STATUS, Z GOTO code_done MOVWF PORTB ; Display char CALL del500ms ; delay INCF count, F GOTO accepted ; Do all chars ; denied MOVF count, W CALL table3 ANDLW 0x0FF ;test if at end of message BTFSC STATUS, Z GOTO code_done MOVWF PORTB ; Display char CALL del500ms ; delay INCF count, F GOTO denied ; Do all chars ; code_done CALL del500ms CLRF count MOVLW b'10000000' MOVWF entry ; first entry flag set GOTO main_loop ; first MOVLW b'00001110' ANDWF temp, F ; mask RRF temp, W ; shift right 1 bit MOVWF entry ; clears first flag bit GOTO main_loop ; Keep displaying message ; disp_done CLRF count GOTO main_loop ; del_xW movwf delaytemp2 ; delay 256 cycles * W clrf delaytemp1 ; min delay ~ 512us max ~ 131072us = 0.131 s del_loop decfsz delaytemp1, f ;delay time = goto del_loop ;msd * ((3 * 256) + 3) * tcy decfsz delaytemp2, f ; goto del_loop ;Actual delay time is 925 us return ; del500ms MOVLW 0x03 MOVWF delaytemp3 ; 4 loops del_loop2 MOVLW 0x0C3 ; 195 loops ~ 100ms * 5 = ~500ms CALL del_xW ; Delay routine DECFSZ delaytemp3, F GOTO del_loop2 RETURN ; Return from routine END ; directive 'end of program' Here are some pictures of the project built on an RMIT prototype board:
Copyright © 1999-2000 Wesley Moore, S9906768@student.rmit.edu.au (last updated 13 Apr, 2000) URL: http://minyos.its.rmit.edu.au/~s9906768/pic/proj_lock.html |