Combination lock on the peak controller. Combination lock on the microcontroller AVR ATTINY2313

I work as an electrician in the Far North. In winter, we always had a problem, the lock at the entrance to the electrical shop freezes. And then the magazine "Radio" No. 5 for 2008 caught my eye. There was published an article by E. Pereverzev "Digital Combination Lock".

Decided and done. Redrawn a seal from a magazine. Soldered the diagram.
I uploaded the firmware and the circuit worked immediately, although this is my first circuit on a microcontroller.

About my build

The diagram shows a battery, but I did not install it.
The lack of electricity in the electrical shop is nonsense, but I took into account the battery on the signet.
The file "1.hex" is the flash firmware, the file "2.hex" is the EEPROM firmware.
The opening code "1, 2, 3" is initially entered into the EEPROM. The code is changed on the open lock, after pressing the "#" button. The code can contain up to 125 characters.

Signet version from the article by E. Pereverzev

The circuit itself, the “Opening”, “Closing” buttons, the power supply was placed to the box from under the control unit of the vacuum circuit breaker.

Power supply used from an old scanner.
I used the solenoid from an old electrical laboratory, one minus - the solenoid consumes 1.5 A.

I took the keyboard from an old phone.


Rubber contacts had to be removed, because they will not work in the cold. In their place, I put SWT-9 buttons. It is not yet possible to install the lock (cold). But the scheme is fully functional.

--
Thank you for your attention!
Igor Kotov, editor-in-chief of Datagor magazine

Original article from "Radio":
🕗 20/12/11 ⚖️ 512.66 Kb ⇣ 111 Hello reader! My name is Igor, I'm 45, I'm a Siberian and an avid amateur electronics engineer. I came up with, created and maintain this wonderful site since 2006.
For more than 10 years, our magazine exists only at my expense.

Good! The freebie is over. If you want files and useful articles - help me!

The device is designed to protect rooms, cabinets and safes from unauthorized opening.

All settings and code are stored in the non-volatile memory of the microcontroller.

This simple scheme is quite within the power of many radio amateurs.

A well-thought-out algorithm of work will give you the pleasure of operating this scheme.

The device is based on a microcontroller. PIC16F628A(DD1 in the diagram of Fig. 1).

After power is applied, the microcontroller program configures its ports, and also disables the reference voltage source, the SHI / comparison capture module, timers, comparators and hardware USART - these modules are not needed for the lock to work. Then the keyboard polling starts. It consists of two parts. The first - buttons SB3-SB14 - is located outside the protected object. The second - buttons SB1, SB2 and switch SA1 - is located indoors. Buttons SB3-SB 13 of the first part of the keyboard are combined into a matrix. The SB 14 button is not included in the matrix, it is designed to restart the microcontroller in case of any failure in the program, as well as in a number of other cases, which will be discussed below.

Button SB1 "Open" is installed indoors near the door. By pressing it, you can open the door from the inside without dialing the code. SB2 - program restart button; buttons SB2 and SB And connected in parallel. Matrix buttons are assigned designations: SB3 - "1", SB4 - "4", SB5 - "7", SB6 - "Open". SB7 - "2", SB8 - "5", SB9 - "8", SB10 - "O", SB11 - "3", SB12 - "6". SB13 - "9". The SAI toggle switch selects the lock closing mode. The code is entered by alternately short-term pressing the number buttons. In confirmation of pressing, a short tone signal of the piezo emitter HA1 will sound. controlled by transistor VT2.

Before opening the door, a four-digit code is entered with pauses between adjacent presses of no more than 3 s. and then within 3 s it is necessary to briefly press the SB6 button. After 2 s, the RAO output of the DD1 microcontroller will go high, the VT1 transistor will open and the electromagnet will work!, which will set the lock bolt in motion, compressing its spring, and the door will open.

If the pause between adjacent pressings exceeds 3 s, then a signal will sound with a decreasing frequency. This means that the program has started to run again and the code must be entered from the beginning. Diode VD1 is designed to protect the transistor VT1 from a voltage surge of self-induction of the electromagnet winding Y1. Before the electromagnet is triggered, a signal will sound with the same frequency as when pressing the number keys, but for a longer duration, which signals the opening of the door.

When the SA1 switch contacts are open, the electromagnet will close the lock after a certain time (default - 12 s). This time is set when programming the microcontroller. In the program that will need to be loaded into the controller, in the field for working with EEPROM, in the cell with the address 0x06 (seventh in a row), you must insert a number from 0x01 to OxFF, at the rate of 1 unit = 2.5 s. The minimum possible pause is 2.5 s, the maximum is 10 minutes.

