Reset on Halt or on Breakpoints

Started by scottmack1 June 10, 2008
Guys, I am using a 16F887 with MPLAB 7.60 and a ICD 2.
I need to continue coding on a project I worked on a while back.
Jumping in and fixing stuff I have managed to get into some kind of
mess. The cpu seems to always reset to the beginning of the program
when I halt it. I kind of figured this may be do to using the WDT &
SLEEP combination, not sure, and that I have something wrong there,
but that is only the start of the problem. When ever I add a
breakpoint, the program resets to the start. THIS, makes debug of
the program impossible of course. So after much hacking, I tried to
back way up to the basic LED blink approach. Using a 'movwf TRISC'
to set the port and a toggle of the port bit, LED works OK and
functions with breakpoints. Next I try to add my 'call Init_Ports'
routine back in and with F9 the program runs one time and resets to
the start. If I put in a breakpoint before the 'call', it stops OK
on the bkpt. If I put in a bkpt after the 'call', it runs ignoring
the bkpt and resets to the start(LED blinks once - code is below).
If I single step, every time I get it to the 'movwf TRISA' statement
with a green arrow, the arrow changes to a flat blue pointer on the
next F7 step, and then resets the green arrow back to the beginning
of the program on the next F7 step. What is going on with this?
What is the blue pointer on the statement line suppose to tell me?

I have looked at the Disassembly Code and the statements and hex seem
OK. Why would it always reset on this 'TRISA' statement? I have
moved it around with some 'nop' lines and it waits till this line and
sends the program counter back to the beginning when I am single
stepping. It will pass through a 'TRISC' statement OK, just not
a 'A' statement.

The code -
goto Start
call Init_Timer1 ; Does this call OK
nop ; Bkpt here works OK
call Init_Ports
nop ; Bkpt here is ignored - program continues - LED
blinks - program resets to Start
banksel TRISC
movlw B'10000000'
movwf TRISC
banksel PORTC
bcf PORTC, 2 ; LED ON (sinks)
call delay_50ms
bsf PORTC, 2 ; LED OFF
call delay_50ms
goto Start
; Skipping the lines where I 'clrf' on all ports
movlw B'10000000'
movwf TRISC ; Will execute OK
movlw B'11001011'
movwf TRISA ; Line that green arrow changes to blue ptr

I don't know if this is causing my full program to reset each time I
try to halt it or put a bkpt in it, but something is wrong here.
Would anyone guess that they are related or do I have another problem

Thanks for the help, I don't know what to do to get past this,