Sunteți pe pagina 1din 9

ConstruCtion

MicRocoNtRolleRbASed code locK

C
K. S. SANKAR based on a 20-pin ATMEL microcontion. However, you may also use any other branded/unb randed LCD for troller AT89C2051. It employs a 4-digit

ode locks can be constructed sequential code with time-out security the purpose. using digital and timer ICs emfeature. In addition to the microcon-

circuit description
ploying pushbuttons or keypads troller, t he circuit uses a single adAs already mentioned, the projec t for entering the code for authentication ditional IC (CD4050) and a transistor and operation of the code lock. Howto drive a relay. Although the project makes use of ATMEL AT89C2051 microcontroller, in 20-pin DIP package, ever, such circuits would require a uses a liquid-crystal display (LCD), it which supports 2 kB of flash-based large number of ICs. is useful for design and developmental program memory. A 6MHz crystal is On the other hand, a microconpurpose only and is not really an estroller-based c ode lock will require sential part of the circuit. The same can used for providing the clock. Port-1 of the microcontroller is used to drive the very f ew peripheral co mponent s. be removed from the circuit without With the cost of microcontrollers now any change in the software. LCD in 4-bit mode with 10-kilo-ohm pull-up resist ors. The 10-kilo -ohm dropping to the equivalent cost of apAs regards LCD modules, these are proximately four digital ICs, it makes available in 14- or 16-pin packages. The potentiometer controls the contrast of the LCD panel. It works better when its sense to design simple logic circuits 16-pin variety has an additional backusing microcontrollers and free version light option. Popular brands available wiper is nearer to ground potential. Timer 0 of 89C2051 is used as an of programming languages. Although in India are Lampex, Hantronix and free-version-language code length is Hitachi. Most other models also have internal counter that increments a vari-

the same pin configuration. The model able every second. This variable is used normally limited to around 2 kB, but that is adequate for small projects like used in this project is Lampex LM16200 in the project to time out the delay for entering the code. this one. 16-c har act er 2-line alphanumeric This simple code lock project is dot-matrix display with backlight opAfter initialisation, the software
Fig. 1: Circuit of microcontroller-based code lock 58 Augus t 2 006 e lect ron i cs for you w w w . ef y m Ag . c o m C M Y K

ConstruCtion
Parts List
Semiconductors: IC1 - AT89C2051 microcontroller IC2 - CD4050 non-inverting buffer IC3 - 7805 +5V regulator T1 - 2N2222 npn transistor D1-D5 - 1N4007 rectifier diode LED1-LED3 - 5mm LED Resistors (all -watt, 5% carbon): R1, R2, R4 - 220-ohm R3 - 150-ohm R5 - 10-kilo-ohm
Fig. 2: Power supply

RNW1, RNW2 - 10-kilo-ohm resistor network VR1 - 10-kilo-ohm preset Capacitors: C1 - 10F, 16V electrolytic C2, C3 - 22pF ceramic disk C4, C6 - 0.1F ceramic disk C5 - 1000 F, 25V electrolytic Miscellaneous: X - 6MHz crystal RL1 - 5V, 100-ohm, 1C/O reT AL

lay S1- S8 - Push-to-on switch S9 - On/off switch X1 - 230V AC primary to 9V, 250mA secondary transformer

- 16-character2-line LCD (male-53 pins used) - Bergstick connector (female- 36 pins used) - 1m long, 4-core ribbon
Fig. 3: Actual-size, single-side PCB of microcontroller-based code lock

respective LEDs. The P1.1 line is also interfaced to relay driver transistor T1 through a buffer to switch on a 12V relay, which can activate an electrically operated lock. Timer 0 is st art ed on the f irs t keystroke to validate the remaining three digits, pro vided these digits are entered within five seco nds. If not, the software loops bac k to the initial state. After three unsuccessful attempts, t he circuit will wait for abo ut 10 sec onds ( before accept ing the next keystroke) to avoid unwanted tampering attempts. All these timings can be changed through the soft ware program to suit your specific requirements. Power suppl y ( Fig. 2). A c onvent ional regulat ed power supply
Fig. 4: Component layout for the PCB

c irc u it em pl o ying a s t ep- do wn switches on Ready LED and waits transform er followed by bridge rec 3. Port-3 does not have the bit P3.6 for a 4-digit code to be entered. The tifier, s moothing capacitor and 5V and hence the same is ignored by the valid code for this project is 1324. The regulator is used to meet the supply software. Two LEDs at port-1 are intercode is entered using the seven input requirement for t he code lock circuit faced to P1.0 and P1.1 pins to provide switches that are connected to portshown in Fig. 1. Ready and Relay On indication via
60 Augus t 2 006 e lect ron i cs for you w w w . ef y m Ag . c o m C M Y K

ConstruCtion
An actual-size PCB layout for the for the project in BASCOM-51 is given should be burnt into the chip using code-lock including the power supply at the end of the article. Although the any universal programmer. The hex is shown in Fig. 3 and its component program is self-explanatory, you need code of the program is only 1.5k long, layout in Fig. 4. to be aware of BASCOM51 compiler while AT89C2051 microcontroller can directives and syntax of statements, take up to 2k of code. This program

the software
may be modified to suit your specific which are available within the help The software is written using BASmenu of BASCOM compiler. BAS requirement. COM-51. (You may find details about All files pertaining to COM contains a lot of statements to EFY note . it in m y artic le Real- Time Cl ock control various peripherals including this project have been carried in this Using Micro co nt roller pub lished the LCD. months EFY-CD, while BASCOM-8051 in Jan. 2005 issue of EFY magazine.) The BOSCOM compiler/IDE can package has already been included in The source code file EFYCLOCK.BAS be used to generate a hex file, which the EFY-CD for May 2005.