If the contacts of the SA1 switch are closed, i.e., a low level is set at the RA4 input of the DD1 microcontroller, then the lock is closed after pressing the SB 14 button or SB2. After the transistor VT1 closes, the electromagnet will de-energize and the lock spring will push the bolt back - the door will be locked again.

To open the door from inside the room, press the SB1 button and hold it until the electromagnet is triggered, which will be indicated by a 2 s tone signal. You can open the door from the inside at any time. If the door does not open, you must press the SB2 button (restart the program) and press the SB 1 button again.

When it is necessary to change the code, the old one is first entered in the same way as during the door opening operation, but then the SB6 button is not pressed briefly, but held until three tones are heard. Then you must immediately release the SB6 button, enter a new four-digit code and immediately press the SB6 button again to confirm the entry. Next, a signal will sound with increasing frequency, which will notify that the new code has been accepted. It is stored in the first four cells of the non-volatile memory of the microcontroller DD1.

The device is equipped with a locking system. Each time you enter an incorrect code, the lock will play two beeps at 1000 Hz and one at 500 Hz. The controller considers it erroneous to press the SB6 button at a time when the wrong code is in the working registers and enter five digits of the code. After three errors in a row, the DD1 microcontroller will set the RA2 output to a high level. This will open the transistor VT3, which will turn on the alarm device. This device can be a siren or a telephone dialer.

At the same time, the HL1 LED installed on the keyboard panel will turn on, which will show that the keyboard polling (except for the SA1 toggle switch and the SB1, SB2, SB14 buttons) is disabled. This is followed by a ten-minute pause, during which the alarm device works and the HL1 LED is on. During this time, the lock can only be opened from the inside. If you press the buttons SB 14 and SB2 (buttons for restarting the microcontroller program), then the ten-minute countdown will start again. After the pause, the controller will provide only one opportunity to enter the code, and if it is incorrect, the ten-minute pause with the activation of the alarm device will be repeated again. And so it will continue until the correct code is entered. Each time after the correct code is entered, the error counter is reset to zero.

The device is powered by a DC source with a voltage of 10...15 V. In the event of a power outage in the 220 V network, the lock continues to operate from the battery. A diagram of the simplest version of such a power supply is shown in fig. 2.

Transformer T1 lowers the mains voltage of 220 V to 15 ... 20 V. The maximum current of the secondary winding of the transformer should not be less than 1.5 A. DA1 is an adjustable voltage regulator. By changing the resistance of the construction resistor R2, a voltage is set at the output of the stabilizer DA1, at which the charging current of the charged battery GB1 does not exceed 100 ... 200 μA. At the same time, during high current consumption, when the electromagnet Y1 worked, the main part of the current is provided by the battery, which allows not to overload the stabilizer DA1. Diode VD5 is designed to protect the stabilizer DA1 in the absence of voltage at its input.

The battery must provide a current of 300 ... 600mA (capacity - 7 Ah). Stabilizer DA1 should be installed on a heat sink with an area of ​​30...40 cm2.

The keyboard can be made from individual buttons. Suitable, for example, DIPTRONICS DTSMW-66N. But you can also use a ready-made keyboard from a push-button telephone or calculator. As a rule, you can easily connect such a keyboard to the device by assembling the buttons in a suitable matrix. It is also necessary to put the HL1 LED on the keyboard panel.

The piezo emitter is suitable for any of the ZP series. The electromagnet Y1 is used from the tape drive mechanism of the tape recorder, but any other suitable in size and with a maximum winding current of not more than 1.3 A will do. If the current consumed by the electromagnet is more than 1 A, then the transistor VT1 should be installed on a heat sink with an area of ​​30 .. .40 cm2.

Archive with firmware

A combination lock will help restrict unauthorized persons' access to valuable information. One of the options for implementing a code lock on a microcontroller is given in this article.

The figure below shows a diagram of a code lock. The core of the circuit is the PIC16F628A microcontroller. The algorithm for executing the main commands is shown in Figure 2. The program code is written in assembly language, see listing CL \ 16F628ATEMP.ASM. The device is controlled by one button. Pressing the button achieves a sequential change in the operating modes of the device. The sound accompaniment of pressing the button is provided by a piezo sound emitter. A display with a built-in controller is used for visual display of information.

