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.

MrDEB

Well-Known Member
It WORKS!!

now I need to combine the 3 codes together then try and decipher what is happening in this code so I might learn something
still trying to decipher what %10111111 or what ever bit states are entered (I understand the numbers are bit states, 8 bits = 1 byte or is it 4 bits = 1 byte?
perhaps with the C+ language being close to swordfish, maybe buy a book??
 

MrDEB

Well-Known Member
going nuts in Salmon

been trying to run (test) the timer section of the code (it worked before?)
I copied n pasted code that worked but now it no workie??
procedure to test=
have code in swordfish
I erase the PIC using the pickit2=erase
I then hit f10
QUESTION = on the junebug I have all the dip switches off
using a 5 cond ribbon cable from junebug to perf board w/ target PIC and several LEDs connected to pins 8,9,17,18
after programmingthe pic I disconnect to 5 cond cable. then copnnect a battery to the perf board and see what the LEDs are doing . hopfully what I wanted them to do.
the timer code worked before??
back couple pages.
will locate and paste.
 

MrDEB

Well-Known Member
here is copy of previous post that worked

not sure how to post a link to another post?
I prg the PIC w/ orginal code that be80be posted, changed the B7 to 5ms
no short bursts of LEDs so shortning the ONTIME values affects everything?
pin 8 = 10-15 seconds on
pin 9 = 60 seconds on
pin 17 = 2 minutes on
timer 4 =2000 havn't figured out this on as no LED (port) to connect to.
Code:

}
// 18F1320@ 8MHz - they are just used here for clarity...
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
 

MrDEB

Well-Known Member
code still dosn't work??

it worked before but not now??
any suggestions as to why not??
I want to implement a simple timer for say 15-20 minutes.
I am thinking about the post using DELAYMS(xxx) and recur about 20 times
was looking at doing a boollean where
time = 1
delayms (200)
time = time + 1
if time = 20000 then end
 

be80be

Well-Known Member
I posted you some thing to go by even if your code runs it would take 10 to 20 min before the osc starts up your code flow is crazy
Every thing in red has to happen before it get's to the osc setting.
Code:
[COLOR="Red"]// your main code would look like this
 Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Dim day As Byte
Dim nite As Byte
Dim light As Byte
Dim checkPIR As Byte
Dim PlaySound As Byte


While true 
      If day = light Then PlaySound 
      ElseIf day = nite Then checkPIR 
      EndIf
      If checkPIR = true Then PlaySound
      EndIf
//Wend
end
      
     // then just make three functions One for day and night
     // One for PlaySound
     // One for checkPIR
     
// PLAY SOUND ROUTINE
     
    // Device = 18F1320
//Clock = 8 // 8MHz clock
//Config OSC = INTIO2, WDT = OFF, LVP = OFF
while  Playsound then
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 PORTB.1 // turns on amp power
Dim AmpTris As TRISB.1//turns on amp pin 9
Dim Speed As Word
Dim dip1 As PORTA.0

Dim dip2 As PORTA.1

Dim dip3 As PORTA.2

Dim dip4 As PORTA.3

Dim dipRD 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=$7f              //all digital
       TRISB.0=0               //make output
       PORTB.0=1 //makes pin 8 high for dip switches
       T1CON = %10000001       //pre=1
       T1CON = %10000001 //pre=1
       Tone=5 //no sound please
       TMR1IE=1 //enable timer 1 interrupt
       TRISA=%10111110         //A0 & 6 output
PORTA.7=1

While (true)
    Toggle(PORTA.0)
    
    
    DelayMS(200)
    Wend
End
Enable(MyInt) //set interrupt going
SpeakerTris=0 //Setup Port
Seed=$12345678 //seed random number
        TRISA =%00001111          //sets your inputs on porta 
While(TRUE) //repeat forever

    If dip1=1 Then //dip1 pin 1
       Speed=25
    EndIf
    
    If dip2=1 Then // dip 2 pin 2
       Speed=50 
    EndIf
    
    If dip3=1 Then //dip3 pin 6
       Speed=75
    EndIf
    
    If dip4=1 Then //dip4 pin 
       Speed=Rand(10)*15+15    //Speed = 25 to 250 random select speed
       
    EndIf
  
If PORTB.1=0 Then PlaySound //if night then PIR is enabled
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
wend

 //CHECK FOR DAYLIGHT OR DARK

