;==================================================================== ; ; Christhmas card Beeper using the 10F200/202/204/206/220/222 ; ; GP0 ---v--- GP3 ; -|1 6|-----------------------+ ; | Vss | | Vdd | ; +--||-(-) -|2 5|-----+(+ 3 to 5 Volts) | ; | | | | | | | | ; | 3V -|3 4|-----------|[]|--------+ ; | GP1 ------- GP2 | | | ; | | piezo element ; +------------------------+ ; ;==================================================================== ; processor type declaration LIST P=10F200 ; include file for register file name definitions #include ; configuration bits __CONFIG _MCLRE_OFF&_CP_OFF&_WDT_OFF ; default radix - hex for compact representation of note table radix hex ;-------------------------------------------------------------------- ; variables in RAM cblock 10 flags count1 count2 note COUNTER endc ;-------------------------------------------------------------------- ; flag bit definitions rest equ 0 tmrh equ 1 ;-------------------------------------------------------------------- ; note equates - loop overhead is 21 counts, so the note delay is ; the equated value plus 21 ;Note equated Delay Chromatic ;Name value cycles note La equ 0ff ; 276 - A2 Le equ 0ef ; 230 - A2# Te equ 0e1 ; 246 - B2 do equ 0d3 ; 232 - C2 di equ 0c6 ; 219 - C2# ra equ 0ba ; 207 - D2 re equ 0ae ; 195 - D2# mi equ 0a3 ; 184 - E2 fa equ 099 ; 174 - F2 fe equ 08f ; 164 - F2# so equ 086 ; 155 - G2 se equ 07d ; 146 - G2# la equ 075 ; 138 - A3 le equ 06d ; 130 - A3# te equ 066 ; 123 - B3 dO equ 05f ; 116 - C3 dI equ 059 ; 110 - C3# rA equ 052 ; 103 - D3 rE equ 04c ; 97 - D3# mI equ 047 ; 92 - E3 ; The above note table is based on data ; provided by Don Lancaster at www.tinaja.com ; "Equally tempered Music" ; 116-123-130-138-146-155-164-174-184-195-207-219-232 ;-------------------------------------------------------------------- ; Program overhead is 54 instructions leaving 202 locations available ; for notes in the pic10f200/204/220. ; 255 notes can be fitted into the pic10f202/206/222. ; ***** tested with 200 & 206 only.***** ;==================================================================== ; Program code starts here org 0 goto continue ; program code is placed after table entries ; because table entries must be in the first 256 locations ;-------------------------------------------------------------------- table ; table of values for note delay - 1 = rest, 0 = end. addwf PCL,F ;scale Te doh ray mi fa so la te dOh rest end ;dt 0e1,0d3,0ba,0a3,099,086,075,066,05f,001, 0 ;-------------------------------------------------------------------- song1 ;dt mi,mi,mi,mi,ra,mi,fa,fa,mi,mi,mi,ra,do,do,mi,mi ;dt ra,ra,ra,do,Te,Te,ra,ra,do,do,do,1 ;dt so,so,so,la,so,fa,mi,fa,so,1 ;dt so,la,so,fa,mi,fa,so,1 ;dt so,la,so,fa,mi,so,fa,mi,ra,ra,do,ra ;dt mi,mi,mi,mi,ra,mi,fa,fa,mi,mi,mi,ra,do,do,mi,mi ;dt ra,ra,ra,do,Te,Te,ra,ra,do,do,do,1,1,0 ;-------------------------------------------------------------------- song2 ;dt dO,te,dO,dO,so,1,fa,mi,fa,fa,ra,1 ;dt mi,fa,so,so,so,fa,mi,ra,mi,mi,1,1 ;dt ra,mi,fa,fa,fa,1,mi,ra,mi,mi,mi,1 ;dt do,1,do,mi,ra,1,do,Te,do,do,do,1,1 ;dt so,so,so,1,so,1,so,so,so,1,so,1 ;dt fa,fa,la,la,1,la,so,fa,fa,fa,1,1 ;dt so,fa,mi,mi,mi,1,fa,mi,ra,ra,ra,1 ;dt mi,ra,do,do,Te,La,Te,do,do,do,1,1,0 ;-------------------------------------------------------------------- song3 ; dt do,do,ra,ra,1,fa,so,fa,so,so,so,1 ; dt fa,fa,so,so,1,te,dO,te,dO,dO,dO,1 ; dt dO,rA,le,le,la,so,so,1,so,la,fa,fa,mi,ra,ra,1 ; dt ra,ra,so,fa,mi,fa,ra,mi,do,do,do,1 ; dt do,do,ra,fa,so,fa,so,so,1,la,le,la,la,so,so,1 ; dt fa,fa,so,so,1,te,dO,te,dO,dO,dO,dO,1 ; dt fa,fa,so,so,1,te,dO,te,dO,dO,dO,dO,1,1,1,1,0 ;-------------------------------------------------------------------- song4 ;dt so,so,1,mi,so,dO,te,la,so,so,so,1,1 ;dt fa,fa,1,mi,ra,la,so,fa,mi,mi,mi,mi,1,1 ;dt so,so,1,mi,so,mi,so,dO,la,la,la,1,1 ;dt te,te,1,dO,te,la,so,fe,so,so,so,1,1 ;dt so,so,so,1,mi,mi,mi,1,dO,dO,dO,1,so,so,so,1 ;dt mI,mI,1,rA,dO,la,so,mi,ra,ra,mi,mi,fa,fa,fa,1,1 ;dt mi,mi,1,mi,mi,mi,fa,so,la,la,la,1,1 ;dt te,dO,so,so,mi,mi,fa,fa,Te,Te,do,do,do,1,1,1,1,1,1,0 ;-------------------------------------------------------------------- song5 ; Go, tell it on the mountain dt mi,mi,1,mi,ra,do,La,so,so,so,1,do,do,do,1 ; Over the hills and everywhere dt ra,ra,1,ra,ra,do,do,mi,mi,so,so,la,so,so,1 ; Go, tell it on the mountain dt mi,mi,1,mi,ra,do,La,so,so,so,1,do,do,do,1 ; That Jesus Christ is born. dt fa,1,mi,mi,1,ra,ra,ra,ra,do,do,do,do,do,1,1,1,1 ; While shepherds kept their watching dt do,do,mi,mi,so,1,so,so,la,la,so,so,mi,mi,mi,1,1 ; O'er silent flocks by night dt do,do,ra,ra,ra,ra,do,do,ra,ra,mi,mi,1,1 ; Behold, throughout the heavens dt do,do,mi,mi,so,1,so,so,la,la,so,so,mi,mi,mi,1,1 ; There shone a holy light. dt do,do,ra,ra,ra,ra,do,do,La,La,so,so,Te,Te,ra,ra,ra,1,0 ;-------------------------------------------------------------------- ; Program code continues here continue movwf OSCCAL start ; movlw 7 ;******* uncomment for 10F206 ********** ; movwf CMCON0 ;switch off comparator ****************** movlw 0xc7 ;prescaler 256 for timer, pullups disabled option movlw 0 ;all pins output tris GPIO movlw 1 movwf GPIO ;GP0 high, GP2 and GP3 low clrf count1 ;clear note count clrf flags ;clear flags register ;-------------------------------------------------------------------- ; initialisation over, endless loop starts here forever movlw 5 ; note length in terms of timer0 rollover movwf count2 movf count1,W call table iorlw 0 skpnz goto start ; if note value zero start all over again movwf note bcf flags,rest decfsz note,w bsf flags,rest ; if note value = 1 set pause flag third bcf flags,tmrh ; clear copy of timer high flag decfsz count2,F ; decrement note length count and loop goto first ; if it is nonzero incf count1,F ; increment note count and get next note goto forever ; if it is zero ;-------------------------------------------------------------------- ; during note duration repeatedly delay and toggle pins first btfss TMR0,7 ; test MSB of timer goto timerhi ; jump if high btfss flags,tmrh ; timer MSB is low, so test flag goto second ; if flag is also low do nothing goto third ; they don't match, so next interval. timerhi bsf flags,tmrh second btfsc flags,rest ; if a rest is wanted don't Beep call Beep goto first ;-------------------------------------------------------------------- Beep ; toggle GPIO pins and delay movf note,w movwf COUNTER movlw 3 ; mask for GP0 and GP1 xorwf GPIO,F ; toggle GP0 and GP1 ;-------------------------------------------------------------------- ; The delay routine below is from Don Lancaster, www.tinaja.com ;-------------------------------------------------------------------- ; Code module to provide a time delay of n instruction ; cycles. n can vary from 4 to 255 and is destructively ; read from COUNTER. There are 8 or 9 overhead cycles. ; The module is easily extended to 9 or 10 bits. DELAY BCF STATUS,C ; clear carry (if needed) RRF COUNTER,1 ; bit 0 into carry BTFSC STATUS,C ; stall one cycle? GOTO EQ1 ; yes, one extra cycle EQ1 BCF STATUS,C ; must clear carry RRF COUNTER,1 ; bit 1 into carry BTFSS STATUS,C ; stall two cycles? GOTO LOOP ; no, no extra cycles GOTO EQ2 ; yes, two extra cycles EQ2 NOP LOOP BCF STATUS,C ; 4*n cycle delay loop DECFSZ COUNTER,F GOTO LOOP ; round and round till done RETLW 0 ; return to calling routine ;-------------------------------------------------------------------- end ; end of program ;====================================================================