hi! recently posted here was ;PROJECT :Siren Driver Module on 16c84 pic ;DONE BY :MARK E'SILVA ;COMPANY :DIGITRON ;ASSEMBLER :MPALC ;DATE :2/3/1998 a program to make various sound effects using a piezo squeeker. i assembled and ran the program and was charmed and delighted at the various sounds it made. then i started to rip apart the 15 sections of the program, one for each of 15 sound effects. it seems that this astonishing variety of noises/sounds were created using just two models: model 1, "tweedle": play one square wave tone for a while, then play a tone of a different frequency for a while. [code starts at "tweed", expecting parameters to have been set up]. this makes various alarm sounds (the "Waverly" or Man from U.N.C.L.E. annunciator) when the times are long, and makes a very plausible electronic telephone sound when times are medium and makes buzzes and growls when times are short. experiments left as an exercise for the reader. model 1, "siren": play square waves at a given frequency and periodically increase the frequency to a high limit at a certain rate and then decrease the frequency to a low limit at another, possibly different, rate. [code starts at "sirex", expecting parameters to have been set up]. this makes sirens, whoopers, laser gun fx and others. experiments left as an exercise for the reader. i share the re-written code at this point, 'cause the next things i do to it are gonna make it unsharable and not the best point of departure for you. sorry about an occasional Parallax/'51 type opcode, it should be clear what's going on. and please excuse the hatchet job on the original code - there is some correspondance to the first version, but no very strict use or coverage was intended. the code at this point is neither mine nor the original. i leave it to you to improve the test jig - i just re-programmed the poor chip dozens of times as i tinkered... shoulda known doing something that would have made it easier would have been worth the time. oh, hardware: dip switches four bits on rb4..7 pulling to ground for sound selection (reset to hear new sound) and a piezo squeeker on rb.0. clock the '84 at 4MHz. -- rob ; sound fx ; device pic16c84,xt_osc,wdt_off,pwrt_on,protect_off id 'beep' ; same equ 1 ;same register _pc equ 02h ;program counter _rtcc equ 01h ;rtcc _fsr equ 04h ;file select register _status equ 03h ;status register _carry equ 0 ;carry flag _zero equ 2 ;zero flag ; org 0Ch _lenth ds 1 sDly ds 1 sweep ds 1 freq ds 1 dTmp ds 1 pTmp ds 1 dipval ds 1 _flags ds 1 loF ds 1 ; lower f bound hiF ds 1 ; higher f bound loT ds 1 ; # cycles at low f hiT ds 1 ; # cycles at high f org 000h ;originate code here init movlw 0F0h ;0..3 output tris rb ; clrf rb ;resetting port b movlw 0FFh ; tris ra ; clrf ra ;resetting port a movlw 00Fh ;setup wdt 128:1 option ;pul ups off int clock enabled clrf _flags ;clear all flags diptest movf rb,w ;get dip value movwf dipval swapf dipval,same ; movf dipval,w andlw 0Fh jmp pc+w goto op0 goto op1 goto op2 goto op3 goto op4 goto op5 goto op6 goto op7 goto op8 goto op9 goto op10 goto op11 goto op12 goto op13 goto op14 goto op15 ;------------------------------------------------------------------------ op0 movlw 200 movwf hiF movlw 125 movwf hiT movlw 100 movwf loF movlw 250 movwf loT tweed bsf _flags,0 ; hi f first movf hiF,w movwf freq ; low f movf hiT,w movwf _lenth :pulse call once ; make one pulse decfsz _lenth,same ; time to change f? goto :pulse ; no btfsc _flags,0 ; going up or down? goto :up ; pitching up :down bsf _flags,0 ; change to hi f,t movf hiF,w movwf freq movf hiT,w movwf _lenth ; reset lenth goto :pulse :up bcf _flags,0 ; change to low f,t movf loF,w movwf freq movf loT,w movwf _lenth ; reset lenth goto :pulse ;----- op15 movlw 100 movwf hiF movlw 20 movwf hiT movlw 50 movwf loF movlw 40 movwf loT sirex bsf _flags,0 ; start going up movf loT,w ;255 /10 th = variable movwf _lenth ; movf loF,w ; movwf freq ; lower bound :pulse call once decfsz _lenth,same ; time to adjust f? goto :pulse ; no btfsc _flags,0 ; going up or down? goto :up ; pitching up :down movf hiT,w movwf _lenth ; reset lenth cjne freq,loF,:nyet0 ; reached low f? ;if loT is zero, just put hiF back into freq and continue cjne loT,#0,:ok0 movf hiF,w movwf freq goto :pulse :ok0 bsf _flags,0 ; change direction to up inc freq goto :pulse :nyet0 dec freq goto :pulse :up movf loT,w movwf _lenth ; reset lenth cjne freq,hiF,:nyet1 ; reached high f? ;if hiT is zero, just put loF back into freq and continue cjne hiT,#0,:ok1 movf loF,w movwf freq goto :pulse :ok1 bcf _flags,0 ; change direction to down dec freq goto :pulse :nyet1 inc freq goto :pulse ;-------------------------------------------------------------------------- once cjne freq,#255,:reg :shhh nop ; double delay 240 = 1 second call pit call pit call pit call pit retlw 0 :reg bsf rb,0 ;beeper on call pit ;variable pitch bcf rb,0 ;beeper off call pit ;variable pitch retlw 0 ;; pit movf freq,w ; movwf dTmp ; g clrwdt ;kick dog decfsz dTmp,same ; goto g ; retlw 0 ; ;-------------------------------------------------------------------------- op1 op8 op10 op11 op13 op14 op15 movlw 160 movwf hiF movlw 3 movwf hiT movlw 85 movwf loF movlw 3 movwf loT goto sirex ;-------------------------------------------------------------------------- op2 movlw 160 movwf hiF movlw 1 movwf hiT movlw 10 movwf loF movlw 1 movwf loT goto sirex ;-------------------------------------------------------------------------- op3 movlw 250 movwf hiF movlw 25 movwf hiT movlw 10 movwf loF movlw 25 movwf loT goto sirex ;-------------------------------------------------------------------------- op4 movlw 100 movwf hiF movlw 1 movwf hiT movlw 50 movwf loF movlw 40 movwf loT goto sirex ;-------------------------------------------------------------------------- op5 movlw 100 movwf hiF movlw 40 movwf hiT movlw 50 movwf loF movlw 1 movwf loT goto sirex ;-------------------------------------------------------------------------- op6 movlw 50 movwf hiF movlw 100 movwf hiT movlw 40 movwf loF movlw 100 movwf loT goto tweed ;------------------------------------------------------------------------ op7 movlw 175 movwf hiF movlw 80 movwf hiT movlw 175 movwf loF movlw 250 movwf loT goto tweed ;-------------------------------------------------------------------------- op9 movlw 40 movwf hiF movlw 2 movwf hiT movlw 254 movwf loF movlw 2 movwf loT goto tweed ;-------------------------------------------------------------------------- op12 movlw 40 movwf hiF movlw 255 movwf hiT movlw 255 ; silence movwf loF movlw 255 movwf loT goto tweed ;-------------------------------------------------------------------------- org 3ffh ; goto init ; END ; ;---------------------------- ; original code ;PROJECT :Siren Driver Module on 16c84 pic ;DONE BY :MARK E'SILVA ;COMPANY :DIGITRON ;ASSEMBLER :MPALC ;DATE :2/3/1998