Device = 18f1320
Clock = 8
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Include "Utils.bas"
Dim but As PORTB.0
Dim led As PORTA.0
SetAllDigital      //set digital so you can read RB0 or it will always read low
TRISA =%00000000  // if your using the junebug This is fool proof to get a led to lite
PORTA =%00000000  // Set's it all low
TRISB =%00000001  // Set's inputs and outputs 
PORTB =%00000000   // Set's it all low
INTCON2.7=0        // sets wpu on portb turns on pullups on PORTB
OSCCON = $72            // 8 MHz clock
While true              // this loops it so it keeps checking 
If day = nite Then checkPIR // enables PIR                
    DelayMS(10)       // small debounce delay
ElseIf day = light Then Timer.Initialize  // triggers on timer
   led =1                 // Turns on led
   DelayMS(10)       // small debounce delay
EndIf                     // closes your IF THEN statements 
Wend

End


//TIMER ROUTINE

// 18F1320@ 8MHz - they are just used here for clarity...
//Device = 18F1320
//Clock = 8

Include "ISRTimer.bas"          

// constant ID to 4 * 16 bit timers...
Const
   Timer1 = 0,
  
   Timer4 = 3
      
// OnTimer1 event...
Event OnTimer1()
   Toggle(PORTB.2)//pin 8
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 event handler
Timer.Items(Timer4).Interval = 200      // 2000ms, no event handler

// enable the timers...
Timer.Items(Timer1).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 day = light Then Timer.Items(Timer4).Enabled
   
      Toggle(PORTB.2)//pin 17 trigger playsound
      DelayMS(10) //change state
      Toggle(PORTB.2)//pin 17
      Timer.Items(Timer4).Enabled = true
   EndIf
    
 
Wend// your main code would look like this
 Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Dim day As Byte
Dim nite As Byte
Dim light As Byte
Dim checkPIR As Byte
Dim PlaySound As Byte


While true 
      If day = light Then PlaySound 
      ElseIf day = nite Then checkPIR 
      EndIf
      If checkPIR = true Then PlaySound
      EndIf
//Wend
end
      
     // then just make three functions One for day and night
     // One for PlaySound
     // One for checkPIR
     
// PLAY SOUND ROUTINE
     
    // Device = 18F1320
//Clock = 8 // 8MHz clock
//Config OSC = INTIO2, WDT = OFF, LVP = OFF
while  Playsound then
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 PORTB.1 // turns on amp power
Dim AmpTris As TRISB.1//turns on amp pin 9
Dim Speed As Word
Dim dip1 As PORTA.0

Dim dip2 As PORTA.1

Dim dip3 As PORTA.2

Dim dip4 As PORTA.3

Dim dipRD 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[/COLOR]
       NOT_RBPU=0              //WPUs on port B
       ADCON1=$7f              //all digital
       TRISB.0=0               //make output
       PORTB.0=1 //makes pin 8 high for dip switches
       T1CON = %10000001       //pre=1
       T1CON = %10000001 //pre=1
       Tone=5 //no sound please
       TMR1IE=1 //enable timer 1 interrupt
       TRISA=%10111110         //A0 & 6 output
PORTA.7=1

While (true)
    Toggle(PORTA.0)
    
    
    DelayMS(200)
    Wend
End
Enable(MyInt) //set interrupt going
SpeakerTris=0 //Setup Port
Seed=$12345678 //seed random number
        TRISA =%00001111          //sets your inputs on porta 
While(TRUE) //repeat forever

    If dip1=1 Then //dip1 pin 1
       Speed=25
    EndIf
    
    If dip2=1 Then // dip 2 pin 2
       Speed=50 
    EndIf
    
    If dip3=1 Then //dip3 pin 6
       Speed=75
    EndIf
    
    If dip4=1 Then //dip4 pin 
       Speed=Rand(10)*15+15    //Speed = 25 to 250 random select speed
       
    EndIf
  
If PORTB.1=0 Then PlaySound //if night then PIR is enabled
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
wend

 //CHECK FOR DAYLIGHT OR DARK

Device = 18f1320
Clock = 8
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Include "Utils.bas"
Dim but As PORTB.0
Dim led As PORTA.0
SetAllDigital      //set digital so you can read RB0 or it will always read low
TRISA =%00000000  // if your using the junebug This is fool proof to get a led to lite
PORTA =%00000000  // Set's it all low
TRISB =%00000001  // Set's inputs and outputs 
PORTB =%00000000   // Set's it all low
INTCON2.7=0        // sets wpu on portb turns on pullups on PORTB
OSCCON = $72            // 8 MHz clock
While true              // this loops it so it keeps checking 
If day = nite Then checkPIR // enables PIR                
    DelayMS(10)       // small debounce delay
