' Listing 3 ' Nuts & Volts - January 2000 ' {$STAMP BS2p} ' -----[ Title ]----------------------------------------------------------- ' ' File...... ALARM.BSP ' Purpose... Simple alarm system demo using BS2p pin polling ' Author.... Jon Williams ' E-mail.... jonwms@aol.com ' Started... 05 DEC 2000 ' Updated... 05 DEC 2000 ' -----[ Program Description ]--------------------------------------------- ' ' This program demonstrates BS2p polled-inputs and polled-output control. ' Two pins are monitored and will control an output (alarm) pin. The ' interrupt condition is latched to determine the cause. ' -----[ Revision History ]------------------------------------------------ ' ' -----[ I/O Definitions ]------------------------------------------------- ' AlarmLED CON 0 FrontDoor CON 4 ' front door input BackDoor CON 5 ' back door input ' -----[ Constants ]------------------------------------------------------- ' On CON 1 ' LED is active high ' -----[ Variables ]------------------------------------------------------- ' iPins VAR Byte ' interrupt detect pins ' -----[ EEPROM Data ]----------------------------------------------------- ' ' -----[ Initialization ]-------------------------------------------------- ' Setup: POLLMODE 0 ' clear and disable polling POLLIN FrontDoor,0 ' interrupt when inputs low POLLIN BackDoor,0 POLLOUT AlarmLED,On ' alarm LED on interrupt POLLMODE 10 ' latch interrupt condition ' -----[ Main Code ]------------------------------------------------------- ' Loop: DEBUG Home,"Monitoring... " GET 128,iPins ' get cause of interrupt iPins = iPins >> 4 ' move to lower nibble IF (iPins = 0) THEN Loop ' no alarms DEBUG CR,CR ' alarm screen DEBUG "Alarm(s) Detected",CR DEBUG "-----------------",CR DEBUG "Front Door: ", DEC iPins.Bit0,CR DEBUG "Back Door: ", DEC iPins.Bit1,CR PAUSE 3000 ' give time for display DEBUG CLS POLLMODE 10 ' reset polling GOTO Loop ' -----[ Subroutines ]----------------------------------------------------- '