Looks like you would want them all off to meSW6-1* Tutor (PK2 controls 18F1320 MCLR), free running mode & SW5 RESET
SW6-2 * Tutor (PK2 controls 18F1320 PGD)
SW6-3 * Tutor (PK2 controls 18F1320 PGC)
SW6-4 TX Uses PGD for PICkit 2 UART test mode (PICkit 2 software)
SW6-5 RX Uses PGC for PICkit 2 UART test mode (PICkit 2 software)
SW6-6 IR IN (38KHz IR) receiver on, Pushbutton 1 is always enabled
SW6-7 VR2 (0-5V pot) or USER port RA3 I/O
SW6-8 VR1 (0-5V pot) or USER port RA1 I/O
Reset switch SW4 will function when SW6-1 is off. Remember you can control reset via MPLAB.
* Turn SW6-1,2,3 OFF to when using the ICD connector (CON2)
If PIR = 1 then //see if it is high
delayMs(250) // so you don't get bad triggers
endif
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
If PIR = 1 then //see if it is high
delayMs(250) // so you don't get bad triggers
endif
ELSE //otherwise
TOGGLE(Speaker) //make sound
ENDIF
TMR1IF=0 //clear interrupt flag
END INTERRUPT
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 dip3TRIS AS TRISB.1 //changes delay dip switch setting
DIM dip4 AS PORTB.0 //changes # of tones dip switch setting
DIM dip4TRIS AS TRISB.0
DIM PIR AS PORTB.2 // turns on PIR
DIM PIRTris AS TRISB.2
DIM speed AS BYTE
DIM TUNE 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
Amp=0 // amp off
PIR=1 //PIR 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=$71 //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
PIRTris=1
Seed=$12345678 //seed random number
WHILE(TRUE) //repeat forever
IF PORTB.2=0 THEN //if PIR activated portRB2 is high
PORTB.1=1 speed=200 //dip switch
PORTB.0=1 TUNE=50 // dip switch
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
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
DIM dip3TRIS AS TRISB.1 //changes delay
DIM dip4 AS PORTB.0 //changes # of tones
DIM dip4TRIS AS TRISB.0
DIM PIR AS PORTB.2 // turns on PIR
DIM PIRTris AS TRISB.2
DIM speed AS BYTE
DIM TUNE 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
Amp=0 // amp off
PIR=1 //PIR 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=$71 //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
PIRTris=1
Seed=$12345678 //seed random number
WHILE(TRUE) //repeat forever
IF PORTB.2=0 THEN //if PIR activated portRB2 is low
PORTB.1=0 speed=25
PORTB.1=1 speed=200
FOR i = 1 TO 200 //play 20 tones
Tone=Rand(5) //each tone is random frequency
DELAYMS(25) //and for 25-200 seconds [COLOR="Red"]here is where I want to change[/COLOR]
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
WHILE(TRUE) //repeat forever
if PORTB.1=0 then
speed=25
else
speed=200
endif
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
ELSE //otherwise
Tone=5 //silence
i=Rand(255) //make rand more random
ENDIF //end if condition
WEND //end of while loop
ENABLE(MyInt) //set interrupt going
SpeakerTris=0 //Setup Port
PIRTris=1
Seed=$12345678 //seed random number
WHILE(TRUE) //repeat forever
WHILE(TRUE) //repeat forever
if PORTB.1=0 then
speed=25
else
speed=200
endif
WHILE(TRUE) //repeat forever
if PORTa.0=0 then
speed=100
else
speed=25
endif
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
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
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 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 dip1 AS PORTa.1
DIM dip1TRIS AS TRISa.1 //changes speed
DIM dip2 AS PORTa.2
DIM dip2TRIS AS TRISa.2 //changes speed
DIM dip3 AS PORTa.3
DIM dip3TRIS AS TRISa.3 //changes speed
DIM dip4 AS PORTa.4 //changes # of tones
DIM dip4TRIS AS TRISa.4
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)
[COLOR="Red"]Const [/COLOR]
[COLOR="Red"] constArray(4) as byte=(25,40,55,70)
[COLOR="Red"]for array = 0 to bound(4)[/COLOR]
[COLOR="Red"] dip1=25 //dip switch values[/COLOR]
[COLOR="Red"]dip2=40[/COLOR]
[COLOR="Red"]dip3=55[/COLOR]
[COLOR="Red"]dip4=70[/COLOR]
speed()=dip1+dip2+dip3+dip4
next[/COLOR]
end
//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
PIR=1 //PIR off
ELSE //otherwise
TOGGLE(Speaker) //make sound
TOGGLE(Amp)//turn amp on
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=$71 //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
PIRTris=1
Seed=$12345678 //seed random number
WHILE(TRUE) //repeat forever
WHILE(TRUE) //repeat forever
speed=dip1+dip2+dip3+dip4
ELSE
speed=200
ENDIF
WHILE(TRUE) //repeat forever
IF PORTB.0=0 THEN
speed=25
PORTB.1=0 THEN speed+50
ELSE
speed=25
ENDIF
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
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
WEND //end of while loop
Const
dim speed(4) as byte=(25,40,55,70)
for speed = 0 to bound(4)
if dip1=1 then speed(1) //dip switch values
if dip2=1 then speed(2)
if dip3=1 then speed(3)
if dip4=1 then speed(4)
speed()=speed(1+2+3+4)
end
That would be nice if the thereYou need to find a good tutorial on Basic
That's from swordfishbasic real help full more like what Mike saidBeginningSFBasic
Module Options
Many Swordfish modules are configured at compile time using options. For example,
#option LCD_RS = PORTE.0
Make sure that the #option is declared before the module is included. If you declare the option after the include file, it will be ignored.
Strings
When declaring strings, don't forget to allow enough space for the null terminator. For example, if you want to declare a 3 character string, you need to use
dim MyStr as string(4)
If you don't explicitly give a string dimension, Swordfish defaults to 24. That is, 23 characters plus a null terminator.
Variables
Public or Private?
With in SwordFish a variable can be thought of in 2 states Static (Public) eg will not be touched by the compiler, or recycled (Private) where once the Function/Sub has finished it will be recycled for use by other routines.
Not quite correct...
It's better to think in terms of scope. A module level variable (that is, a variable not declared in a sub or function) is static, but it can be public or private. Every sub or function within a module can see a module level variable - even if it is private (and assuming it is declared before it is referenced). However, if you import a module into another module or program, only public variables can be seen. In programming terms, public subroutines, functions and variables are the modules 'interface'
Variables declared withing a subroutine or function are of course private to the routine they are declared in - referred to as 'local'. Parameters are local in terms of scope. For example, you cannot reference a parameter by name outside the procedure it is declared in. However, parameters do provide the 'interface' to a sub or function.
All 'local' variables (parameters and variables) are recycled by the compiler. Module level variables (private or public) are not recycled and are static.
Hope the above is useful...
David Barker
To understand how you the variable you declared is seen by the compiler you have to think of the different context the compiler sees the variable in.
1 Main, this is with in the main program i.e not with in a Module or a Function/Sub Variables declared here................
To be continued once I get my facts right
Please correct add to this section by editing it, just click the Edit button below
MrDeb It takes time to do this when you have to learn how to write the code and the more you add to it the harder it gets. Mike posted you a good code to start with. But you need to learn that part and how it works before adding to it. Or you will never get done with it.how can I put this politely, rubbish.
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?