A full cycle of in-circuit programming and debugging of the PIC16F628A microcontroller was carried out using the (integrated development environment), MPASM v5.22 compiler (included in MPLAB IDE v8.15) and MPLAB ICD 2 (in-circuit debugger - "Debugger"). For those who do not have the above tools, but have their own program for working with HEX files and another programmer, you can find the 16F628ATEMP.HEX file in the corresponding project. The technical specification of the microcontroller can be found on the website and.

The DD1 microcontroller has functional outputs RA0, RB0 - RB7, CCP1, which are used to input and output information. The DD1 microcontroller does not have a forced reset function, the reset pin is connected through a resistor R1 to the positive power potential. An on-chip RC oscillator is used to generate the clock frequency.

The clock button SB1 is connected to the output RA0 through the current-limiting resistor R3. In the depressed position of the clock button SB1, the resistor R7 simulates a low logic level. The DD1 microcontroller recognizes three states of the SB1 clock button:

  1. not pressed;
  2. Pressed briefly (less than 1 s);
  3. Pressed and held (more than 1 s).

Piezo sound emitter P1 helps to distinguish the states of the tact button SB1. So, in state 1, no sound is generated, in state 2, sound is generated until the microcontroller recognizes state 3, and in state 3, no sound is generated.

To display information, a liquid crystal display HG1 is used. The technical specification of the display can be found on the website. It has a controller that implements the character generation function. Displays two lines of sixteen characters each. The display is controlled through the microcontroller pins RB0, RB1, RB4 - RB7. Data loading occurs in nibbles, through pins RB4 - RB7. "Latch" - RB1. The choice of the signal register is formed at the output RB0. Resistors R5 and R6 set the contrast of the display HG1. The backlight of the display is connected to the power supply through the current-limiting resistor R4. The HG1 display is screwed to the board with 3 x 15 mm brass standoffs and 3 x 6 mm screws.

By forming logic on RB2, they achieve the opening or closing of the field effect transistor VT1, which turns on and off the electric lock connected to the X1 terminal block. The electric lock must be designed for an operating voltage of 9-15 V and consume a current of no more than 1 A. When voltage is applied to the electric lock, it must open, in the absence of voltage it blocks (closes).

To the output of CCP1 (hardware implementation of PWM, frequency 4 kHz, duty cycle 2) through the current-limiting resistor R2, a piezo sound emitter P1 with an operating frequency of sound generation of 4 kHz is connected.

The device is powered by an AC or DC voltage source connected to connector X2. The rated voltage of the power supply is 9 - 15 V. The rated current of the power supply is 1 A. To stabilize the power supply, a conventional circuit is used from a diode bridge VD1, a linear stabilizer DA1, filter capacitors C1 - C4.

The device can be operated in the temperature range from -20 °С to +70 °С.
The microcontroller is programmed in such a way that it has eleven operating states.

  1. When the device is turned on, the non-volatile data memory EEPROM is read, where the data of the lock status and code are uploaded. The device opens or closes the electric lock according to the lock status register read. The device goes to the state where it displays the encoding statistics, i.e. 2.
  2. In this state, the device in the upper line displays the inscription “Stat. Stat." and on the bottom line displays encoding statistics, namely the number of encodings and the number of decodings*. After a short or long press of the tact button, the device, guided by the lock state register, enters the coding state if the lock is open, i.e. 3 and enters the decoding state if the lock is closed, i.e. 4.
  3. The device displays the inscription “Code Code” in the upper line of the display and switches to the state where the code is entered (subprogram “Code Entry”), i.e. 5. Increment the counter of the number of encodings. The device goes into a state where it changes the state of the lock, closing it, i.e. 9.
  4. The device displays the inscription “Decode D.code” in the upper line of the display and goes to the state where the code is entered (subprogram “Code Entry”), i.e. 5. Increment the counter of the number of decodes. The device compares the entered code with the code stored in non-volatile EEPROM memory. If the code matches, then the device goes into a state where it changes the state of the lock, opening it, i.e. 10, and if the code does not match, it goes to the state where it displays information about the error, i.e. eleven.
  5. The first digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, the device switches to the state where the second digit of the code is selected, i.e. 6.
  6. The second digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, the device switches to the state where the third digit of the code is selected, i.e. 7.
  7. The third digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, the device switches to the state where the fourth digit of the code is selected, i.e. 8.
  8. The fourth digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, then the device switches to the state from where the “Code Entry” subroutine was requested, i.e. 3 or 4.
  9. The device closes the lock and saves the state of the lock and the code. In the top line displays the inscription "Saving Saving." and a four-digit code on the bottom line. Next, the device goes to the state where it displays the encoding statistics, i.e. 2.
  10. The device opens the lock and saves the lock state and code. In the top line displays the inscription "Saving Saving." and a four-digit code on the bottom line. Next, the device goes to the state where it displays the encoding statistics, i.e. 2.
  11. In the top line displays the inscription "Error Error" and in the bottom line a four-digit code. (Photo 4) After a short or long press of the tact button, the device switches to the state where it displays the encoding statistics, i.e. 2.

