Code lock on pic16f628a firmware. Electronic combination lock on the PIC12F675 microcontroller

In various amateur radio literature, you can find many options for electronic combination locks.

A feature of this microcontroller combination lock scheme is a fundamentally new method of reading keystrokes using only one port of the PIC12F675 microcontroller. This feature can only be implemented with microcontrollers that include an analog-to-digital converter (ADC) module, such as our PIC12F675 microcontroller.

This microcontroller is equipped with a 10-bit ADC with a conversion range from 0 to 1023. The essence of the method is that the keyboard is, in fact, a voltage divider on resistors R1-R12 and when a certain keyboard button is pressed, a voltage is supplied to input 7 of the microcontroller, the value of which specific to this button.

Combination lock operation on PIC12F675

To write 4 digits of a secret code, you must first press the “CODE” button and hold it until the LED lights up. Then, one by one, you need to dial 4 digits of the secret code. Upon completion of input, given code will be written to the non-volatile memory of the microcontroller.

Now if you type this code on the keyboard, the relay will turn on for 5 seconds. With a tenfold mistyped secret code an alarm will sound.

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!

Answer

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five http://jquery2dotnet.com/ centuries , but also the leap into electronic typesetting, remaining essentially unchanged.

This design is distinguished by the simplicity of the circuit design, to enter the code, only one button is used, which must be pressed a certain number of times, in accordance with the code digit, observing a pause when entering the next digit. The number of digits in the code is 4. To increase secrecy, you can place a keyboard in which only one button for entering the code will be active. If the correct code is entered, the system will activate the relay, however, it is possible to configure for other functions when the system is activated, for this you will need to switch to the device programming mode.

The device can be used in control systems garage doors, in the lighting control system, in security systems.

The main element of the circuit is the PIC16F628A microcontroller, which monitors the pressing of a button, visually notifies the user about the receipt of a command, and controls the state of the relay. For visualization, an LED is used, which is connected in parallel with the button for entering the code, which allows using only two wires to install and connect the button in the required place.
To power the device, you will need a 12 V power supply, the LM7805 voltage regulator is installed in the circuit. LED D3 indicates power supply.
The system has two modes of operation: normal mode and programming mode. In normal mode, the device performs its main task - it monitors button presses and responds when the code is entered correctly. In the programming mode, the main parameters of the system are configured: code, activation time, operating mode.
Switch JP1 is used to change the operating mode (normal/programming). When the switch is off, it is the normal operating mode; when it is on, it is the programming (settings) mode. It should be noted that the input to a particular mode is carried out when power is applied (the switch state is checked by the microcontroller when power is applied). Therefore, to enter the setting mode, you must set the switch and turn on the power, to exit the mode, turn off the switch, turn off and then turn on the power.

To enter a code of the form 1234, the sequence of actions is as follows:
press the button 1 time;
wait for visual confirmation by the LED on the button (the LED will flash once);
press the button twice;

press the button three times;
wait for visual confirmation by the LED on the button;
press the button 4 times.
After entering the fourth digit, the system will function according to established regime work. If an invalid code has been entered, the user will see a visual alert (LED blinking).
The programming mode is used to set the lock parameters. In this mode, to switch between options, the button is pressed and held for 3 seconds. After releasing the button, the transition to the next menu item will be performed, while the number of flashes will indicate which menu item you are in (for example, flash, flash, pause, flash, flash, pause, ... - means that the second menu item is selected).

Menu options:

Code change– used to change the user code. To change the code is entered in the same way as in normal operation. When the new code has been saved, the LED will indicate this with frequent flashes;
Changing the activation time– used to change the active state time. Pressing the button once in this menu changes this time by 1 s. For example, if you need a time of 10 seconds, then you need to press the button 10 times. When the parameters are saved, the LED will indicate this with frequent flashes.
Operating mode selection– used to change the relay control mode. There are two modes of operation: relay activation when the correct code is entered, and relay state change (activation/deactivation) when the correct code is entered. When the second mode is selected, the device will act as follows: if the relay is activated and the correct code is entered, the relay is deactivated, the next time the correct code is entered, the relay is activated. To change the operating mode: press the button once to select the first mode and twice to select the second mode.

All parameters are stored in the non-volatile memory of the microcontroller.

The circuit is assembled on a double-sided printed circuit board.

This electronic combination lock can be used to open an electromechanical shutter. Functionality implemented in software. The lock control relay turns on (usually to open the door) for a few seconds if someone enters the correct code.

The current consumption of the circuit is low because the microcontroller sleeps most of the time and only wakes up to process keystrokes. The 16F628A controller is already powered by an internal RC oscillator, so no external crystals are required. Each keystroke is duplicated sound signal BM1 buzzer. The buzzer is used with an internal generator. The status of the device is displayed on the LCD indicator type 16x02 with the HD44780 controller. The lock uses a standard matrix keyboard with 3 columns and 4 rows. The diagram of the lock is in the figure below.

In order to open the lock, enter the correct code and use "#" as the "enter" key. The original code is 623342. The code can be changed at any time after entering the current code. The "*" key is used to change the code. Enter the actual code, and press "*". If the code is entered correctly, the code change indicator HL1 will light up, then enter a new code, confirming the entry twice with the "#" key. You can also change the length of the code.

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 button SB6 After 2 s, the RAO output of the microcontroller DD1 will be set to high level, the transistor VT1 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 contacts of the SA1 switch are open, the electromagnet will close the lock through 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.

Powers the device source direct current voltage 10 ... 15 V. In case 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 a high current consumption, when the electromagnet Y1 worked, the main part of the current gives accumulator 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 set 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



Loading...
Top