blueroomelectronics
Well-Known Member
10K is fine, you can also generally omit the diode.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
that to program lol bill posted at the same time* Turn SW6-1,2,3 OFF to when using the ICD connector (CON2)
I added battery, split batteries, removed diode and moved 2n2222NPN transistor
He sure has a short there lolThe moment Q1 is biased , the transistor would FAIL. Please cgeck your schematic. collector direct to Bty and Emitter direct to Gnd.
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
amp=0 //turn amp off
Else //otherwise
amp=1 //turn amp on
Toggle(Speaker) //make sound
EndIf
TMR1IF=0 //clear interrupt flag
End Interrupt
in swordfish I assume.
even thought about just zipping the file and posting?
tags[/b]
not sure I did the code tags right?
moved dip switch read into interrupt section and define amptris(oups I see I didn't capitalize Dim amp
}
[code]
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
DIM amp as PORTA.1 // turns on amp power
Dim ampTris As TRISA.1
Dim dip3 AS PORTB.1 //changes delay
DIM dip4 AS PORTB.0 //changes # of tones
//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
amp=0 // amp 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.2=1 Then //if PIR activated portRB2 is high
If PORTB.1=1 then speed=200
Else speed = 25
For i = 1 To 200 //play 20 tones
Tone=Rand(5) //each tone is random frequency
DelayMS(speed) //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
3ma load=LM386