;teatimer ;waits minutes selected by single jumper on P1.7 - P1.0 , P3.0 - P3.3 ;flashes LED on P3.5 while time elapses ;makes finally three beeps and goes to sleep until next start = reset ;makes directly after reset three beeps if no jumper was found ;04-01-10 added flashing LED, comments, changed timing sligtly IEN0 EQU 0A8H ;Interupt control LED BIT P3.5 JumperGND BIT P3.7 Piezo BIT P3.7 BeepDuration EQU 150 ;Duration of Beep and Pause LEDFlash EQU 50 ;Delay for flashing LED NoofBeeps EQU 3 ;Number of beeps after time elapsed or if no jumper was fund ORG 0000H SJMP Start ORG 000BH ;Timer 0 interupt handling RETI ;wake-up only Start: MOV SP, #010H ;Move stackpointer CLR JumperGND ;Pull low to read minutes MOV A, #0H ;State if no jumper is set JB P1.7, CKP16 ;Convert jumper setting to minutes in ACC MOV A, #1 CKP16 JB P1.6, CKP15 MOV A, #2 CKP15 JB P1.5, CKP14 MOV A, #3 CKP14 JB P1.4, CKP13 MOV A, #4 CKP13 JB P1.3, CKP12 MOV A, #5 CKP12 JB P1.2, CKP11 MOV A, #6 CKP11 JB P1.1, CKP10 MOV A, #7 CKP10 JB P1.0, CKP30 MOV A, #8 CKP30 JB P3.0, CKP31 MOV A, #9 CKP31 JB P3.1, CKP32 MOV A, #10 CKP32 JB P3.2, CKP33 MOV A, #11 CKP33 JB P3.3, CKPEND MOV A, #12 CKPEND JZ NoJumper ;Alarm on no jumper set, which is equal to ACC=0! ACALL Beep ;Make start beep SETB JumperGND ;Save energy MOV B, #20 ;3*20 seconds per minute MUL AB ;calc interupts occuring during the time MOV TMOD, #00000000B ;Init T0 as 2^13 divider MOV IEN0, #10000010B ;Interupt T0 ON SETB TCON.4 ;T0 start Wait: ;wait for programmed time to pass (stored in ACC) and flash LED CLR LED ;LED on MOV R1, #LEDFlash LEDon: DJNZ R1, LEDon SETB LED ;LED off ORL PCON, #00000001B ;Idel, wake-up by T0 DJNZ ACC, Wait NoJumper: MOV A, #NoofBeeps ;Make beeps in a row with pauses inbetween BeepCountLoop: ACALL Beep ;Make end-beep DEC A JZ PowerDown ;No pause after last beep ACALL Pause SJMP BeepCountLoop PowerDown: SETB Piezo ;Save Energy ORL PCON, #00000010B ;Power Down NOP NOP NOP NOP NOP ;Total halt of the MCU SJMP PowerDown ;Sometimes wakes up from reset here Beep: ;Makes single beep, uses R1 alone MOV R1, #BeepDuration BeepLoop: CPL Piezo NOP DJNZ R1, BeepLoop RET Pause: ;Pause, uses R1 alone MOV R1, #BeepDuration PauseLoop: NOP NOP DJNZ R1, PauseLoop RET