EFYCLOCK.BAS
p as s = 1 4 2 8 b in ( 1324 ) d e ci m al L o ca te 2 , 0 : L c d t im e o ver R ead y _l ed = 1 Inc r Attem p ts $c r y sta l = 6000 000 G o su b E r r or _fl as h $r egfi l e = 89c 20 51. d at For I = 1 To 4 Wai t 1 G o to B eg in Di m I As B yte W h i le 1 = 1 En d If Di m K (4) As B y te Di m P a ss (4 ) As B yt e I f S ec _c ou n t > P a ss ti m e T hen Di m K ey As B y te

E x i t F or c h ec k v al d i ty Di m I nv al i d _p a ss As B i t E n d If Inv al i d _p a ss = 0 Di m S ec _c o u nt As B y te Fo r I = 1 T o 4 If K (i ) <> P as s (i ) T hen Di m C l o ck _w or d As Wo rd I f P 3 < > 255 T h en Di m P a ss ti m e As B y te s om e key pr es s ed - c h ec k i t Inv al i d _p a ss = 1 Di m A ttem p ts As B y te En d If Di m M axat tem pt s As B y te I f I = 1 T hen Next I s tar t ti me r0 on fi rs t key s tro k e R ead y_ l ed Al i as P 1. 0 S ec _c ou n t = 0 If I nv al i d _p a ss = 1 T h en G o to In va l id R el ay_ ou t Al i as P 1 .1 S tar t T i m er 0 E n d If En d If F or I = 1 T o 4 K( i) = 0 K ey = P 3 N ext I w ai t for key rel ea se Val i d : W hi l e K ey = P3 L o ca te 2 , 0 : L c d v al i d p as sw or d P as s (1) = 1 Wen d Rel ay _o ut = 1 P as s (2) = 3 K (i ) = 255 - K ey Wai t 3 If K (i ) = 1 T h en P as s (3) = 2 Rel ay _o ut = 0 P as s (4) = 4 G oto L c d_ ou t G o to B eg in E n d If S ec _c ou n t = 0 If K (i ) = 2 T h en Inv al i d : G oto L c d_ ou t L o ca te 2 , 0 : L c d i n v al i d P as s ti m e = 5 Atte mp ts = 0 E n d If G o su b E r r or _fl as h If K (i ) = 4 T h en Ma xatte mp ts = 3 Inc r Attem p ts K (i ) = 3 Wai t 1 Co n fi g L c d = 16 * 2 G oto L c d_ ou t Co nfi g Lc d p i n = P in , Db4 = P 1.4 , Db 5 = P 1. 5 , Db6 = E n d If G o to B eg in If K (i ) = 8 T h en P 1 .6 , Db 7 = P 1 .7 , E = P 1 .3 , R s = P 1.2 p or t 1 K (i ) = 4 G oto L c d_ ou t Tr y l ater : P1 = 0 E n d If wa it fo r 10 s ec o nd s If K (i ) = 16 T h en P 3 = 255 Fo r I = 1 T o 1 0 K (i ) = 5

Wai t 1 Co n fi g T i me r0 = T im er , G ate = I nte rn al , Mo d e = 2 G oto L c d_ ou t K ey = P 3 T i m er0 u se ti m er 0 E n d If K ey = 255 - K ey Ga te = In ter n al n o ex ter na l i n ter ru p t If K (i ) = 32 T h en If Key = 3 T h en Mo d e = 2 8 b it au to rel o ad K (i ) = 6 E xi t F or G oto L c d_ ou t End If se t t0 i n ter na l i n ter ru p t 2000 ti m es a s ec E n d If Next I On T i m er 0 T i m er _0_o v erfl o w_ in t If K (i ) = 128 T h en L o ad T im er 0 , 250 K (i ) = 7 Wai t 2 G oto L c d_ ou t P r i or i ty Set T i m er 0 Retu r n E n ab l e I nt err u p ts E n d If E r ro r_fl a sh : E n ab l e T i m er 0 i nv al i d key c om bi n at io n Fo r I = 1 T o 1 0 K ey(i ) = 0 Read y _l ed = R ead y_ l ed X or 1 B eg i n : Wai tm s 1 00 If Atte mp ts > = Ma xatte mp ts T h en L c d _o u t: Next I L oc ate 0 , 0 : L c d Max attem p ts ; attem p ts o v er Read y _l ed = 0 L oc ate 2 , 0 : L c d tr y af ter 10 s ec on d s L c d K (i ) Retu r n Atte mp ts = 0 W ai tm s 30 G os u b T r yl at er E x i t W h il e E n d If E n d If i n terr u p t su b ro u ti n e T i m er_ 0_o ver fl ow _i n t: S ec _c ou n t = 0 W en d p r og ra m c o m es h er e 200 0 ti m es a sec w i th a 6m hz xtal F or I = 1 T o 4 Inc r Cl o ck _w or d K( i) = 0 N ext I N ext I If C l o ck _w or d > 200 0 T hen R ead y _l ed = 0 Cl o ck _w or d = 0 Cls Inc r Sec _c o u nt C u rs o r On B l i n k S top T i m er0 En d If c le ar th e L CD d i sp l a y Retu r n L c d E n ter P as s: c he ck i f ti m e ov er d i s p la y th i s at th e top l i ne I f S ec _c ou n t > P a ss ti m e T hen En d

62 Augus t 2 006

e lect ron i cs for you w w w . ef y m Ag . c o m C M Y K

S-ar putea să vă placă și