How to find the Breakpoints in Mplab?

Thread Starter

morgan

Joined Jul 10, 2010
9
I have to set breakpoints to examine memory and register for the following code. Could anyone teach me how to find the breakpoints and what should be set as "add SFR" and "add Symbol"? Thank you.


Code:
; File CHASER.ASM
; Blinks LEDs on outputs (Port B) in a rotating pattern.
; Reverses direction if port A, Bit 0, is high.
processor 16f84
include <p16f84.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
; Give names to 2 memory locations (registers)
J equ H'1F' ; J = address hex 1F
K equ H'1E' ; K = address hex 1E
; Program
org 0 ; start at address 0
; Set Port B to output and initialize it.
movlw B'00000000' ; w := binary 00000000
tris PORTB ; copy w to port B control reg
movlw B'00000001' ; w := binary 00000001
movwf PORTB ; copy w to port B itself
bcf STATUS,C ; clear the carry bit
; Main loop. Check Port A, Bit 0, and rotate either left
; or right through the carry register.
mloop:
btfss PORTA,0 ; skip next instruction if bit=1
goto m1
rlf PORTB,f ; rotate port B bits to left
goto m2
m1:
rrf PORTB,f ; rotate port B bits to right
m2:
; Waste some time by executing nested loops
movlw D'50' ; w := 50 decimal
movwf J ; J := w
jloop: movwf K ; K := w
kloop: decfsz K,f ; K := K-1, skip next if zero
goto kloop
decfsz J,f ; J := J-1, skip next if zero
goto jloop
goto mloop ; do it all again
end ; program ends here
 

Markd77

Joined Sep 7, 2009
2,806
To set or clear a breakpoint, doubleclick in the gray bit to the left of the code (has to be an instruction).
SFRs are things like PORTB, etc.
Symbols are individual bits of the SFRs or your own variables.
I tend to hover the mouse over the variable name in the code to get the value and also use the file registers view.
 

Thread Starter

morgan

Joined Jul 10, 2010
9
I set PORTB as SFR and F as Symbol, and set the breakpoints after"
movwf PORTB ;" But it still does not work, it keeps running without halting unless i click the "halt". What is the problem? Thank you.
 

BMorse

Joined Sep 26, 2009
2,675
your code is probably not getting to that point when running it that is why it is not stopping at the breakpoint.

Have you tried stepping through the code from beginning to see if it is getting there?
Rich (BB code):
; File CHASER.ASM 
; Blinks LEDs on outputs (Port B) in a rotating pattern. 
; Reverses direction if port A, Bit 0, is high. 
processor 16f84 
include <p16f84.inc> 
__config _RC_OSC & _WDT_OFF & _PWRTE_ON 
; Give names to 2 memory locations (registers) 
J equ H'1F' ; J = address hex 1F 
K equ H'1E' ; K = address hex 1E 
; Program 
org 0 ; start at address 0 
; Set Port B to output and initialize it. 
movlw B'00000000' ; w := binary 00000000 
tris PORTB ; copy w to port B control reg 
movlw B'00000001' ; w := binary 00000001 
movwf PORTB ; copy w to port B itself 
bcf STATUS,C ; clear the carry bit 
; Main loop. Check Port A, Bit 0, and rotate either left 
; or right through the carry register. 
mloop: 
btfss PORTA,0 ; skip next instruction if bit=1 
goto m1 
rlf PORTB,f ; rotate port B bits to left 
goto m2 
m1: 
rrf PORTB,f ; rotate port B bits to right 
m2: 
; Waste some time by executing nested loops 
movlw D'50' ; w := 50 decimal 
movwf J ; J := w 
jloop: movwf K ; K := w 
kloop: decfsz K,f ; K := K-1, skip next if zero 
goto kloop 
decfsz J,f ; J := J-1, skip next if zero 
goto jloop 
goto mloop ; do it all again 
end ; program ends here
and use the code tags in the advanced editor....
B. Morse
 

Thread Starter

morgan

Joined Jul 10, 2010
9
Oh, yes. It circulates between "go to kloop" and "kloop: decfsz K,f ". I have another question: Where does the main program begin? Does it begin from “ movlw B'00000000' ”? Thx.
 

Markd77

Joined Sep 7, 2009
2,806
Main code starts at mloop. If you put breakpoints on rrf and rlf and watch portb you should see the main point of the program.
 

Thread Starter

morgan

Joined Jul 10, 2010
9
I have another code, mostly the same as the last one. However, it continued running and never stopped untill i clicked "halt". After i did that, the arrow pointed at “nop" each time. Am i doing anything incorrectly? I already tried the breakpoints at different places. Thx.



processor 16f84A
include <p16F84A.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON

reset: org 0x00 ; reset at address 0
goto start

inter: org 0x04 ; interrupt vector (automatically clears GIE)
; no need to save W or STATUS

; first, read and set the pre-scale factor from RA0-2
movf PORTA,W ; w = PORTA
andlw 0x07 ; zero all bits except PS0-2
iorlw 0x80 ; set bit 7 to disable PORTB pull-ups
bsf STATUS,RP0 ; switch to bank 0 memory
movwf OPTION_REG ; load the option register
bcf STATUS,RP0 ; return to bank 1 memory

; now, test RA3 and rotate PORTA bits
btfss PORTA,3 ; skip next instruction if RA3=1
goto i1
rlf PORTB,F ; rotate port B bits to the left for RA3=1
goto i2
i1:
rrf PORTB,F ; rotate port B bits to the right for RA3=0
i2:
bcf INTCON,T0IF ; clear the timer interrupt flag
RETFIE ; return from interrupt (automatically sets GIE)

start:
; On reset, all ports are inputs and timer is disabled
; This code sets PORTB to output, and sets the carry bit
; Also, the timer is setup and enabled

bsf STATUS,RP0 ; switch to bank 1 memory
clrf TRISB ; set PORTB to all outputs
movlw B'10000000' ; T0CS=PSA=0, PS=000
movwf OPTION_REG ; enable timer with 1:2 pre-scaler
bcf STATUS,RP0 ; return to bank 0 memory

clrf PORTB ; initialize all PORTB outputs to 0
bsf STATUS,C ; set the carry flag

clrf TMR0 ; clear the timer register
bsf INTCON,T0IE ; set the timer interrupt mask
bsf INTCON,GIE ; enable interrups

mloop:
sleep
nop
goto mloop ; wait in endless loop for interrupts

end
 
Top