#include #include #define byte unsigned char //#define timdebug #ifdef timdebug #define firstalarmtim 5 #define repeatalarmtim 4 #else #define firstalarmtim 300 #define repeatalarmtim 60 #endif /* Configuration bit definitions */ #define CONFIG_ADDR 0x2007 __CONFIG(UNPROTECT & BORDIS & MCLRDIS & WDTDIS & PWRTEN & INTIO) ; #define stickremoved GPIO2 void wait1sec(void) { byte dwncnt = 16 ; while (dwncnt) { while (!T0IF) ; T0IF = 0 ; TMR0 += (256-244) ; dwncnt-- ; } } void wait250ms(void) { byte dwncnt = 4 ; while (dwncnt) { while (!T0IF) ; T0IF = 0 ; TMR0 += (256-244) ; dwncnt-- ; } } byte secfrac ; int seconds ; byte minutes ; byte hours ; byte btel = 47 ; byte dummy ; byte nralarm ; void beep(void) { int nrper = 300 ; byte lencnt = 1 ; GPIO = 2 ; while (--nrper) { lencnt = btel ; while (--lencnt) ; GPIO = 0x30 ; lencnt = btel ; while (--lencnt) ; GPIO = 0x03 ; } GPIO = 0 ; } void alarmsound(void) { byte i = 7 ; while (i--) { beep() ; wait250ms() ; } } void main( void ) { CMCON = 7; TRISIO = (1 << 3)+(1<<2) ; OPTION = 7 ; WPU = 0x33+4 ; beep() ; while (1) { if (T0IF) { T0IF = 0 ; TMR0 += (256-244) ; dummy = GPIO ; if (!stickremoved) { dummy = GPIO ; beep() ; secfrac = 0 ; seconds = 0 ; WPU = 0 ; GPIF = 0 ; IOCB2 = 1 ; GPIE = 1 ; #asm sleep nop #endasm dummy = GPIO ; GPIE = 0 ; WPU = 4 ; IOCB2 = 0 ; nralarm = 0 ; beep() ; } secfrac++ ; if (secfrac == 16) { secfrac = 0 ; seconds++ ; if (seconds >= firstalarmtim) { alarmsound() ; seconds -= repeatalarmtim ; if (++nralarm > 30) { dummy = GPIO ; WPU = 4 ; GPIF = 0 ; IOCB2 = 1 ; GPIE = 1 ; #asm sleep nop #endasm dummy = GPIO ; GPIE = 0 ; WPU = 4 ; IOCB2 = 0 ; nralarm = 0 ; beep() ; } } } } } }