ElseIf day = light Then Timer.Initialize  // triggers on timer
   led =1                 // Turns on led
   DelayMS(10)       // small debounce delay
EndIf                     // closes your IF THEN statements 
Wend

End


//TIMER ROUTINE

// 18F1320@ 8MHz - they are just used here for clarity...
//Device = 18F1320
//Clock = 8

Include "ISRTimer.bas"          

// constant ID to 4 * 16 bit timers...
Const
   Timer1 = 0,
  
   Timer4 = 3
      
// OnTimer1 event...
Event OnTimer1()
   Toggle(PORTB.2)//pin 8
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 event handler
Timer.Items(Timer4).Interval = 200      // 2000ms, no event handler

// enable the timers...
Timer.Items(Timer1).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 day = light Then Timer.Items(Timer4).Enabled
   
      Toggle(PORTB.2)//pin 17 trigger playsound
      DelayMS(10) //change state
      Toggle(PORTB.2)//pin 17
      Timer.Items(Timer4).Enabled = true
   EndIf
    
 
Wend
evey thing in red has to happen betfore it get's to the osc setting.
 

be80be

Well-Known Member
Boolean 1 True or False
was looking at doing a boollean where
time = 1
delayms (200)
time = time + 1
if time = 20000 then end
How is that true or false Boolean is just true or false
 

MrDEB

Well-Known Member
Am just testing the timer code

the sound code etc is not included as of yet.
the Boolean thing I am just trying different things??
maybe a code where in a WHILE TRUE loop it keeps adding to a variable until the variable equals a predetermined value that after so many times through the loop the elapsed time is say 20 minutes.
X=1
WHILE TRUE
IF X>=200 then FALSE

DELAYMS(200)
X=X+1
WEND
something similar??
this should cycle 199 times until X = 200 I think
 

MrDEB

Well-Known Member
not sure of syntax??

this is a non-working example of what I have been trying
tried X as BYTE, LONGWORD, WORD
not sure of what they mean??
just trying something, maybe hit the right combo??
I just might get a book on C then maybe, just maybe??
Code:
Device = 18f1320
Clock = 8
Config OSC = INTIO2, WDT = OFF, LVP = OFF
OSCCON = $62
TRISA=%00000000         //A0 & 6 output
dim (x) as boolean
end
PORTB.0=1
PORTB.1=0
x=(1) 
 While (true)
 Toggle(PORTB.0)
 DelayMS(20)


IF (X>=200) then FALSE

   DELAYMS(20)
   X=X+1

endif
WEND
    Toggle(PORTB.0)
    DelayMS(10)
    Toggle (PORTB.1)
    DelayMS(30)
    Toggle(PORTB.0)
    DelayMS(10)
   
    Toggle(PORTB.0)
    DelayMS(10)
end
 

be80be

Well-Known Member
MrDeb take a look at this code it gives a 10 sec delay you can make it longer
Code:
Device = 18F1320
Clock = 8
Config OSC = INTIO2
Config MCLRE = Off
Include "INTOSC8.bas"           // set OSO
dim delaycounter as byte
Sub Longdelay()
        delaycounter = 0
        repeat                        // 10 sec delay 
            delayms(1000)
            inc (delaycounter)
        until delaycounter = 10
End Sub
 
 output (portb.0)
 while true
    high (portb.0)
    Longdelay          //10 sec on 
    low (portb.0)
    Longdelay         // 10 sec off 
 wend
 

be80be

Well-Known Member
This is on the junebug with a 60sec delay
Code:
Device = 18F1320
Clock = 8
Config OSC = INTIO2
Config MCLRE = Off
Include "INTOSC8.bas"           // set OSO
include "Utils.bas"

dim delaycounter as byte

Sub Longdelay()
        delaycounter = 0
        repeat                        // 60 sec delay 
            delayms(1000)
            inc (delaycounter)
        until delaycounter = 60
End Sub
 SetAllDigital
 trisa =%00000000
 porta =%00000000
 output (portA.0)
 while true
    high (portA.0)
    Longdelay          //60 sec on 
    low (portA.0)
    Longdelay         // 60 sec off 
 wend
