$regfile = "m16def.dat" $baud = 9600 $crystal = 8000000 $hwstack = 32 ' default use 32 for the hardware stack $swstack = 64 ' default use 10 for the SW stack $framesize = 20 ' default use 40 for the frame space Config Portd = Output $lib "mcsbyte.lbx" Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Config 1wire = Portd.2 'use this pin Config Int0 = Low Level Dim Ar(8) As Byte , A As Word , I As Byte , E As Byte , W As Word Dim Code1(8)as Byte Dim Flag As Bit 'flag for correctness 'Code(8 Byte) = {&H01 ,&HDD , &H83 , &H07 , &H13 , &H00 , &H00 , &H1E} Code1(1) = &H01 Code1(2) = &HDD Code1(3) = &H83 Code1(4) = &H07 Code1(5) = &H13 Code1(6) = &H00 Code1(7) = &H00 Code1(8) = &H1E On Int0 Int0_int Enable Interrupts Enable Int0 'enable the interrupt E = 0 'flag for number of attempts W = 65000 Do Set Portd.4 'initially the relay is off Loop Int0_int: Disable Interrupts Disable Int0 Flag = 0 Wait 1 1wreset 'reset the device Print "iButton Access Code:"; If Err = 0 And E <= 6 Then 'check DS1990A is present 1wwrite &H33 'present, read code 'read ROM command Ar(1) = 1wread(8) For I = 1 To 8 Print Hex(ar(i)); 'print output Next Print For I = 1 To 8 If Ar(i) <> Code1(i) Then Set Portd.4 Flag = 0 'access not allowed For A = 10 To 1000 Sound Portd.6 , 4 , A Next Print "Access Code Not Match:Access Denied"; Print E = E + 1 Print E; Print ":"; Exit For Else Flag = 1 End If Next If Flag = 1 Then E = 0 Print Err; Reset Portd.4 'access allowed Sound Portd.6 , 10 , 50000 'siren on portD.6 Print "--Access Allowed"; Print Wait 2 End If Else Set Portd.4 'access not allowed For A = 50 To 500 Sound Portd.6 , 1 , A Next Print "Rejected"; Print If E = 5 Then '5 attempts of correctness Do Sound Portd.6 , 4 , W 'SOUND pin, duration, pulses W = W + 1 If W > 1000 Then W = 10 End If Loop End If End If 'End If Enable Int0 Enable Interrupts Return