How to find the Breakpoints in Mplab?

Discussion in 'Embedded Systems and Microcontrollers' started by morgan, Jul 17, 2010.

  1. morgan

    Thread Starter New Member

    Jul 10, 2010
    9
    0
    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
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  3. morgan

    Thread Starter New Member

    Jul 10, 2010
    9
    0
    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.
     
  4. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    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?
    Code ( (Unknown Language)):
    1. ; File CHASER.ASM
    2. ; Blinks LEDs on outputs (Port B) in a rotating pattern.
    3. ; Reverses direction if port A, Bit 0, is high.
    4. processor 16f84
    5. include <p16f84.inc>
    6. __config _RC_OSC & _WDT_OFF & _PWRTE_ON
    7. ; Give names to 2 memory locations (registers)
    8. J equ H'1F' ; J = address hex 1F
    9. K equ H'1E' ; K = address hex 1E
    10. ; Program
    11. org 0 ; start at address 0
    12. ; Set Port B to output and initialize it.
    13. movlw B'00000000' ; w := binary 00000000
    14. tris PORTB ; copy w to port B control reg
    15. movlw B'00000001' ; w := binary 00000001
    16. movwf PORTB ; copy w to port B itself
    17. bcf STATUS,C ; clear the carry bit
    18. ; Main loop. Check Port A, Bit 0, and rotate either left
    19. ; or right through the carry register.
    20. mloop:
    21. btfss PORTA,0 ; skip next instruction if bit=1
    22. goto m1
    23. rlf PORTB,f ; rotate port B bits to left
    24. goto m2
    25. m1:
    26. rrf PORTB,f ; rotate port B bits to right
    27. m2:
    28. ; Waste some time by executing nested loops
    29. movlw D'50' ; w := 50 decimal
    30. movwf J ; J := w
    31. jloop: movwf K ; K := w
    32. kloop: decfsz K,f ; K := K-1, skip next if zero
    33. goto kloop
    34. decfsz J,f ; J := J-1, skip next if zero
    35. goto jloop
    36. goto mloop ; do it all again
    37. end ; program ends here        
    and use the code tags in the advanced editor....
    B. Morse
     
  5. morgan

    Thread Starter New Member

    Jul 10, 2010
    9
    0
    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.
     
  6. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    If you stepped through the code, you would have seen where it starts ;)...
     
  7. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  8. morgan

    Thread Starter New Member

    Jul 10, 2010
    9
    0
    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
     
  9. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Try putting an interrupt at the instruction after inter:
    If the code is right it should get there periodically.
     
Loading...