*After the counter overflows (greater than 65535), it resets to zero and the count starts again, which leads to a failure in statistics, in the sense that the number of encodings can be greater than the number of decodings. Therefore, it is recommended to de-energize the device to reset the counters.

** When incrementing the number 9, zeroing occurs.

Of course, despite the fact that the microcontroller has EEPROM memory protected from in-circuit reading (specified in the configuration), using MPLAB ICD to read and find out the password in-circuit, and therefore turn on the electric lock, will not work. There remains an easier way to open it - directly apply voltage to the electric lock directly. I conclude that the “combination lock” device and the electric lock must be reliably protected from the penetration of unauthorized persons. The button and display must be freely accessible.

It should be noted that the device can be de-energized, anyway, after entering the code, the state of the lock and the code are stored in the non-volatile EEPROM memory. It is forbidden to de-energize the device while the code is being stored in non-volatile EEPROM memory.

It is worth paying attention to one important detail in the operation of the device. When the device is turned on, it can open the electric lock for a short time (for a time less than 1 s), despite the fact that the closed state of the electric lock is stored in the non-volatile EEPROM memory. When simulating the execution of the program code in the MPLAB IDE environment, this error was not detected by me. In case of an unexpected power failure of the device while the code is being stored in the non-volatile EEPROM memory, the code can be saved incorrectly and it cannot be restored, which will lead to the re-programming of the microcontroller. Hence follows a recommendation about the need for a stable and (or) backup power supply to the device. GB1 - backup power.

See the files for the manufacture of printed circuit boards in the folder.

The following parts can be replaced on this unit. Microcontroller DD1 from the PIC16F628A-I / P-xxx series with an operating clock frequency of 20 MHz in a DIP18 package. The HG1 display will fit any of the WH1602x series. Voltage stabilizer DA1 domestic KR142EN5A (5 V, 1.5 A). Field MOSFET transistor VT1 (N-channel) in the I-Pak package (TO-251AA), an analog of the rating indicated on the diagram is suitable. Piezo sound emitter P1 with an operating frequency of sound generation of 4 kHz. Diode bridge VD1 can be applied to any of the 2Wxx series. Power connector X2 similar to that shown in the diagram with a central contact d=2.1 mm. Non-polar capacitors C1 and C2 with a nominal value of 0.01 - 0.47 µF x 50 V. Electrolytic capacitors C3 and C4 have the same capacitive rating, and the voltage is not lower than that indicated in the diagram.

List of radio elements

Designation Type Denomination Quantity NoteShopMy notepad
DD1 MK PIC 8-bit

PIC16F628A

1 To notepad
DA1 Linear Regulator

L7805AB

1 To notepad
VT1 MOSFET transistor

IRLU024N

1 To notepad
VD1 Diode bridge

2W10

1 To notepad
VD2 rectifier diode

1N5403

1 To notepad
C1, C2 Capacitor0.1uF2 To notepad
C3 470uF 25V1 To notepad
C4 electrolytic capacitor100uF 10V1 To notepad
R1, R6 Resistor

10 kOhm

2 To notepad
R2 Resistor

240 ohm

1 To notepad
R3 Resistor

470 ohm

1 To notepad
R4 Resistor

Electronic locks come in different types, this article presents another interesting option. The difference with this design is that the keyboard uses only one pin of the microcontroller. An ADC is used to determine which button has been pressed. This method can only be used with microcontrollers that have a built-in ADC, PIC12F675 is used in this circuit.

How it works

Press the 4 buttons in sequence and the relay will close the lock circuit for about 5 seconds. But first you need to program the code as follows: press and hold the CODE button until the LED lights up. When the LED lights up, enter your code. After entering the fourth digit, the code will be written to the eeprom, and it will be possible to turn on the relay only using this code. If you make a mistake 10 times when entering the code, the second relay responsible for the alarm will turn on.


Button recognition with ADC

