added an LM386
took 2n2222 out, added an LM386 to con5(RB3)
changed pieces of the code and POW!!
them deer are gona run for the hills (hopefully)
hav'nt figured out how to leave the formatting in when copying n pasting
do I nessarly need to erase the chip when changing the code. sometimes I have to hit F10 twice??
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : Doug Bezaire *
* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 4/16/2009 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
{
************************************************** ***************************
* Name : sound freq gen.BAS *
* Author : *
* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 4/15/2009 *
* Version : 1.0 *
* Notes : *
* : *
************************************************** ***************************
}
Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Dim NOT_RBPU As INTCON2.7
Dim TMR1IE As PIE1.0
Dim TMR1IF As PIR1.0
Dim TMR1 As TMR1L.AsWord
Dim Speaker As PORTB.3
Dim SpeakerTris As TRISB.3
//global variables
Dim Seed As LongWord, Tone As Byte
Dim i As Byte
//half period delays = clock speed divided by 2*frequency
Const Tones(18) As Word = (2000000/12000,2000000/10000,2000000/8000,2000000/6000,2000000/4000,1000,
2000000/12000,2000000/10000,2000000/8000,2000000/6000,2000000/4000,1000,2000000/12000,2000000/10000,2000000/8000,2000000/6000,2000000/4000,1000)
//interrupt routine
Interrupt MyInt()
T1CON.0=0 //stop timer
TMR1=-Tones(Tone) //reset period
T1CON.0=1 //restart timer
If Tone=5 Then //if silence
Speaker=0 //speaker off
Else //otherwise
Toggle(Speaker) //make sound
EndIf
TMR1IF=0 //clear interrupt flag
End Interrupt
Function Rand(Range As Byte) As Byte
Dim i As Byte, feed As Bit, temp As Word
For i = 0 To 7 //generate 8 bits
Feed = Seed.30 Xor Seed.27 //make new bit
Seed=Seed*2+Feed //shift seed left and add new bit
Next
Temp=(Seed And 255) * Range //change Rand from 0 to 255
Rand = Temp/256 //to 0 to (Range-1)
End Function
//main code starts here
OSCCON = $72 //select 8MHz internal clock
NOT_RBPU=0 //WPUs on port B
ADCON1=$70 //all digital
T1CON = %10000001 //pre=1
Tone=5 //no sound please
TMR1IE=1 //enable timer 1 interrupt
Enable(MyInt) //set interrupt going
SpeakerTris=0 //Setup Port
Seed=$12345678 //seed random number
While(TRUE) //repeat forever
If PORTB.0=0 Then //if button 1 pressed add PIR here
For i = 1 To 200 //play 20 tones
Tone=Rand(5) //each tone is random frequency
DelayMS(25) //and for 1.00 seconds
Next //end for loop
Else //otherwise
Tone=5 //silence
i=Rand(255) //make rand more random
EndIf //end if condition
Wend //end of while loop