incorrect password three times, the circuit sounds an alarm.
The alarm can be configured to work in two modes: auto-reset and latch-up. In the auto-reset alarm mode, all the keys pressed are ignored and the buzzer keeps beeping
continuously for one minute, and thereafter the code lock resets automatically.
However, if you want additional secu-rity, you can enable the latch-up mode. In this mode the code lock never switches to the normal mode from the alarm mode and the only way to reset the code lock is to interrupt the power. When not in use, the code lock goes into sleep mode, and it wakes up if any key is pressed. This feature reduces the power consumption by the microcontroller.
The main features of PIC16F84 micro-controller are:
1. Program and data memory are in separate blocks, with each having its own bus connecting to the CPU
2. Reduced instruction set controller (RISC) with only 35 instructions to learn
3. 1024 words (14-bit wide) of program memory
4. 68 bytes of data RAM 5. 64 bytes of data EEPROM 6. 8-bit wide data bus
7. 15 special-function registers (SFRs)
8. 13 input/output (I/O) pins with individual direction control
9. Code protection
10. Built-in power-on-reset, power-up timer, oscillator start-up timer
11. Power-saving sleep mode
Circuit description
Fig. 1 shows the block diagram of the microcontroller-based code lock. Pin diagram of PIC16F84 microcontroller is shown in Fig. 2. Basically, the circuit Working model of PIC16F84-based coded device switching system
Fig. 1: Block diagram of PIC16F84-based coded device switching system
August
(shown in Fig. 3) comprises PIC16F84 mi-crocontroller (IC2), 4x3 matrix keyboard, relays and buzzer.
The microcontroller. PIC16F84 is an 8-bit CMOS microcontoller. Its internal circuitry reduces the need for external components, thus reducing the cost and power consumption and enhancing the system reliability. The microcontroller has two ports, namely, Port A and Port B. Out of the available 13 bidirectional I/O pins of Ports A and B, seven pins are used for keyboard interfacing, four pins are used to drive the relays cor-responding to the four devices and one pin is used to read the jumper status for selecting the alarm mode. One can reset the microcontroller only by interrupting the power.
The password is stored in the internal 64-byte EEPROM memory of the mi-crocontroller at addresses 0x00 through 0x3F. The memory can be programmed and read by both the device programmer and the CPU when the device is not code Fig. 2: Pin details of PIC18F84 microcontroller
Semiconductors:
IC1 - 7805 +5V regulator IC2 - PIC16F84 microcontroller T1-T5 - BC547 npn transistor D1-D5 - 1N4007 rectifier diode LED1-LED4 - Red LED
Resistors (all ¼-watt, ±5% carbon, unless stated otherwise):
R1 - 10-kilo-ohm
R2 - 4.7-kilo-ohm R3-R5 - 220-ohm R6-R10 - 2.2-kilo-ohm R11-R14 - 1-kilo-ohm Capacitors:
C1 - 470µF, 35V electrolytic C2, C3 - 0.1µF ceramic disk C4, C5 - 33pF ceramic disk Miscellaneous:
RL1- RL4 - 12V, 285-ohm, 1C/O relay (OEN58 type 1C) XTAL - 4MHz crystal PZ1 - Piezobuzzer
S1-S12 - Push-to-on tactile switch Parts List
Fig. 3: Circuit diagram of PIC16F84-based coded device switching system
protected. It is non-volatile and can retain data for more than 40 years.
Four special-function registers are used to read and write the EEPROM.
These registers are named as EECON1, EECON2, EEDATA and EEADR, respec-tively. Register EEDATA holds 8-bit data for read/write and register EEADR holds the address of the EEPROM location be-ing accessed. Register EECON1 contains the control bits, while register EECON2 is used to initiate the read/write operation.
Oscillator. The internal oscillator circuitry of the microcontroller generates the device clock. The microcontroller can be configured to work in one of the four oscillator modes:
1. External resistor-capacitor 2. Low-power crystal (oscillation fre-quency up to 200 kHz)
3. Crystal/resonator (oscillation fre-quency up to 4 MHz)
4. High-speed crystal/resonator (oscil-lation frequency up to 10 MHz)
In this circuit, the oscillator is con-figured to operate in crystal mode with a 4MHz crystal along with two 33pF capacitors.
Reset circuit. The built-in power-on reset circuitry of the microcontroller elimi-nates the need for the external power-on reset circuit. In the circuit, MCLR pin is tied to VDD through resistor R1 (10 kilo-ohms) to enable power-on reset. The in-ternal power-up timer (PWRT) provides a nominal 72ms delay from power-on reset.
This delay allows VDD to rise to an accept-able level when the microcontroller is powered on. The oscillator start-up timer (OST) provides 1024-oscillator cycle delay after the power-up timer delay is over.
This ensures that the crystal oscillator has started and is stable.
Power supply. The 12V DC supply for
the circuit is obtained from a 12V adaptor with 500mA rating. Any other source such as a 12V lead-acid battery can also be used. This 12V DC is used for operation of the relays used in the circuit. The regu-lated +5V supply for the microcontroller is derived using regulator IC 7805 (IC1).
Diode D1 protects the circuit from reverse supply connections. Capacitor C1 filters out the ripples present in the incoming DC voltage.
Keyboard. The 12-key matrix key-board comprises 12 tactile pushbutton switches arranged in four rows and three columns as shown in Fig. 3. Data is en-tered via this keyboard.
Ports A and B of the microcontroller are bidirectional I/O ports. Three lines of Port A (RA0 through RA2) are used as the output-scan lines and four lines of Port B (RB4 through RB7) are used as the input-sense lines. Port B of IC2 has weak Fig. 4: Actual-size, single-side PCB layout for PIC16F84-based coded device switching system
Fig. 5: Component layout for the PCB
internal pull-ups, which can be enabled through the software. This eliminates the need for connecting external pull-up resis-tors to pins 10 through 13. Resisresis-tors R2 through R4 protect Port A’s output drivers from shorting together when two keys of the same row are inadvertantly pressed simultaneously.
In the scanning routine, initially all the scan lines are made low and it is checked whether all the keys are in released state.
If all the keys are in released state, the
processor is put into sleep (power-down) mode. The interrupt-on-change feature of Port-B pins RB4 through RB7 is used to wake up the processor from sleep.
When any key is pressed, one of the sense lines becomes low. This change in the pin status causes an interrupt to wake up the microcontroller (IC2) from sleep.
Now each scan line is made low while keeping the remaining scan lines in high state. After making a scan line low, the status of the sense lines is read.
If any of the sense lines is found low, it means that a key at the intersection of the current scan line and the low sense line has been pressed. If no key is found to be pressed, the next scan line is made low and again scan lines are checked for low state. This way all the twelve keys are checked for any pressed key by the microcontroller.
Since mechani-cal tactile switch keys are used, pressing of a single key may be consid-ered by the micro-controller as press-ing of many keys due to the bouncing of the keys. To avoid this, the proces-sor is made to wait up to a debounce delay of 20 ms dur-ing the pressdur-ing or releasing of a key.
Within this deb-ounce delay, all the bounces get settled out, thus debounc-ing the key.
In sleep (power-down) mode, the device oscillator is turned off and the microcontroller is placed in its low-est-current con-sumption state.
Also note that the microcontroller’s I/O pin status remains unaltered during sleep mode.
Relays. To turn on/off the equip-ment or to lock/unlock the solenoid-oper-ated locks, four relays (RL1 through RL4) are provided—one for each channel.
Since the current-driving capacity of the port pins of PIC16F84 (IC2) is not enough to drive the relays directly, tran-sistors T2 through T5 are used to boost the current to drive relays RL1 through RL4, respectively.
Fig. 6: Flow-chart of the main program Fig. 6(a): Flow-chart for locking/unlocking the code lock
The bases of transistors T2 through T5 are connected to Port-B pins 6 through 9 (RB0 through RB3) through base- current-limiting resistors R7 through R10, respectively. The equipment or solenoid-operated locks can be connected to the normally open (N/O) contacts of these relays. Diodes D2 through D5 are used as freewheel clamp diodes. The series combination of a red LED (LED1 through LED4) and a current-limiting resistor (R11 through R14) is connected across each relay coil.
Buzzer. Pin 2 (RA3) of IC2 is con-nected via resistor R6 and transistor T1 to piezobuzzer PZ1. The buzzer gives a short beep when any key is pressed. In the case of a wrong data entry, the buzzer gives a long beep to indicate the error.
On successful password verification, it gives three short beeps, and after success-ful password change, it gives two short beeps. When a wrong password is entered
consecutively for three times, the buzzer sounds an alarm.