As can be seen from the diagram, the keyboard is assembled from a set of buttons and resistors. The keyboard is connected with only three wires: +5V, ground and a signal wire connected to terminal 7 of the controller. Resistors are connected in series, and each connection point has its own voltage. When we press a button, we apply a certain voltage to pin 7 of the microcontroller. Pin 7 is configured as an input and connected to the ADC module of the controller. The PIC12F675 has a 10-bit ADC and the value range is from 0 to 1023. So if we have 12 buttons, the range between them is 85 units. Button “0” is in the range 0-85, Button “1” 86-170, Button “2” 171-256…etc.

A code lock will help to restrict access of unauthorized persons to rooms with valuables. One of the options for implementing a code lock on the PIC16F628A microcontroller is given in this article.

The figure below shows a diagram of a code lock. The core of the circuit is the PIC16F628A microcontroller. The algorithm for executing the main commands is shown in Figure 2. The program code is written in assembly language, see the listing in the CL \ 16F628ATEMP.ASM folder of the archive with the project. The device is controlled by one button. Pressing the button achieves a sequential change in the operating modes of the device. The sound accompaniment of pressing the button is provided by a piezo sound emitter. A display with a built-in controller is used for visual display of information.

A full cycle of in-circuit programming and debugging of the PIC16F628A microcontroller was carried out using MPLAB IDE v8.15 (integrated development environment), MPASM v5.22 compiler (included in MPLAB IDE v8.15) and MPLAB ICD 2 (in-circuit debugger). For those who do not have the above tools, but have their own program for working with HEX files and another programmer, you can find the 16F628ATEMP.HEX file in the corresponding project.

The DD1 microcontroller has functional outputs RA0, RB0 - RB7, CCP1, which are used to input and output information. The DD1 microcontroller does not have a forced reset function, the reset pin is connected through a resistor R1 to the positive power potential. An on-chip RC oscillator is used to generate the clock frequency.

The clock button SB1 is connected to the output RA0 through the current-limiting resistor R3. In the depressed position of the clock button SB1, the resistor R7 simulates a low logic level. The DD1 microcontroller recognizes three states of the SB1 clock button:

  1. not pressed;
  2. Pressed briefly (less than 1 s);
  3. Pressed and held (more than 1 s).

Piezo sound emitter P1 helps to distinguish the states of the tact button SB1. So, in state 1, no sound is generated, in state 2, sound is generated until the microcontroller recognizes state 3, and in state 3, no sound is generated.

To display information, a liquid crystal display HG1 is used. The technical specification of the display can be found on the website. It has a controller that implements the character generation function. Displays two lines of sixteen characters each. The display is controlled through the microcontroller pins RB0, RB1, RB4 - RB7. Data loading occurs in nibbles, through pins RB4 - RB7. "Latch" - RB1. The choice of the signal register is formed at the output RB0. Resistors R5 and R6 set the contrast of the display HG1. The backlight of the display is connected to the power supply through the current-limiting resistor R4. The HG1 display is screwed to the board with 3 x 15 mm brass standoffs and 3 x 6 mm screws.

By forming logic on RB2, they achieve the opening or closing of the field effect transistor VT1, which turns on and off the electric lock connected to the X1 terminal block. The electric lock must be designed for an operating voltage of 9-15 V and consume a current of no more than 1 A. When voltage is applied to the electric lock, it must open, in the absence of voltage it blocks (closes).

To the output of CCP1 (hardware implementation of PWM, frequency 4 kHz, duty cycle 2) through the current-limiting resistor R2, a piezo sound emitter P1 with an operating frequency of sound generation of 4 kHz is connected.

The device is powered by an AC or DC voltage source connected to connector X2. The rated voltage of the power supply is 9 - 15 V. The rated current of the power supply is 1 A. To stabilize the power supply, a conventional circuit is used from a diode bridge VD1, a linear stabilizer DA1, filter capacitors C1 - C4.

