The security system application and program offers a simple demonstration of the BASIC Serial Interface. By adding only a few door and window switches, a transistor, a siren, (see schematic) and a few lines of BASIC program (see program listing) the interface can become a multi-function security system. Please note, however, that it is a "barebones" program. It is left to the reader to fancy it up to their liking.
Normally closed door and window switches can be attached to the interface "in" ports as shown in the schematic(all unused ports should be grounded). In this configuration with all the switches closed the "in" port is held "low". When any switch opens the port goes "high". The program recognizes this as an alarm condition for the zone associated with that port. If the program "detects" a high on "in" port number 1 it will delay sounding the alarm for a user defined length of time. This is done to allow the owner time to enter the secured area and reset the alarm before the siren is activated. If a "high" condition is detected on any of the other ports, 2 to 7, an alarm will be sounded immediately.
Normally closed door and window switches can be attached to the interface "in" ports as shown in the schematic(all unused ports should be grounded). In this configuration with all the switches closed the "in" port is held "low". When any switch opens the port goes "high". The program recognizes this as an alarm condition for the zone associated with that port. If the program "detects" a high on "in" port number 1 it will delay sounding the alarm for a user defined length of time. This is done to allow the owner time to enter the secured area and reset the alarm before the siren is activated. If a "high" condition is detected on any of the other ports, 2 to 7, an alarm will be sounded immediately.
The alarm is sounded by bringing "out" port number 1 high. Connected to "out" port 1 is a NPN transistor which switches a 12 volt supply to a security siren or bell (figure 3) . The.alarm remains on until the system is reset or it reaches it's time out period.
In order for the BSI to transmit the status of it's "in" ports Data Strobe (pin. 23 of IC1) must be toggled. This toggling of the Data Strobe is done by program control. In this application Data Strobe is connected to "out" port 8 by a jumper. In order to trigger a transmission of the port conditions the program turns "out" port8 "on" then "off". This causes IC1 to transmit the status of it's "in" ports.
10 ' BASIC SERIAL INTERFACE
20 '
30 ' SECURITY SYSTEM DMONSTRATION PROGRAM
40 '
50 ' setup
60 KEY OFF:CLS:CLOSE'......................................... turn key off, clear screen, close
70 OPEN "COM1:1200,N,8,2" AS #1' .......................all files, open the serial port
80 PRINT#1,CHR$(NUL);'.........................................as com port #1, and transmit "0".
90 GOTO 310
100 '
110 FOR X=1 TO 8'.................................................. Subroutine to convert decimal number
120 B=C MOD 2:C=INT(C/2):R(X)=B'...................... received from the UART to binary
130 NEXT X'............................................................. and set array variables to represent
140 RETURN'.............................................................UART port conditions,R(1) to R(8)
150 REM
160 IF T(HP)=1 THEN 210'.......................................Subroutine to turn one UART port on
170 FOR X=1 TO 8'..................................................without changing the condition of
180 IF HP=X THEN OT=OT+2^(X-1):T(X)=1'...............any other UART port.---
190 NEXT X
200 PRINT #1,CHR$(OT);
210 RETURN
220 '
230 IF T(HP)=0 THEN 280'........................................Subroutine to turn one UART port off
240 FOR X=1 TO 8'...................................................without changing the condition of
250 IF HP=X THEN OT=OT-2^(X-1):T(X)=0'................any other port.---
260 NEXT X
270 PRINT #1,CHR$(OT);
280 RETURN
290 '********************* SECURITY SYSTEM MAIN PROGRAM *******
300 '
310 PRINT" Security System Program
320 '
330 PRINT:PRINT"Note:'OUT' port 8 of the UART (pin 5) must be connected to Data Strobe (pin 23)before running this program.":PRINT
340 INPUT"ENTER ALARM DELAY FOR ZONE #1 ENTRY ";DELAY
350 INPUT"ENTER ALARM TIMEOUT ";TIMEOUT
360 '
370 CLS:PRINT#1,CHR$(128);'.................................clear screen and turn UART port 8 on
380 PRINT "Ctrl E to reset"
390 HP=8 :GOSUB 220:HP=8:GOSUB 150'................Ask UART for 'in' port status.
400 IF LOC(1)=0 THEN 470'.......................................If transmission not received,skip.
410 IN$=INPUT$(1,#1):C=ASC(IN$):GOSUB 100'... read transmission and convert to
420 FOR X=1 TO 8'......................................................binary,assign each bit to array R(X)
430 LOCATE X+9,10
440 IF R(X)=1 THEN PRINT X;" ALARM !!!!!"' Print UART port status conditions
450 IF R(X)=0 THEN PRINT X;" ZONE SECURE"' as either 'alarm' or 'secure'
460 NEXT X
470 IF R(1)=1 THEN TIME=TIME+'.............................If zone 1 is high start delay time.
480 IF TIME=DELAY THEN ALARM=1'.......................if delay time is up set alarm.
490 FOR X=2 TO 8
500 IF R(X)=1 THEN ALARM=1'..................................if any zone,2-8,is high,set alarm.
510 NEXT X
520 IF ALARM=1 THEN HP=1:GOSUB 150'............... if alarm set,turn port 1 on.
530 IF ALARM=1 THEN RESETT=RESETT+1'............ if alarm is set start timeout.
540 IF RESETT=TIMEOUT THEN GOTO 580'............ If timeout is up then shutdown.
550 A$=INKEY$:IF A$="" THEN 570'........................ Check to see if Ctrl E was entered,
560 IF ASC(A$)=5 THEN 50'...................................... if it was then reset program.
570 GOTO 390
580 PRINT#1,CHR$(NUL);'.......................................Turn alarm off
590 PRINT:PRINT"SYSTEM SHUTDOWN AT "TIME$,DATE$ ' print shutdown
600 END
In order for the BSI to transmit the status of it's "in" ports Data Strobe (pin. 23 of IC1) must be toggled. This toggling of the Data Strobe is done by program control. In this application Data Strobe is connected to "out" port 8 by a jumper. In order to trigger a transmission of the port conditions the program turns "out" port8 "on" then "off". This causes IC1 to transmit the status of it's "in" ports.
10 ' BASIC SERIAL INTERFACE
20 '
30 ' SECURITY SYSTEM DMONSTRATION PROGRAM
40 '
50 ' setup
60 KEY OFF:CLS:CLOSE'......................................... turn key off, clear screen, close
70 OPEN "COM1:1200,N,8,2" AS #1' .......................all files, open the serial port
80 PRINT#1,CHR$(NUL);'.........................................as com port #1, and transmit "0".
90 GOTO 310
100 '
110 FOR X=1 TO 8'.................................................. Subroutine to convert decimal number
120 B=C MOD 2:C=INT(C/2):R(X)=B'...................... received from the UART to binary
130 NEXT X'............................................................. and set array variables to represent
140 RETURN'.............................................................UART port conditions,R(1) to R(8)
150 REM
160 IF T(HP)=1 THEN 210'.......................................Subroutine to turn one UART port on
170 FOR X=1 TO 8'..................................................without changing the condition of
180 IF HP=X THEN OT=OT+2^(X-1):T(X)=1'...............any other UART port.---
190 NEXT X
200 PRINT #1,CHR$(OT);
210 RETURN
220 '
230 IF T(HP)=0 THEN 280'........................................Subroutine to turn one UART port off
240 FOR X=1 TO 8'...................................................without changing the condition of
250 IF HP=X THEN OT=OT-2^(X-1):T(X)=0'................any other port.---
260 NEXT X
270 PRINT #1,CHR$(OT);
280 RETURN
290 '********************* SECURITY SYSTEM MAIN PROGRAM *******
300 '
310 PRINT" Security System Program
320 '
330 PRINT:PRINT"Note:'OUT' port 8 of the UART (pin 5) must be connected to Data Strobe (pin 23)before running this program.":PRINT
340 INPUT"ENTER ALARM DELAY FOR ZONE #1 ENTRY ";DELAY
350 INPUT"ENTER ALARM TIMEOUT ";TIMEOUT
360 '
370 CLS:PRINT#1,CHR$(128);'.................................clear screen and turn UART port 8 on
380 PRINT "Ctrl E to reset"
390 HP=8 :GOSUB 220:HP=8:GOSUB 150'................Ask UART for 'in' port status.
400 IF LOC(1)=0 THEN 470'.......................................If transmission not received,skip.
410 IN$=INPUT$(1,#1):C=ASC(IN$):GOSUB 100'... read transmission and convert to
420 FOR X=1 TO 8'......................................................binary,assign each bit to array R(X)
430 LOCATE X+9,10
440 IF R(X)=1 THEN PRINT X;" ALARM !!!!!"' Print UART port status conditions
450 IF R(X)=0 THEN PRINT X;" ZONE SECURE"' as either 'alarm' or 'secure'
460 NEXT X
470 IF R(1)=1 THEN TIME=TIME+'.............................If zone 1 is high start delay time.
480 IF TIME=DELAY THEN ALARM=1'.......................if delay time is up set alarm.
490 FOR X=2 TO 8
500 IF R(X)=1 THEN ALARM=1'..................................if any zone,2-8,is high,set alarm.
510 NEXT X
520 IF ALARM=1 THEN HP=1:GOSUB 150'............... if alarm set,turn port 1 on.
530 IF ALARM=1 THEN RESETT=RESETT+1'............ if alarm is set start timeout.
540 IF RESETT=TIMEOUT THEN GOTO 580'............ If timeout is up then shutdown.
550 A$=INKEY$:IF A$="" THEN 570'........................ Check to see if Ctrl E was entered,
560 IF ASC(A$)=5 THEN 50'...................................... if it was then reset program.
570 GOTO 390
580 PRINT#1,CHR$(NUL);'.......................................Turn alarm off
590 PRINT:PRINT"SYSTEM SHUTDOWN AT "TIME$,DATE$ ' print shutdown
600 END