Code Lock
Code Lock
1.0 INTRODUCTION
uor the other the activities of human beings in all field of their endeavours.
and new methods are also being developed. This has permitted the
The ancient Egyptians have since used security locks to protect their
belongings. The Egyptian security lock had a wooden bolt with holes in it.
When it was locked, wooden pegs fell into the hole. The turning of a key
raised the pegs and allows the bolt to be withdrawn. The warded lock made
by the ancient Romans has a number of barriers that the key must pass
through before it unlocks the lock. The level trumbler lock on the other hand
has levers that must be raised to a certain height before it unlocks. All these
1
The advancement in electronic technology, especially in security and
systems.
low cost and among them is the micro controller based sliding door.
These new and more reliable modules are conceived and implemented.
microcontroller based sliding door system used to lock and unlock a safe,
but its use can be extended to other locking systems such as; doors etc.
The high level of burglary and insecurity in the society, makes the
1.3 OBJECTIVES
2
This work will make or bring the issue of burglary and insecurity to a
minimum level not only that, the programmable sliding door will make the
1.5THESIS OUTLINE
3
This study comprises of five different chapters arranged sequentially.
Chapter one gives a brief history of the various forms of locks and
Chapter four presents the results and discussions drawn from tests
performed on the system, while the last chapter gives a conclusion and
4
CHAPTER TWO: THEORETICAL BACKGROUND
2.1 INTRODUCTION
5
2.2 POWER SUPPLY UNIT
The power supply unit is the unit that energizes all other units of the
line to D.C voltage. In this design, 12V and 5V D.C voltage levels are
required for all the system units. The process for the conversion of A.C
1. Step-down transformer.
2. Rectifier.
3. Filter.
4. Voltage Regulator.
6
T1
10TO1
V1 N1 N2 V2
2.2.2 Rectifier
7
Terminal 1
240/15V D4 D1
D3 D2
Terminal 2
+
C1
2.2.3 Filter
8
Fig. 2.4: Rectified and Filtered Output
(2.0)
Equation (i) refers to the relationship between the filter capacitor and
Where,
regulator
Supply frequency
9
In order to keep the terminal voltage of the DC supply constant, a
voltage regulator was used. The regulators used were 7812 and 7805 since
12V and 5V respectively are needed for the system operation. It maintains a
constant DC supply even when there is a variation of the AC input from the
D1
240/15V BRIDGE
50Hz
78L12
IN OUT
COM
78L05
+
C1 IN OUT
COM
The control unit consists of the microcontroller pic 16f84A chip. The
10
Fig 2.6 Pin Diagram of PIC16f84A
11
Fig 2.7 PIC16F84A Block Diagram
Flash memory is used to store the program. One word is 14 bits long
and 1024 words (1kbyte words ) can be stored. Even if power is switched off
the contents of the flash memory will not be lost. Flash memory can be
12
written to address using the writer, but the number of times it be rewritten is
(Watchdog Timer) or any other factor, the program will start from this
address.
13
The basic operation of the PIC is specified at this memory location. The
enable bits of the Power-up timer, and the Watch-dog timer as well as the
oscillator selection bits are set here. This area is behind the usual program
area and can not be accessed by the program. These parameters must be
specified using the burner when burning the program into flash memory.
access this memory. Each bank has a memory capacity of 80 bytes (00h-
4Fh). The PIC16F84A has two banks. This memory is divided into two
sections. The first 12 bytes (00h-0Bh) of each bank are called SFR (Special
Function Registers) and are used to record the operating states of the PIC,
the input/output (I/O) port conditions and other conditions. There are 16
different registers in the SFR (11 in bank 0 and 5 in bank1). The content of
each register is managed by the PIC. Although there are a total of 24 file
registers, several of them are in both banks. The remaining 68 bytes (0Ch-
4Fh), from byte 13 upward, are called GPR (General Purpose Registers) and
can be used to temporally store results and conditions while the program is
running. The contents of the GPR are the same in both banks, so even with
bank switching the total capacity is only 68 bytes. The contents of the GPR
are lost when the power is switched off. There is no limit to the number of
14
2.3.2 EEPROM (Electrically Erasable Programmable Read Only
Memory)
turned off. The memory contents can be rewritten by the program. The total
to about one million. For this reason it is not recommended for temporary
data storage. It is used to store data which will not change frequently.
bank switching technique. Fig. 2.9 shows the RAM File Registers. The
memory capacity is only 160 bytes. The contents of the registers with the
left pointing arrow are the same on both banks. The other registers of the
SFR are accessible through bank switching, and the gray colored registers
15
Fig. 2.9: SFR Register
16
2.3.4 Program Counter
executed, and the location of the following instruction is shown in the PC.
But when a jump is executed the contents of this counter is rewritten to that
The stack stores the program return address when a jump is executed.
For example if the same instructions are to be executed more than once, a
subroutine and the program continues were it left off. A CALL instruction
after the CALL) is stored at the top of the stack. This operation is sometimes
RETURN instruction is executed, the address at the top of the stack is put in
sometimes called a POP. This way multiple subroutines can be called and
17
the processing will return to the part of the program which called the
subroutine. Since there are eight stack registers, eight subroutine calls can be
made sequentially. After the eighth, a call will roll the contents of the eighth
(and last register) back to the top of the stack. When a return is executed, the
PC will send the program to the wrong address, and the program will not
work properly. For this reason only eight sequential subroutines calls can be
made.
18
2.3.5 Instruction Register
2.3.6 W Register
This Register stores the result of the ALU (Zero, positive or negative),
19
FSR (File Select Register) is used to specify the address of the RAM file
register when using the indirect addressing method. In the direct address
case a 7 bit address, from 0 to 127, can be specified. This range is for one
bank. To change the bank, the RP0 bit of the status register must also be
specified. Since the FSR is 8 bits, it is possible to specify the address and
bank at the same time, saving instruction cycles. In the PIC16F84A memory
locations 80 (50h) to 127 (7Fh) are not installed. When using the FSR it is
convenient to make the file register data area continuous. Incrementing the
2.3.10 EEDATA
EEPROM.
2.3.11 EEADR
eight bits addresses from 0 to 255 can be specified. The PIC16F84A has
20
2100h.
2.3.12 Timer
The PIC16F84A has only one timer (TMR0, an 8 bit timer). It times out
when the count reaches 256 and the TOIF bit of the INCON register of the
interrupt occur. The interrupt will stop the processing which was in progress
at that time. To make the interrupt occur the GIF and the TOIE bits of the
There are 13 I/O pins, with individual direction controls. The mode
(input or output) of each pin can be set from within the program. The 13 pins
are divided into two groups. The A Port has five pins and the B Port has
eight. There is a limitation on control timing, but each of the 13 pins can be
individually controlled.
Timing Generation
21
This circuit generates the clock pulses which determine the speed of
resonator is used. Generally the circuitry is simpler with the resonator, which
can also be [Link] PIC16F84A executes one instruction (one cycle) every
four clock pulses, using pipeline architecture. But when a JUMP is executed
two cycles are necessary (8 clock pulses). With a 20MHz clock the
22
immediately after power on. This timer is used to recover
program.
2.4.1 Transistor
p or n region to a p-n junction diode. With two n-regions and one p-region,
two junctions are formed and it is known as an NPN transistor. The common
NPN
2.4.2 Relay
23
This is an electromagnetic switch having an electromagnetic coil with
specified current flows through it. The contact remains in the same position
until the current falls below the holding value at which point the contact
shown below;
CONTACT
COIL
2.4.3 DC Motor
(2.1)
24
The schematic representation of a DC motor is shown below;
reverses the direction of rotation. Thus, the motor was connected in the
switching unit to lock and unlock the safe when its supply current is
2.5 KEYPAD
pulse for some duration T which is use to switch a relay that supplies the
power to the alarm. A 555 timer in the mono stable mode has this capability.
25
time delays, or oscillation. For operation as a one shot (mono stable mode),
The alarm is also 555 timer in astable mode used as atone generator. A
555 timer connected to operate as an astable multivibrator which is free
running non-sinusoidal oscillator is shown in figure 2.3 below
26
Vcc
R1
4 8
R2 3
6
5
2 0.01µF
1 (Decoupling Optional)
C1
From the figure above, the threshold input is connected to the trigger
input. The external components R1, R2 and C1 form the timing network that
sets the frequency of oscillation. The 0.01µf capacitor C 2 connected to the
control input is strictly for decoupling and has no effect on the operation, so,
in some cases it can be left off.
pulse for some duration T (about 1 minute) which is use to switch a relay
that supply the power to the motor. A 555 timer in the mono stable mode has
27
(mono stable mode), the frequency is accurately controlled with external
hours, and generates pulse over a wide range of frequency. The 555 is shown
mechanism of the 555, the timers will always time-out once triggered,
regardless of any subsequent noise (such as bounce) on the input trigger (pin
2). This is a great asset in interfacing the 555 with noisy sources. Just in case
you don't know what 'bounce' is: bounce is a type of fast, short term noise
caused by a switch, relay, etc. and then picked up by the input pin.
The trigger input is initially high (about 1/3 of +V). When a negative-going
trigger pulse is applied to the trigger input, the threshold on the lower
That causes T1 to cut off, acting as an open circuit. The setting of the flip-
flop also causes a positive-going output level which is the beginning of the
28
The capacitor now begins to charge through the external resistor. As soon as
the charge on the capacitor equal 2/3 of the supply voltage, the upper
comparator triggers and resets the control flip-flop. That terminates the
output pulse which switches back to zero. At this time, T 1 again conducts
reset input while the output pulse is high, it will be terminated immediately
external resistance and capacitance used, the output timing pulse may be
29
CHAPTER THREE: DESIGN AND IMPLEMENTATION
3.1 INTRODUCTION
and how the program was implemented to control the design and perform
3.2.1 Transformer
The system input resistance is about 200Ω, therefore the expected load
current is
A transformer with the current rating of 500mA which is greater than load
current was used. Thus the power rating of the transformer was completed to
be
S = VI = 12 X 500 mA = 6VA
30
3.2.2 Rectifier
Terminal 1
240/15V D4 D1
D3 D2
Terminal 2
+
C1
This is made up of capacitor connected across the out put of the rectifier to
smoothen the voltage to have the minimum ripple factor (at least 10% of the
Vripple = 0.1Vpeak
Vripple = 0.1 × 16.97
Vripple = 1.697V
But also Vripple = I/2fC for full wave
Where; I = current taken by the load
f = frequency of supply
C = filtering capacitor
31
C = I /2fVripple
= 0.17/ (2 × 50 × 1.697)
C = 1001.7µF
From this calculation, a standard capacitor of 2200µF was chosen.
The regulator is a single chip that regulates the ripple free rectified
voltage to give a constant out put voltage. Since the circuit needs a supply
voltage of 12V and 5V, a 12V and 5V regulators were used. The percentage
regulation or simply regulator of a power supply is given by:
% regulation = [(Vmax – Vmin)/Vmax] × 100
Where;
Vmax = maximum dc output voltage
Vmin = minimum dc output voltage
In a general form
% regulation = [(Vno load – Vfull load)/Vfull load] × 100
DEVICE OVERVIEW
32
instructions, since each 14-bit program memory word is the same width as
each device instruction. The data memory (RAM) contains 68 bytes. Data
EEPROM is 64 bytes. There are also 13 I/O pins that are user-configured on
a pin-to-pin basis. Some pins are multiplexed with other device functions.
• External interrupt
into W or f.
Result in W or f.
33
DECF f, d Decrements selected register. Result in W or f.
left.
or f.
right.
or f.
register. Result in W or f.
34
RETLW k Return from subroutine. Load W with
literal.
instruction if register = 0.
Result in W or f.
instruction if register = 0.
Result in W or f.
Nothing
Control Microcontroller
watchdog timer
35
OPTION W contents (bit pattern) sent to option register.
power consumption.
Logic SUBWF f,
ANDLW k W & k W. d f - W W or f.
ANDWF f, d W & f W or f.
IORLW k W || k W.
IORWF f, d W || f W
or f.
XORLW k W xor k W.
XORWF f, d W xor f W or f.
Arithmetic
ADDLW k W + k W.
ADDWF f, d W + f W or f.
SUBLW k k - W W.
36
37
There are two memory blocks in the PIC16F84A. These are the program
memory and the data memory. Each block has its own bus, so that access to
each block can occur during the same oscillator cycle. The data memory can
further be broken down into the general purpose RAM and the Special
Function on each individual peripheral module. The data memory area also
contains the data EEPROM memory. This memory is not directly mapped
unto the data memory, but is indirectly mapped. That is, an indirect address
pointer specifies the address of the data EEPROM memory to read/write. The
the physically implemented address will cause a wraparound. For example, for
38
locations 20h, 420h, 820h, C20h, 1020h, 1420h, 1820h, and 1C20h, the
The data memory is partitioned into two areas. The first is the Special
Function Registers (SFR) area, while the second is the General Purpose
Registers (GPR) area. The SFRs control the operation of the device. Portions
of data memory are banked. This is for both the SFR area and the GPR area.
39
The GPR area is banked to allow greater than 116 bytes of general purpose
RAM. The banked areas of the SFR are for the registers that control the
peripheral functions. Banking requires the use of control bits for bank
selection.
These control bits are located in the STATUS Register. Figure 2-2 shows the
data memory map organization. Instructions MOVWF and MOVF can move
values from the W register to any location in the register file (“F”), and vice-
versa. The entire data memory can be accessed either directly using the
absolute address of each register file or indirectly through the File Select
Register (FSR). Indirect addressing uses the present value of the RP0 bit for
access into the banked areas of data memory. Data memory is partitioned into
two banks which contain the general purpose registers and the special function
the RP0 bit selects Bank 1. Each Bank extends up to 7Fh (128 bytes). The first
twelve locations of each Bank are reserved for the Special Function Registers.
The EEPROM data memory is readable and writable during normal operation
(full VDD range). This memory is not directly mapped in the register file
Registers. There are four SFRs used to read and write this memory. These
registers are:
41
• EECON1
• EEDATA
• EEADR
EEDATA holds the 8-bit data for read/write, and EEADR holds the address
of data EEPROM with an address range from 0h to 3Fh. The EEPROM data
memory allows byte read and writes. A byte write automatically erases the
location and writes the new data (erase before write). The EEPROM data
memory is rated for high erase/write cycles. The write time is controlled by an
on-chip timer. The write time will vary with voltage and temperature as well
as from chip to chip. Please refer to AC specifications for exact limits. When
the device is code protected, the CPU may continue to read and write the data
memory.
To read a data memory location, the user must write the address to the
EEADR register and then set control bit RD (EECON1<0>). The data is
available, in the very next cycle, in the EEDATA register; therefore, it can be
42
read in the next instruction. EEDATA will hold this value until another read
To write an EEPROM data location, the user must first write the address to
the EEADR register and the data to the EEDATA register. Then the user must
The PIC16F84A can be operated in four different oscillator modes. The user
can program two configuration bits (FOSC1 and FOSC0) to select one of
• XT Crystal/Resonator
• RC Resistor/Capacitor
The PIC16F84A oscillator design requires the use of a parallel cut crystal. Use
of a series cut crystal may give a frequency out of the crystal manufacturers
OSC1/CLKIN pin.
44
table. Higher capacitance increases the stability of the oscillator, but also
increases the start-up time. This circuit was operated in the HS mode and thus
known as the programmer. The program and Hex code is given in appendix.
3.5.1 Assembler
The assembler used for this project is the MPLAB version 5.7 which was
development environment (IDE) software which gives support for the PIC and
tool bar and key mapping, status bar with project information.
MPLAB allows you to edit your source files (either in assembly or ‘C’).
Source files
This was used to burn the hex files into the PIC. This programmer has the
facility to program a PIC 16F84, erase the EEPROM, and also verify the
R19
C945
Where, , and
47
12V
Vs
R1 J1
VCC NO
RST OUT D1
1N4009 NC
DI S Key = Space
THR
555_VIRTUAL Rl
SI GNAL FROM THE SENSOR TRI
Timer
CON Q1
GND
C Cf BJT_NPN_VIRTUAL
Whenever a trigger pulse is applied to the input, the 555 will generate
resistance and capacitance used, the output timing pulse may be adjusted from
standard logic one-shots designed for narrow pulses be used instead of a 555
timer. IC timers are normally used where long output pulses are required. In
48
equal to:
R1
VCC
THR
TRI
R2
CON
GND
555_VIRTUAL
Timer
C Cf
(3.0)
MECHANICHAL PART
50
4.1 INTRODUCTION
This chapter deals with the description of tests performed on the various
sections of the overall system and their corresponding results as well as the
result of the overall system. In order to verify the correct functionality of the
effective testing of these various components, the following tools were used:
Digital multimeter
Bread board
Logic probe
The testing was done on each and every components/sections that make up the
circuit to ensure proper and satisfactory operation of the safe lock. The
debugging was done using the MPLAB; Each and every section of the code
was done. This is a facility in the MPLAB that enables you step into program
and at the same Time views the registers and flag settings.
51
The whole system was tested with various trials of six digit numbers
unlock the door as required. The code can be changed to the desired digital
example. The close button is used to turn on the DC motor in reverse mode to
lock the safe as required. The touch activated alarm is being activated by any
small induced current on the touch plate to alert burgling attempt as expected
and the wrong pin alarm deactivated the whole system in any attempt of
hacking as required.
The power supply unit of +5V and +12V were tested for the output
Under no-load, the voltage of the +5V supply section was measured to
be 4.95V while that of the +12V supply was measured to be 11.94V. At full-
Where,
No-load Voltage
Full-load Voltage
% %
% %
From the results obtained above, the performance of the power supply
is satisfactory.
53
RECOMMENDATION
5.1 CONCLUSION
system that can be used to lock and unlock a safe but its use can be extended
to other electronic locking systems such as doors. Having realized the device
and found working properly based on its design and relatively cheap
components involved in its realization, the aim of the project can be said to be
5.2 RECOMMENDATION
The project was designed to describe fully the locking and unlocking of
REFERENCE
Boylestad, R.L and Nashelsky, L. (1996). Electronic Devices and
Circuit Theory, Prentice Hall, London.
[Link]
55
APPENDIX A
Flow Chart
START
ENTER
THE
PASSWORD
NO
NO
IS THE IS
PASSWORD N=4
RIGHT
YES YES
END
56
APPENDIX B
Microcontroller circuit arrangement
57
APPENDIX C
; CODELOCK program
Author: Abubakar Ibrahim Musa
Supervisor: Engr. (Dr.) G.A Bakare
;=============================================
; HARDWARE
;=============================================
; Keyboard connections
;
; RB0 = scanline 0
; RB1 = scanline 1
; RB2 = scanline 2
; RB3 = returnline 0
; RB4 = returnline 1
; RB5 = returnline 2
; RB6 = returnline 3
;(key = 3 x returnline (0,1,2,3) + scanline (0,1,2)
;
; RA2 = BEEPER active low
;
;RA3 = LED active low
;
; RA0 = level output
; RA1 = pulse output
;
;
;
;============================================
; Configuration
;============================================
PROCESSOR 16c84
__CONFIG RC+CPOFF+PWRTE
58
;============================================
; Constants
;============================================
;general
w equ 0
f equ 1
indf equ 00h ;indirect file
fsr equ 04h ;pointer to indirect file
ram equ 0ch ;rambottom (start)
status equ 03h ;status register file
porta equ 05h ;port A
portb equ 06h ;port B
;============================================
; macro definitions
;============================================
jz macro lab1
btfsc status,zero
goto lab1
endm
jc macro lab3
btfsc status,carry
goto lab3
endm
;============================================
; setbank
;============================================
setbank macro banknr
if banknr == 0
bcf status,rp0
endif
if banknr == 1
bsf status,rp0
endif
endm
;============================================
; portio
60
;
; sets tris of port
; usage: portio porta,b'10010011' ;example
; 0 is output, 1 is input
;============================================
portio macro portnr,io
clrf portnr
setbank 1
movlw io
if portnr == porta
movwf trisa
endif
if portnr == portb
movwf trisb
endif
setbank 0
endm
;============================================
; program constants
;============================================
;============================================
; variables
;============================================
org ram
;============================================
; reset addres
;============================================
org 0
goto start
;============================================
; identify interrupt source
;============================================
org 4
goto interrupt
;============================================
; rdeeprom
; reads byte from eeprom
; entry EEADR, exit EEDATA
;============================================
rdeeprom:
bsf status,rp0
bsf eecon1,rd
bcf status,rp0
return
62
;============================================
; wreeprom
;
; writes a byte of data to eeprom
;
; entry: eedata,eeadr
;============================================
wreeprom:
;write sequence
movlw 55h
movwf eecon2
movlw 0aah
movwf eecon2
bsf eecon1,wr ;begin write
waitwr:
btfsc eecon1,wr
goto waitwr ;wait for writecycle complete
return
;============================================
; interrupt routines
;============================================
interrupt:
retfie
;============================================
;
;============================================
63
;============================================
; Init
;============================================
init:
portio porta,b'00000'
portio portb,b'11111000'
movlw 7h
movwf portb ;set keyboard scanlines
movlw 1
movwf newkey
clrf tries
movlw 6
movwf eeadr ;first signature adress
call rdeeprom
movlw 0AAh
subwf eedata,w
jnz nosig
incf eeadr
call rdeeprom
movlw 055h
subwf eedata,w
jnz nosig
64
incf eeadr
call rdeeprom
movlw 0CCh
subwf eedata,w
jnz nosig
clrf eeadr
movlw 1
movwf eedata
wrcod:
call wreeprom
incf eedata
incf eeadr
movlw 6
subwf eeadr,w
jnz wrcod
movlw 0AAh
movwf eedata
call wreeprom
incf eeadr
movlw 055h
movwf eedata
call wreeprom
incf eeadr
movlw 0CCh
movwf eedata
call wreeprom
return
65
;============================================
; beep
; beeps 50mS
;============================================
beep:
bcf porta,2
movlw .5
movwf del10
call delay10
bsf porta,2
return
;============================================
; delay10
; delays del10 x 10mS
;============================================
delay10:
;delayloop 10 mS
movlw .40
movwf del1
dec250u:
;delayloop 250 uS
movlw .83
movwf del0
dec1u:
decfsz del0
goto dec1u
decfsz del1
goto dec250u
decfsz del10
goto delay10
return
;============================================
delay macro dly00
movlw dly00
movwf del10
66
call delay10
endm
;============================================
; scankeyboard
; scans the keyboard
; returns scankey = 1..12, 0ffh = nokey
; scankey is nokey if no key is pressed
; scanlines = RB0..RB2
; returnlines = RB3..RB6
;============================================
scankeyboard:
;find scanline
movlw 0
movwf portb
clrf scanln
bsf portb,0
nop
movf portb,w
andlw b'01111000'
jnz retl
incf scanln
bsf portb,1
nop
movf portb,w
andlw b'01111000'
jnz retl
incf scanln
bsf portb,2
nop
movf portb,w
andlw b'01111000'
jnz retl
goto nokeyp ;no keypress
movf portb,w
movwf retval
rrf retval
rrf retval
rrf retval
nxtrl:
bcf status,carry
rrf retval
jc keyfound
incf retln
movlw 4
subwf retln,w
jnz nxtrl
keyfound:
incf scankey
return
;============================================
; getkey
; exits key:1..12,nokey
; debounced filtered output
;============================================
68
getkey:
call scankeyboard
movf scankey,w
movwf key
movlw .2
movwf del10
call delay ;delay 20mS
call scankeyboard
movf scankey,w
subwf key,w
jnz getkey
;debounce complete
movlw nokey
subwf key,w
jnz exitkey
movlw 1
movwf newkey ;next key is new
goto pkey
exitkey:
movlw 1
subwf newkey,w
jnz pkey
clrf newkey
return
call getkey
movlw nokey
subwf key,w
jz readkey
call beep
return
;============================================
; main program
;============================================
start:
call init
call beep
rdkey:
call readkey ;wait for key
;key pressed
movlw sterretje
subwf key,w
jnz rdkey
; '*' pressed
nxkey0:
call readkey
movlw sterretje
subwf key,w
jz deactivate ;'**' pressed, deactivate ouput, restart input
movlw hekje
subwf key,w
jz getcode ;'*#' goto new code input
movlw 6
movwf digit ;digit count, 6
movlw 1
movwf match ;code match to input flag
clrf eeadr ;start with eeprom adress 0
rdee:
call rdeeprom
movf eedata,w
subwf key,w ;compare stored codedigit to key
jz eq00
clrf match
eq00:
decfsz digit
goto nxtdg00
;6 digits compared
btfss match,0
goto nomatch0 ;no match, do nothing, return to input start
;pulse 1 sec
;beep 1 sec
bcf porta,2
bsf porta,1 ;set pulse
delay .100
bcf porta,1
bsf porta,2
goto rdkey
deactivate:
bcf porta,0 ;deactivate output
; bsf porta,3 ;LED off
goto nxkey0
71
nxtdg00:
call readkey ;wait for key
;key pressed
movlw sterretje
subwf key,w
jz nxkey0 ;restart input
movlw hekje
subwf key,w
jz rdkey ;restart input
;digit pressed
incf eeadr
goto rdee
nomatch0:
;wrong accescode entry
incf tries
movlw 4
subwf tries,w
jnz nomatch
alarm:
call beep ;50mS
delay .15 ;150ms
call beep ;50
delay .15 ;150
call beep ;50
delay .55 ;550mS
decfsz digit
goto alarm
goto rdkey
72
nomatch:
;beep 3x
delay .30
call beep
delay .10
call beep
delay .10
call beep
goto rdkey
getcode:
;'*#' pressed, get new accescode
;format = '*#ooooonnnnnmmmmm'
;o = oldcode,n = newcode, m = newcode verification
movlw hekje
subwf key,w
jz nomatch ;error in input
call rdeeprom
movf key,w
subwf eedata
73
jz match00
clrf match ;mismatch in input
match00:
incf eeadr
decfsz digit
goto gtdg00 ;read next
movlw 6
movwf digit
movlw ncode0
movwf fsr ;point to first digit
rdnc00:
call readkey ;wait for key
movlw sterretje
subwf key,w
jz nxkey0 ;'*' pressed, restart input
movlw hekje
subwf key,w
jz nomatch ;error in input
movf key,w
movwf indf
incf fsr
decfsz digit
goto rdnc00
movlw 6
movwf digit
movlw ncode0
movwf fsr ;point to saved code
74
rdvc00:
call readkey ;wait for key
movlw sterretje
subwf key,w
jz nxkey0 ;'*' pressed, restart input
movlw hekje
subwf key,w
jz nomatch ;error in input
movf indf,w
subwf key,w
jz mok
clrf match ;key and saved digit differ, no match
mok:
incf fsr
decfsz digit
goto rdvc00
btfss match,0
goto nomatch ;input mismatch, error signal, restart input
;long beep
bcf porta,2
delay .100
bsf porta,2
movlw 6
movwf digit
movlw ncode0
movwf fsr
clrf eeadr
store00:
movf indf,w
75
movwf eedata
call wreeprom
incf fsr
incf eeadr
decfsz digit
goto store00
;============================================
; eeprom definition
;============================================
org 2100h
de 0,0,0,0,0,0,0,0,0
end