The device can be operated in the temperature range from -20 °С to +70 °С.
The microcontroller is programmed in such a way that it has eleven operating states.

  1. When the device is turned on, the non-volatile data memory EEPROM is read, where the data of the lock status and code are uploaded. The device opens or closes the electric lock according to the lock status register read. The device goes to the state where it displays the encoding statistics, i.e. 2.
  2. In this state, the device in the upper line displays the inscription “Stat. Stat." and on the bottom line displays encoding statistics, namely the number of encodings and the number of decodings*. After a short or long press of the tact button, the device, guided by the lock state register, enters the coding state if the lock is open, i.e. 3 and enters the decoding state if the lock is closed, i.e. 4.
  3. The device displays the inscription “Code Code” in the upper line of the display and switches to the state where the code is entered (subprogram “Code Entry”), i.e. 5. Increment the counter of the number of encodings. The device goes into a state where it changes the state of the lock, closing it, i.e. 9.
  4. The device displays the inscription “Decode D.code” in the upper line of the display and goes to the state where the code is entered (subprogram “Code Entry”), i.e. 5. Increment the counter of the number of decodes. The device compares the entered code with the code stored in non-volatile EEPROM memory. If the code matches, then the device goes into a state where it changes the state of the lock, opening it, i.e. 10, and if the code does not match, it goes to the state where it displays information about the error, i.e. eleven.
  5. The first digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, the device switches to the state where the second digit of the code is selected, i.e. 6.
  6. The second digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, the device switches to the state where the third digit of the code is selected, i.e. 7.
  7. The third digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, the device switches to the state where the fourth digit of the code is selected, i.e. 8.
  8. The fourth digit of the four-digit code is highlighted in square brackets on the bottom line of the display. By briefly pressing the clock button, the register of the entered digit is incremented**. If the tact button is pressed and held for more than 1 s, then the device switches to the state from where the “Code Entry” subroutine was requested, i.e. 3 or 4.
  9. The device closes the lock and saves the state of the lock and the code. In the top line displays the inscription "Saving Saving." and a four-digit code on the bottom line. Next, the device goes to the state where it displays the encoding statistics, i.e. 2.
  10. The device opens the lock and saves the lock state and code. In the top line displays the inscription "Saving Saving." and a four-digit code on the bottom line. Next, the device goes to the state where it displays the encoding statistics, i.e. 2.
  11. In the top line displays the inscription "Error Error" and in the bottom line a four-digit code. (Photo 4) After a short or long press of the tact button, the device switches to the state where it displays the encoding statistics, i.e. 2.

*After the counter overflows (greater than 65535), it resets to zero and the count starts again, which leads to a failure in statistics, in the sense that the number of encodings can be greater than the number of decodings. Therefore, it is recommended to de-energize the device to reset the counters.

** When incrementing the number 9, zeroing occurs.

Since the EEPROM memory (set in the configuration) is protected from in-circuit reading of the microcontroller, it will not be possible to read and find out the password in-circuit, and therefore turn on the electric lock. There remains an easier way to open it - directly apply voltage to the electric lock directly. I conclude that the “combination lock” device and the electric lock must be reliably protected from the penetration of unauthorized persons. The button and display must be freely accessible.

It should be noted that the device can be de-energized, anyway, after entering the code, the state of the lock and the code are stored in the non-volatile EEPROM memory. It is forbidden to de-energize the device while saving the code in the non-volatile EEPROM memory.

It is worth paying attention to one important detail in the operation of the device. When the device is turned on, it can open the electric lock for a short time (for a time less than 1 s), despite the fact that the closed state of the electric lock is stored in the non-volatile EEPROM memory. When simulating the execution of the program code in the MPLAB IDE environment, this error was not detected by me. In the event of an unexpected power failure of the device while saving the code in EEPROM memory, the code can be saved incorrectly and it will not be possible to restore it, which will lead to re-programming of the microcontroller. Hence follows a recommendation about the need for a stable and (or) backup power supply to the device. GB1 - backup power.

See the files for the manufacture of printed circuit boards in the folder.

The following parts can be replaced on this unit. Microcontroller DD1 from the PIC16F628A-I / P-xxx series with an operating clock frequency of 20 MHz in a DIP18 package. The HG1 display will fit any of the WH1602x series. Voltage stabilizer DA1 domestic KR142EN5A (5 V, 1.5 A). Field MOSFET transistor VT1 (N-channel) in the I-Pak package (TO-251AA), an analog of the rating indicated on the diagram is suitable. Piezo sound emitter P1 with an operating frequency of sound generation of 4 kHz. Diode bridge VD1 can be applied to any of the 2Wxx series. Power connector X2 similar to that shown in the diagram with a central contact d=2.1 mm. Non-polar capacitors C1 and C2 with a nominal value of 0.01 - 0.47 µF x 50 V. Electrolytic capacitors C3 and C4 have the same capacitive rating, and the voltage is not lower than that indicated in the diagram.

Download archive with code lock project: 16F628Code_Lock.rar

Share