Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Junebug help??

Status
Not open for further replies.
On junebug dip switchs

I have an 18F1320 on a perf board
I want to program said chip
do I switch dip switch 1, 2, 3 off then compile-program F10
then can I verify the program
When I hit F10 nothing lite up = LEDs
 
Hope I did this right

Its a bugger getting the PIC installed in its socket.
I have an insert er tool but it doesn't cover all 18 pins
I set dip sw 1=off
2=on
3=on
4=on
5=on
6&7 off
hit F10 and busy led flashes
must be programmed?
can I verify or just pull PIC out and insert onto breadboard?
fingers crossed for sure.
 
I think you need to revisit the 386 datasheet. The quiescent current is 4mA, when outputting 0.25W it will require something like 90mA.

If you're programming a pic on an external board then all dip switches should be OFF on the Junebug.

Mike.
 
It WORKED!!!!

I programmed the PIC with 2-5 on all else off
don't know if its right but ????
now comes the hard part
programming with the revised code as per suggestions
hook up the PIR but not the extra dip switch-using a bread board
figure just use jumper wires for the dip switch simulation.
I need to have a way to program the PIC on the breadboard.
Its a bear pulling the chip out of the programming socket and inserting into the breadboard unless I build circuit on the programming perf board.
figure I would take a 14 pin socket, solder a 5 conductor ribbon cable to the socket on the 5 pins needed, then run 5 jumpers on the breadboard to the 14 pin socket.
already bent 2 pins back into shape!!! grrrr
 
missed the 90ma on data sheet

coarse not real savy on reading data sheets.
I guess I should leave the 2n2222 in or something better??
the speakers are either
665-AT-1620-TWTR
or
665-AS02808MR2R
at Mouser.com
opting for the second one
 
revised code says error in then statement

but its a else statement??
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
[COLOR="Red"]Else //otherwise[/COLOR]
Tone=5 //silence
i=Rand(255) //make rand more random
EndIf //end if condition
Wend //end of while loop
 
Well I took you word for it MRdeb Mike right it will not power from a port pin it pulls 55.5 up to his figure of 90 mA depending on how you hook it up.
 
You should put the indentation back and you will see that you have code that makes no sense.

An if statement requires an endif and can have an optional else statement. It is indented to indicate which endif goes with which if.

This code has the indentation and is easier to follow,
Code:
[COLOR="Blue"]While[/COLOR](TRUE)             //repeat forever
    [COLOR="Red"]If[/COLOR] PORTB.0=0 Then       //if button 1 pressed
        [COLOR="Lime"]For[/COLOR] i = 1 To 200    //play 10 tones
            Tone=Rand(5)    //each tone is random frequency
            DelayMS(250)    //and for 0.25 seconds
        [COLOR="lime"]Next[/COLOR]                //end for loop
    [COLOR="red"]Else[/COLOR]                    //otherwise
        Tone=5              //silence
        i=Rand(255)         //make rand more random
    [COLOR="red"]EndIf [/COLOR]                  //end if condition
[COLOR="blue"]Wend[/COLOR]                    //end of while loop

Note that the instruction coloured the same have the same indentation and so we know where the If...endif statement starts and finishes (same with while...wend and for..next). In the above if Portb.0 is 0 then the code between the if and else lines gets executed, if Portb.0 is not 0 then the code between the else and endif is executed.

Try to match up ifs with endifs in your code and you will see the problem.

Mike.
 
Last edited:
How do I prevent swordfish from

moving the indents?
you mentioned adding
Code:
 and
when and where o put
and how did you get all that color??
 
As you can see you typed [code] and [/code] and it was converted to

Code:
 and

Swordfish should have the indents as I posted earlier and all you do is copy and paste between the code tags. To get the colour you hit the "Go Advanced" button and you can select the text and then a colour.

Mike.
 
I actually changed some code!!

I found in the editor options you can define color of different items as well as font etc.
still not clear on the
Code:
 tags
did I post it right?
[code]While(TRUE) //repeat forever
    If PORTB.2=1 Then //if PIR activated portRB2 is high
    PORTB.1=1 speed=200
    PORTB.0=1 TUNE=50
    

    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

I changed the speed and # of tunes (read the dip switches)
Need to have a better way to test this code instead of pulling out the chip when I make changes.
Have a 10 pin ICD plug soldered to board, program chip, remove and insert into breadboard.Header pins would be nice
need to figure out longword and byte
 
MrDEB The code tag he been telling you about is to post your code on the form like you have just started doing. It keeps your code formatted. And when you write use the tab key to keep your code tags inline easy to see if left one out
Code:
While True
    If Then    //tab end 1 time
        Else    //tab end 3 times
    EndIf      // same tab as if so you can see you you closed it
wend 

// thats easy to see what you did and make sure you put the right tags
// this is hard to see what you did
    While True
    If Then
    Else
    EndIf
    If Then
    ElseIf
    Wend
the last part I didn't put a ENDIF in it hard to see because I had ELSIF
 
port B3 on all the time?

when I changed the PIR from A0 to B2 port B3 is on always.
even disconnected the PIR B3 stays on.
do I need to Tris (havn't figured out what Tris is) or add a Dim PortB2
In my original configuration I didn't have a Dim for A0
my thinking is B2 is always high Supposed to be low then high when PIR triggers.
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
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
    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
    PORTB.1=1 speed=200
    PORTB.0=1 TUNE=50
    

    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
 
getting portb2 to go low

waiting for a high from the PIR
I disconnected the PIR, even connected the PortB2 to ground(pin 17)
the dang thing stays on, won't shut off
What do I need to do??
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 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=0 //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=$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
    PIRTRIS=1
    Seed=$12345678 //seed random number
WHILE(TRUE) //repeat forever
    IF PORTB.2=1 THEN //if PIR activated portRB2 is high
    PORTB.1=1 speed=200
    PORTB.0=1 TUNE=50
    

    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
 
The PIR you have looks like what I got from parallax which radio shack sells it had two setting one makes it act like switch that's the one you want. It can take 2 minutes for the PIR to start working right
 
Last edited:
Check the voltage on PORTB.2, it should be 0V and go to 5V when the PIR is triggered. Didn't you mention that it only outputs 3V, if so that could be the problem.

I also noticed a bugette (a little bug) in the initialisation code. ADCON1=$70 should be ADCON1=$7f for all digital.

Mike.
 
YES the PIR outputs only 3 v

Thats one of the reasons I had a transistor to take the port low.
BUT the breadboarded circuit is on with or without the PIR connected.
I even tried grounding RB2
the circuit worked using the orginal code where PORTB.0=0(only code I find that refers to portB.0
and the ADCON1=$70 is in the original code.
I have been refering back to the original code to see if I missed something.
Will need to add the PIR trigger transistor back in, change the code for it.
thinking about going back to the orginal code but the unit will use less current using an interrupt as suggested bu be80be. PUT little PICey to sleep.
will change the ADCON1 first then proceed on unless any more ideas?
I think I should remove the Dip Switch routine and get the PIR thingy working first but removing the PIR from the circuit and the circuit stays triggered has me baffled.
 
one problem after another now

I tried breadboarding the connections from the perf board I have an 18 pin socket soldered to Junebug.
It was programming the chip just using Swordfish
Well seems therecwas/is a VDD error using pickit2 prg (wanted to verify the communication between Junebug and the perf board
After I soldered 5 wires to the perf board so I could plug into the breadboard and program the PIC without pulling it out all the time I keep getting VDD error using pickit2.
Will the junebug/pickit2 communicate with the dip switches set
1=off
2-5 on
6-8 off
 
Pommie said you set all dip switches to off for ICSP programming
If you're programming a pic on an external board then all dip switches should be OFF on the Junebug.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top