Sie sind auf Seite 1von 6

11.

12

A simple alarm system

Figure 11.11 shows a simple alarm system. The alarm status of two doors (DOOR1 and DOOR2), a window (W !) and a smo"e dete#tor ($D) are to %e monitored. &a#h alarm point gi'es a logi# ( if the status is normal and a logi# 1 if an alarm o##urs. When an alarm o##urs, the #orresponding indi#ator light flashes and, at the same time, the %u))er is turned on. When the *+, (for a#"nowledge) %utton is pressed, the indi#ator light %e#omes steady %right while the %u))er is turned off. *fter the alarm #ondition is re#tified (returned to normal #ondition), on pressing the R$T (reset) %utton, the indi#ator light goes off. *n alarm indi#ator light will not %e a%le to turn off %y the R$T %utton without, first, %eing a#"nowledged. The alarm system has a lamp test (-./ T&$T) %utton whi#h is used to test if the alarm indi#ators and the %u))er are in wor"ing a #ondition.
*larm inputs

DOOR1

indi#ator lights DOOR1 mi#ro#ontroller DOOR2 W! $D

DOOR2

2u))er W! *+, 2utton -./ T&$T R$T 2utton 2utton

$D

Fig 11.11

101

The 314( mi#ro#ontroller is used in this alarm system. The mi#ro#ontroller has an 45%it output port with address (617( and an 45%it input port (611(. The #onne#tions to these ports are shown in Fig 11.12 %elow.
DOOR1 DOOR2 W! $D

DOOR1 DOOR2 W! $D *+, R$T -./ T&$T

%( %1 %2 %7 %1 %8 %0 %9 (611(

%( %1 %2 %7 %1 %8 %9 %9 (617(

2u))er

Fig 11.12 The alarm points are represented %y swit#hes. *t normal #ondition, the alarm points are at the normally #losed position, thus, gi'ing a logi# ( at the input. *n alarm #ondition o##urs when the swit#h opens and produ#es a logi# 1 at the input. * swit#h whi#h opens momentarily is #onsidered an alarm #ondition. $imilarly, the *+,, R$T and -./ T&$T %uttons are in a normally #losed position, gi'ing a logi# ( at ea#h inputs. When a %utton is pressed, a logi# 1 is applied at the input. The program flow#hart for the alarm system is shown in Fig 11.17.
$tart

nitialisation

*#"nowledged %efore : !o

<es R$T pressed :

!o

<es +lear all a#";ed alarms and "eep una#";ed alarm

lamptest( ) <es !o -./ T&$T : !o

Read input port

*nnun#iation routine

*ny *larms :

<es *+, pressed : <es Off %u))er, set a#"nowledge flag

!o

Fig 11.17

108

The purposes of some 'aria%les used in the program are e6plained in the ta%le %elow. =aria%le alarmpt alarm Des#ription Whate'er is read from the input port is stored in this 'aria%le, so it has the present status of the alarm points. This is used to "eep the pre'ious alarm status. n this way, a momentarily alarm #ondition is "ept and stored. The 'alue of alarm is gi'en %elow> alarm = alarm | alarmpt ackflg This is the a#"nowledge flag whi#h "eeps a re#ord if an alarm is a#"nowledged. * %it is set to 1 when the alarm is a#"nowledged.
%9 %0 %8 %1 %7 %2 %1 %( ackflg

not used

alarmflg This is used to #he#" for any una#"nowledged alarm. t is o%tained as follows> alarmflg = alarm ^ ackflg *ny una#"nowledged alarm will #ause alarmflg !=0

The program for the alarm system is shown in /rogram 11514 %elow.
/* Program 11-18 A simple alarm system by KC Chong 30th Nov 2000 Alarm4.C in Dynamic C directory port usage output port (x130) b7 b6 b5 b4 b3 b2 b1 b0 ||||||||| |__|__|__|__|__|__|__|__| ^ ^ ^ ^ ^ | | | | |_____ | | | |________ | | |___________ Buzzer _______ | |______________

Door 1 Door 2 Window Smoke Detector

100

input port (x110)

b7 b6 b5 b4 b3 b2 b1 b0 ||||||||| |__|__|__|__|__|__|__|__| ^ ^ ^ ^ ^ ^ ^ LMP TEST _____| | | | | | | RST _____________| | | | | |_____ ACK ________________| | | |________ | |___________ |______________

Door 1 Door 2 Window Smoke Detector

*/ #define #define #define #define #define #define #define #define main() { int alarm, alarmpt, alarmflg, ackflg, delay, flash, pattern; int controlkey, ackey, rstkey,lmpkey; int mask = 0x0f; /* initialisation */ alarm=0x00; alarmflg = 0x00; ackflg = 0x00; delay = delay_count; outport(outprt,00); while(1) { alarmpt = inport(inprt) & mask; alarm = alarm |alarmpt; buz_on 0x80 buz_of 0x00 inprt 0x110 outprt 0x130 delay_count 2500 ack 0x20 rst 0x40 lmptest 0x80

/* read input port */

if (alarm !=0) /* alarm ? */ { /* yes */ alarmflg = alarm ^ ackflg; if(alarmflg !=0) /* acknowledged ? */ { /* no */ if(flash==1) pattern = alarm |ackflg|buz_on; else pattern = ackflg |buz_on; delay--; if(delay==0) { if(flash==1) flash=0; else flash=1; delay = delay_count; }

109

outport(outprt, pattern); }

controlkey = inport(inprt);

/* read control button */

ackey = controlkey & ack; if(ackey !=0) /* ACK pressed ?*/ { ackflg = alarm; pattern = ackflg | buz_of; outport(outprt, pattern); } rstkey = controlkey & rst; if (rstkey !=0) { alarm=alarm^ackflg; alarmflg = 0x00; ackflg = 0x00; delay = delay_count; outport(outprt,alarm); } } lmpkey = inport(inprt) & lmptest; /* read input for lamp test */ /* RST pressed ?*/

if(lmpkey !=0) /* LMP TEST ? */ { lamptest(); outport(outprt,alarm); } } }

/* lamp test function - indicator lights test pattern*/ lamptest () { int x,y,z,i; for(x=0;x<3;x++) { outport(outprt, 0x0f|buz_on); for(i=0;i<20000;i++); outport(outprt,0x00|buz_on); for(i=0;i<20000;i++); }

for(x=0;x<3;x++) { outport(outprt, 0x05|buz_on); for(i=0;i<20000;i++); outport(outprt,0x0a|buz_on); for(i=0;i<20000;i++); } y=0x01; while (y !=0x10) { outport (outprt,y|buz_on);

104

for(i=0;i<20000;i++); y <<=1; } y = 0x08; while (y !=0) { outport (outprt,ybuz_on); for(i=0;i<20000;i++); y >>=1; } }

10?

Das könnte Ihnen auch gefallen