I have attached a small file which shows how to implement a noise generator with a 12C509. This can be easily modified for the 16F84, of which I have done. The code is not originally mine. Credits are given in the file... Nino Code follows... ; ; Pseudorandom digital white noise generator for PIC series. ; ; PIC12C508 version written April 7th, 1997 by Scott Rider. ; Questions/comment to chip@aeug.org ; ; PIC12C509 modified version by Antonio L. Benci. 22/03/1999. ; ; This program uses Microchip assembler mnemonics and the Microchip ; MPASM assembler (http://www.microchip.com/). Default config options ; are set in the __FUSES line below: MCLRE off, CP off, WDT off, OSC=INTRC. ; ; _______ _______ ; | \/ | ; (+5V) Vdd --+ 1 8 +-- Vss (GND) ; | | 470 ; X1/CLKI/GP5 --+ 2 7 +-- GP0 (audio out) --/\/\/-- (spkr) ; (not used) | | | 10K 1uF ; X2/CLKO/GP4 --+ 3 6 +-- GP1 --/\/\/--|(-- (line) ; (swt input) | | (swt input) ; GP3/!MCLR --+ 4 5 +-- GP2 ; (swt input) | (PIC12C508) | (swt input) ; +----------------+ ; ; This program generates a continuous stream of white noise through a ; speaker connected (via a 470-ohm series resistor) to pin GP0 of a ; PIC12C509. It demonstrates an easy method for generating a seemingly ; random stream of bits. Hardware folks will probably recognize it as the ; tapped shift register technique covered in the CMOS Cookbook by Don ; Lancaster. ; ; Adapted from the original PIC16C54 (Parallax) version by Scott Edwards. ; ;########################################################################## ; ; Programmable noise weighting added by A L Benci 22/03/1999 ; ; GP1..GP4 are connected to a dip switch which the user can use to select ; 'textures' of 2 to 30. A zero value skips the function. ; ; list p=12c509 radix dec include "p12c509.inc" __FUSES _MCLRE_OFF &_CP_OFF & _WDT_OFF & _IntRC_OSC ;Internal osc. cblock 0x07 ;Variables i ;Loop counter x ;Scratch y ;Scratch zz ;Scratch sr0 ;32 bits of shift register sr1 sr2 sr3 ;/ endc org 0x0 ; ; PIC12C509 cold starts at 03FFF (where it loads a factory-programmed ; internal osc. calibrate value). It then rolls over to 0x0. ; movwf OSCCAL goto start ; ; Subroutines in 12-bit PIC series must go on bottom page of ROM. ; wait loop decfsz i,F goto loop retlw 0 ; ; Main code area traditionally starts at 0x100 on a 12-bit PIC. ; org 0x100 start movlw b'11000000' ;Turn off T0CKI option ;/ movlw b'00000000' ;Preset outputs to come up low movwf GPIO ;/ movlw b'00011110' ;Set the I/O direction (GP3..GP1 as inputs, GP0,GP5 as output) tris GPIO clrf sr0 ;Might as well start with a seed of zero. clrf sr1 clrf sr2 clrf sr3 ;/ ; ; The main loop 'taps' is 24 CPU cycles. At the 4MHz internal clock ; rate, the noise output is operating at a max. rate of about 21KHz. ; taps btfss sr3,6 ;Get bits 18 and 31 for the feedback XOR. bcf x,0 btfsc sr3,6 bsf x,0 ;Bit 31 -> x btfss sr2,1 bcf y,0 btfsc sr2,1 bsf y,0 ;Bit 18 -> y movf y,W ;!(x XOR y) -> carry xorwf x,F btfsc x,0 bcf STATUS,C btfss x,0 bsf STATUS,C ;/ rlf sr0,F ;32-bit shift rlf sr1,F rlf sr2,F rlf sr3,F ;/ ; ; Put a pseudorandom bit out to the speaker. In this example, GPIO bit 0 ; (pin 7 on the PIC12C509) is used. Be sure to use a 470 ohm resistor for ; speaker or 10K or better for input to an op-amp/divider/whatever. ; btfss sr3,7 ;line 1 bcf GPIO,0 ;line 2 btfsc sr3,7 ;line 3 bsf GPIO,0 ;line 4 ; ; Uncomment the following 'call wait' to experiment with changing the ; 'texture' of the noise (see 'wait' routine, above). movf GPIO,W ;read switch input andlw b'00011110' ;mask all but swt bits movwf i ;save value btfss STATUS,Z ;is result zero call wait ;Optional delay routine to alter sound goto taps ;Ad infinitum... ; ; That's all, folks! ; end -- ****************************************************** * Antonio (Nino) Benci * * Professional Officer / Electronic Services Manager * * Monash University - Dept of Physics * * Wellington Rd, Clayton. 3168 * * Victoria, Australia. * * TEL - 61 3 9905 3649, FAX - 61 3 9905 3637 * * Mobile - 0414 764 763 (private and ah only) * * EMAIL - nino.benci@sci.monash.edu.au (work) * * - fleatech@excite.com (private) * * WWW - www.physics.monash.edu.au/ * ****************************************************** Content-type: application/x-unknown-content-type-PFE32; name=noise509.asm Content-disposition: inline; filename=noise509.asm Attachment converted: wonderland:noise509.asm (????/----) (0000BF5E) Content-type: text/x-vcard; name=Nino.Benci.vcf; charset=us-ascii Content-description: Card for Antonio L Benci Content-disposition: attachment; filename=Nino.Benci.vcf Content-transfer-encoding: 7BIT Attachment converted: wonderland:Nino.Benci.vcf (TEXT/CSOm) (0000BF5F)