Device = 18F1320
Clock = 8
Include "ISRTimer.bas"
// constant ID to 4 * 16 bit timers...
Const
Timer1 = 0,
Timer2 = 1,
Timer3 = 2,
Timer4 = 3
// OnTimer1 event...
Event OnTimer1()
Toggle(PORTB.0)//pin 8
End Event
// OnTimer2 event...
Event OnTimer2()
Toggle(PORTB.1)//pin9
End Event
// OnTimer3 event...
Event OnTimer3()
Toggle(PORTB.2)//pin 17
End Event
// activate the timer module...
Timer.Initialize
// initialise the timers - refresh every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 50 // 50ms
Timer.Items(Timer1).OnTimer = OnTimer1 // timer event handler
Timer.Items(Timer2).Interval = 250 // 250ms
Timer.Items(Timer2).OnTimer = OnTimer2 // timer event handler
Timer.Items(Timer3).Interval = 500 // 500ms
Timer.Items(Timer3).OnTimer = OnTimer3 // timer event handler
Timer.Items(Timer4).Interval =2000 // 2000ms, no event handler
// enable the timers...
Timer.Items(Timer1).Enabled = true
Timer.Items(Timer2).Enabled = true
Timer.Items(Timer3).Enabled = true
Timer.Items(Timer4).Enabled = true
// start processing all timers...
Timer.Start
// main program loop...
While true
// this is a polled timer, not event driven - check to see
// if it has timeout...
If Not Timer.Items(Timer4).Enabled Then
Toggle(PORTB.3)
Timer.Items(Timer4).Enabled = true
EndIf
// background flash LED...
High(PORTB.7)//pin 13
DelayMS(5)
Low(PORTB.7)//pin 13
DelayMS(5)
Wend
Interrupt MyInt()
TMR2IF=0
Count=Count+1
If Count=50 Then
Count=0
IntFlag=1
EndIf
End Interrupt
Sub Delay(Seconds as Word)
Dim x as Word
for x=0 to Seconds
While(IntFlag=0)
Wend
IntFlag=0
next
end sub
OSCCON = $72 // select 8MHz internal clock
ADCON1 = $7f //all digital
NOT_RBPU=0 //WPUs on port B
T2CON = %01001110 //pre=16 post=10
PR2 = 249 //=8000000/4/16/10/250 = 50Hz
TMR2IE=1 //enable timer 2 interrupts
Enable(MyInt) //set interrupt going
While true
LED(1) //light LED 1
Delay(5) //wait 5 seconds
LED(2) //light LED 2
Delay(1) //wait 1 second
Wend
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// speaker output port pin 18
dim SpeakerTris as TRISB.3
//Dim PIR As PORTB.2 // turns on PIR
//Dim PIRTris As TRISB.2
dim speed as byte
//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=$7f //all digita
TRISB.0=0 //make output
PORTB.0=1 //and high
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
speed = 25 //changes via dip switches
// If PORTB.2=0 Then //if PIR activated portRB2 is low
for i = 1 to 200 //play 20 tones
Tone=Rand(5) //each tone is random frequency
delayms(speed) //and for 25-200 seconds here is where I want to change
next //end for loop
// delayms(100)
//delayms(200)
// Enable(MyInt) //set interrupt going
// Else //otherwise
Tone=5 //silence
i=Rand(255) //make rand more random
// EndIf //end if condition
Tone=5 //silence
i=Rand(255) //make rand more random
// PORTB.0 = 0//to save power put to sleep
delayms(200)// MY LATEST ATTEMPT
TMR1IF=0 //clear interrupt flag
enable(MyInt) //set interrupt going
end //end of while loop
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 de_lay as PORTB.0
//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
while (true)
if de_lay = 0 then
enable(MyInt) //set interrupt going
SpeakerTris=0 //Setup Port
Seed=$12345678 //seed random number
//de_lay=0
//while(TRUE) //repeat forever
//if de_lay=0 then //if button 1 pressed add PIR here pin 8
//toggle (de_lay)
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
de_lay=1
else //otherwise if pin 8 is high
//time delay
Tone=5 //silence
i=Rand(255) //make rand more random
endif //end if condition
delayms(10000)// INSERT a long 10 minute delay here then start all over
// at WHILE TRUE
wend //end of while loop
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 TMR2IE as PIE1.1
dim TMR2IF as PIR1.1
dim TMR1 as TMR1L.AsWord
dim Speaker as PORTB.3// speaker output port pin 18
dim SpeakerTris as TRISB.3
//global variables
dim Seed as longword, Tone as byte
dim i as word, count as byte
dim speed as byte
dim IntFlag as bit
//half period delays = clock speed divided by 2*frequency
const Tones(6) as word = (2000000/12000,2000000/10000,2000000/8000,2000000/6000,2000000/4000,1000)
//interrupt routine
interrupt MyInt()
if TMR1IF=1 then
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
endif
if TMR2IF = 1 then
TMR2IF=0
Count=Count+1
If Count=50 Then
Count=0
IntFlag=1
endif
EndIf
end interrupt
Sub Delay(Seconds as Word)
Dim x as Word
for x=0 to Seconds
While(IntFlag=0)
Wend
IntFlag=0
next
end sub
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=$7f //all digita
TRISB.0=0 //make output
PORTB.0=1 //and high
T1CON = %10000001 //pre=1
Tone=5 //no sound please
TMR1IE=1 //enable timer 1 interrupt
T2CON = %01001110 //pre=16 post=10
PR2 = 249 //=8000000/4/16/10/250 = 50Hz
TMR2IE=1 //enable timer 2 interrupts
enable(MyInt) //set interrupt going
SpeakerTris=0 //Setup Port
Seed=$12345678 //seed random number
speed = 25 //changes via dip switches
while TRUE
for i = 1 to 5*60 //play for 5 minutes
while IntFlag=0
Tone=Rand(5) //each tone is random frequency
delayms(speed) //and for 25-200 seconds here is where I want to change
wend
IntFlag=0
next //end for loop
Tone=5 //silence
i=Rand(255) //make rand more random
Delay(10*60) //delay 10 minutes
WEND
end
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?