Save this file here to your user library name it INTOSC8.bas
Code:
Module IntOSC8

OSCCON = $72
It set your osc up from the getgo. Start LOL
 

be80be

Well-Known Member
Here the code with 3min on and 1 min off
Code:
Device = 18F1320
Clock = 8
Config OSC = INTIO2
Config MCLRE = Off
Include "INTOSC8.bas"           // set OSO
Include "Utils.bas"
Include "bigdelay.bas"


SetAllDigital
 TRISA =%00000000
 PORTA =%00000000
 Output (PORTA.0)
 While true
    High (PORTA.0)
    longmindelay          //3minute on 
    Low (PORTA.0)
    Longdelay         // 60 sec off 
 Wend

Save this to your user module library as bigdelay.bas
Code:
Module bigdelay

Dim delaycounter As Byte
Public Sub Longdelay()
        delaycounter = 0
        Repeat                        // 1 minute.delay 
            DelayMS(1000)
            Inc (delaycounter)
        Until delaycounter = 60
End Sub

Dim mindelaycounter As Byte
Public Sub longmindelay()
        mindelaycounter = 0
        Repeat                        // 3 minute.delay 
            Longdelay
            Inc (mindelaycounter)
        Until mindelaycounter = 2 //change this to make it longer
End Sub
 
Last edited:

MrDEB

Well-Known Member
I am playing with all that code

learning alot
BUT curious WHY this code for the orginal timer dosn't work??
It worked before.
I added the INTOS8.bas
I wonder if I dumped this code ontop of another code =it worked as desired.
Code:
// 18F1320@ 8MHz - they are just used here for clarity...
Device = 18F1320
Clock = 8

Include "ISRTimer.bas"
include "INTOSC8.bas"          

// constant ID to 4 * 16 bit timers...
Const
   Timer1 = 0,
   Timer4 = 2
// OnTimer1 event...
Event OnTimer1()
   Toggle(PORTB.0)//pin 8
   DelayMS(10)
   
End Event

// OnTimer2 event...
Event OnTimer2()
   Toggle(PORTB.1)//pin9
    DelayMS(10)
   
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 = 10        // 50ms
Timer.Items(Timer1).OnTimer = OnTimer1   // timer event handler
 //
 // timer event handler
Timer.Items(Timer4).Interval = 40      // 2000ms, no event handler

// enable the timers...
Timer.Items(Timer1).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
       DelayMS(30)
      Toggle(PORTB.3)
      Timer.Items(Timer4).Enabled = true
   EndIf
      
   // background flash LED...
   High(PORTB.2)//pin 13
   DelayMS(50)
   Low(PORTB.2)//pin 13
   DelayMS(50)
Wend
 

be80be

Well-Known Member
Should be like this. You do have leds and resistors on portb 0 to 3 don't you.
If so it works.
And you have the osc module named INTOSC8.bas in your Swordfish user library.
Code:
// 18F1320@ 8MHz - they are just used here for clarity...
Device = 18F1320
Clock = 8
include "INTOSC8.bas"
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)
End Event

// OnTimer2 event...
Event OnTimer2()
   Toggle(PORTB.1)
End Event

// OnTimer3 event...
Event OnTimer3()
   Toggle(PORTB.2)
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)
   //delayms(500)
   //low(PORTB.7)
   //delayms(500)
Wend
 
Last edited:

MrDEB

Well-Known Member
yes everything is connected

LEDs on correct ports etc.
I even ran an LED test code to make sure all the connected ports etc are working.
Code:
Device = 18f1320
Clock = 8
Config OSC = INTIO2, WDT = OFF, LVP = OFF

OSCCON = $72
TRISA=%00000000         //A0 & 6 output

 

PORTB.0=1
PORTB.1=1

PORTB.2=1
PORTB.3=1

While (true)
    Toggle(PORTB.0)
    DelayMS(20)
    Toggle (PORTB.3)
    DelayMS (50)
     Toggle(PORTB.2)
    DelayMS(20)
    Toggle (PORTB.1)
    DelayMS (50)
Wend

all the LEDs flash.
I erase PIC before hitting F10
possible the ports are LOW instead of HIGH??
I don't see it but then I is blind in one eye and can't see outta the other when PIC programming is concerned.
Have to abmit I am learning
like yesterday I unpluged the USB/ JUNEBUG
came back to it reconnected and the Junebug/pik2 never communicated.
I thought I poped something??
don'tknow what I did but got the two to communicate again.
 

be80be

Well-Known Member
I tried the code you posted It works fine only thing I did was move the osc setting because
it was slow starting. That's the timer code. It don't flash a led for about 1 minute the it blinks in turn b0 b1 and b2
I thought I poped something??
don'tknow what I did but got the two to communicate again.
you popping a lot. I'm sure you can hurt a pic but it's harder then you think. And if you use the junebug like the pickit2 you can power the target board and if you hook it up wrong
it will not power up
 
Last edited:

MrDEB

Well-Known Member
Little Juney is working BUT code no

something is not right??
I inserted several test clips, took out timer 2 & 3
the test is on port B1
Code:
// 18F1320@ 8MHz - they are just used here for clarity...
Device = 18F1320
Clock = 8
include "IntOSC8.bas"   // you need this to set the osc.
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)
End Event


 portB.1=1// TEST of progression
 delayms(50)
 portb.1=0
// OnTimer2 event...
//Event OnTimer2()
  // Toggle(PORTB.1)
//End Event

// OnTimer3 event...
//Event OnTimer3()
  // Toggle(PORTB.2)
//End Event

// activate the timer module...
Timer.Initialize

// initialise the timers - refresh every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 200        // 50ms
Timer.Items(Timer1).OnTimer = OnTimer1   // timer event handler
//Timer.Items(Timer2).Interval = 50       // 250ms
//Timer.Items(Timer2).OnTimer = OnTimer2   // timer event handler
//Timer.Items(Timer3).Interval = 50       // 500ms
//Timer.Items(Timer3).OnTimer = OnTimer3   // timer event handler
Timer.Items(Timer4).Interval = 200      // 2000ms, no event handler


portB.1=1// TEST of progression
 delayms(50)
 portb.1=0


// 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
portB.1=1// TEST of progression
 delayms(50)
 portb.1=0
// 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.2)
   delayms(500)
   low(PORTB.2)
   delayms(500)
Wend
B1 never comes on??
I have the background flash LED working
maybe try a different chip?? but it appears to work
 

be80be

Well-Known Member
How many leds do have on portb just 1 or what. If you don't have leds on b0 b1 b2 your not going to see any thing happen.
 

MrDEB

Well-Known Member
1 LED and one resistor

per port.
the code I posted for testing the LEDs works.
I thought about trying a new PIC but can just some code not wrk on it but most other codes will.
I coded the PIC, un hooked from Junebug then connected a battery and worked on some othe timer codes you posted.
never saw any LEDs come on.
You say it works ??
maybe I have a jinks in my PIC??
will try with a new PIC
 

MrDEB

Well-Known Member
put in new PIC

and it still dosn't work??
I had that code working before??
I checked all my connections etc?
going onward. Inserting the code snippet be80be posted
3min on 1 minute off
just changed the minute module to 10 instead of 1000
changed the high low in the while true loop
Code:
Module delaytimer
Dim delaycounter As Byte
Public Sub Longdelay()
        delaycounter = 0
        Repeat                        // 1 minute.delay 
            DelayMS(10)   // 1000 = 1 minute
            Inc (delaycounter)
        Until delaycounter = 60
End Sub

Dim mindelaycounter As Byte
Public Sub longmindelay()
        mindelaycounter = 0
        Repeat                        // 3 minute.delay 
            Longdelay
            Inc (mindelaycounter)
        Until mindelaycounter = 12000 //change this to make it longer
End Sub
Code:
Dim delaycounter As Byte
Public Sub Longdelay()
        delaycounter = 0
        Repeat                        // 1 minute.delay 
            DelayMS(1000)
            Inc (delaycounter)
        Until delaycounter = 60   //set for desired seconds
End Sub

Dim mindelaycounter As Byte
Public Sub longmindelay()
        mindelaycounter = 0
        Repeat                        // 3 minute.delay 
            Longdelay
            Inc (mindelaycounter)
        Until mindelaycounter = 20 //change this to make it longer
End Sub
am testing as I type
geez 20 minutes is long!!
 

MrDEB

Well-Known Member
may have found problem w/ timer

did a communciation check using pk2
good
did a blank check = error =memory not starting at 0x000000
need to do some investigation.
 
Status
Not open for further replies.
Top