I won't comment of fixing your problem cos im too dumb, but you might want to turn off your code protect while playing with the code, or you are going to go through several pics rather quickly.
I won't comment of fixing your problem cos im too dumb, but you might want to turn off your code protect while playing with the code, or you are going to go through several pics rather quickly.
Even if you have enabled the CodeProtect... it just prevent to read it, you can Still program your PIC.but you might want to turn off your code protect while playing with the code,
peterdeco1, what else your PIC will do, here i don't see any part of your code that seems to do some delay job. Did you read TIMER0, TIMER1 section of your datasheet? what sbout the Elapsed timer of darrel?
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Thanks for the code protect advice but I'm using a flash PIC. I'm going to look for the Elapsed Timer now.
Here is some code I use in an 18F8720 using a 20Mhz Xtal, You can modify the technique to run on nearly any other part. It works best when you you need accuracy over a long period, but don't need to time over very small intervals.
'---------------------------------------------------------------------
T0CON =$87 ' Set up TMR0 prescaler with 256 divisor
LOOP:
IF INTCON.2 = 1 THEN
INTCON.2 = 0
TMR0H = $69
TMR0L = $7A
GOSUB CountTime
EndIF
'Your code goes here'
GOTO LOOP
CountTime:
Seconds = Seconds + 2
IF Seconds = 60 THEN
Seconds = 0
Minutes = Minutes + 1
.
.
.
RETURN
'-------------------------------------------------------------------------
Explanation of what is going on above:
Hardware Timer0 is set up with a 256 (/8) divisor
INTCON.2 gets set whenever the timer rolls over.
When the timer rolls over, the timer gets loaded with a value
that insures it will time out again in 2 seconds.
Your program executes normally, but exactly every two seconds
the CountTime sub is executed.
The only caveat: Your program MUST complete at least one loop every
2 seconds!
I have used a similar technique with the 16F series, but since the timers are "shorter", sometimes the maximum timeout is only 65 ms. Still, the procedure can be very useful.
Bookmarks