> Date: Thu, 2 Jan 2014 17:13:31 +0000 > From: nicola@nicolaperotto.it > To: piclist@MIT.EDU > Subject: Re: [PIC] Beep 3 times once a minute inside a timing loop >=20 > Hi Robert, >=20 > On 02/01/2014 15:46, Robert Dvoracek wrote: >> btfss Beep,DoIBeep > ... >> movlw 1 >> xorwf Beep,f >> >> > I dont see the declarations so cant be sure but I think that the bit you = are > testing/changing is the same so there is a potential source of problems: = if for > some reason you change the value of "DoIBeep" and forget to change also t= he "1". > Define it near the other and comment adequately. Sorry I should have put that in there. =A0That is a good idea. =A0I went ah= ead and changed it to movlw 0xff just in case, since the variable isn't bei= ng used for anything else. Other than the variable cleanup, I'm surprised at the soundness of the core= algorithm. =A0Anyway, here is the code in its current condition, hopefully= with all the relevant bits included this time. =A0Thank you everyone for a= ll your help. #define LED =A0 =A0 =A0 =A0 shadow,GP2 =A0 =A0 =A0; Have an LED for some ou= tput. #define LED_MASK =A0 =A0b'00000100' =A0 =A0 ; Bitmask to toggle the LED #define DoIBeep =A0 =A0 Beep,0 =A0 =A0 =A0 =A0 =A0; boolean beeping toggle ;**************************************************************************= ***** ; Processor Inclusion ;**************************************************************************= ***** #include "p10f200.inc" ;**************************************************************************= ***** ; Variable Definitions ;**************************************************************************= ***** GPR_VAR =A0 =A0 =A0 =A0 UDATA TimerL =A0 =A0 =A0 =A0 =A0RES 1 TimerH =A0 =A0 =A0 =A0 =A0RES 1 TimerE =A0 =A0 =A0 =A0 =A0RES 1 TimerW =A0 =A0 =A0 =A0 =A0RES 1 Beep =A0 =A0 =A0 =A0 =A0 =A0RES 1 shadow =A0 =A0 =A0 =A0 =A0RES 1 ;**************************************************************************= ***** ; Reset Vector ;**************************************************************************= ***** RES_VECT =A0CODE =A0 =A00x0000 =A0 =A0 =A0 =A0 =A0 =A0; processor reset vec= tor =A0 =A0 GOTO =A0 =A0START =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; go to begin= ning of program ;**************************************************************************= ***** ; MAIN PROGRAM ;**************************************************************************= ***** MAIN_PROG CODE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; let linker plac= e main program START Init=09 =A0 =A0 movlw =A0 b'10011111' =A0 =A0 =A0 =A0 =A0 =A0 ; put Timer0 in timer= mode to free up GP2 =A0 =A0 option =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; and ena= ble weak pull-ups =A0 =A0 clrf =A0 =A0GPIO =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; clear out= put (latch) =A0 =A0 clrf =A0 =A0shadow =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; and output = register shadow =A0 =A0 movlw =A0 0xff =A0 =A0 xorlw =A0 LED_MASK =A0 =A0 tris =A0 =A0GPIO =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; load tris BeginCountdown ; Wait 5 minutes then shut the door =A0 =A0 clrw =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; Ensur= e our port is in the proper state =A0 =A0 movwf =A0 shadow =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; before beginn= ing =A0 =A0 movwf =A0 GPIO =A0 =A0 movlw =A0 0xff =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; initialize = beeper =A0 =A0 movwf =A0 Beep =A0 =A0 movlw =A0 .2 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; set up ti= ming variables =A0 =A0 movwf =A0 TimerW =A0 =A0 movlw =A0 .252 =A0 =A0 movwf =A0 TimerE =A0 =A0 movlw =A0 .47 =A0 =A0 movwf =A0 TimerH =A0 =A0 movlw =A0 .245 =A0 =A0 movwf =A0 TimerL Delay5m =A0 =A0 nop =A0 =A0 nop =A0 =A0 nop =A0 =A0 nop =A0 =A0 nop =A0 =A0 nop =A0 =A0 decfsz =A0TimerL,f =A0 =A0 goto =A0 =A0Delay5m =A0 =A0 btfss =A0 DoIBeep =A0 =A0 goto =A0 =A0Delay5m.DecTmrH =A0 =A0 movlw =A0 LED_MASK =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; Sound a tone to= remind the user that =A0 =A0 xorwf =A0 shadow,W =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; the door is ope= n. =A0 =A0 movwf =A0 shadow =A0 =A0 movwf =A0 GPIO Delay5m.DecTmrH =A0 =A0 decfsz =A0TimerH,f =A0 =A0 goto =A0 =A0Delay5m =A0 =A0 movf =A0 =A0TimerE,W =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; Sound tone du= ring 6/256 TimerE iterations =A0 =A0 andlw =A0 b'11111000' =A0 =A0 =A0 =A0 =A0 =A0 ; Throw out the lower= 3 bits. =A0 =A0 xorlw =A0 b'11111000' =A0 =A0 =A0 =A0 =A0 =A0 ; Compare the upper 5= .. =A0 =A0 btfss =A0 STATUS,Z =A0 =A0 goto =A0 =A0Dec5m.DecTmrE =A0 =A0 movlw =A0 0xff =A0 =A0 xorwf =A0 Beep,f Dec5m.DecTmrE =A0 =A0 decfsz =A0TimerE,f =A0 =A0 goto =A0 =A0Delay5m =A0 =A0 decfsz =A0TimerW,f =A0 =A0 goto =A0 =A0Delay5m KeepGoing =A0 =A0 END =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; Direc= tive 'end of program' =20 --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .