1. 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.
    Dismiss Notice

Memory Restricted In Watch Window

Discussion in 'Microcontrollers' started by Inquisitive, Mar 4, 2018.

  1. Inquisitive

    Inquisitive Super Moderator

    Joined:
    Aug 31, 2011
    Messages:
    1,096
    Likes:
    100
    Location:
    Georgia, USA
    I need some assistance getting this solved.

    I'm still learning to crawl in PIC microcontrollers. Working with a PIC 16F628A

    Code (Asm):

    ;=============================================================================
    ;    Bin4B.asm                    3-4-18
    ;=============================================================================
    ;    Slow output binary count is stopped, started
    ;    and reset with push buttons. This version uses a
    ;    subroutine for the delay...
    ;    Processor:    PIC 16F628A
    ;    Hardware:    BIN Demo System
    ;    Clock:      
    ;    Inputs:        Push Buttons RA0, RA1 (active low)
    ;    Outputs:    RB0 - RB7 LEDs (active high)
    ;
    ;    WDTimer:    Disabled
    ;    PUTimer:    Enabled
    ;    Interrupts:    Disabled
    ;    Code Protect:    Disabled      
    ;=============================================================================
    ;              16F628A
    ;         ____ ____
    ;    RA2-| 1 U 18 |-RA1
    ;    RA3-| 2   17 |-RA0
    ;    RA4-| 3   16 |-OSC1/RA7
    ;    MCLR-| 4   15 |-OSC2/RA6
    ;    VSS-| 5   14 |-VDD
    ;    RB0-| 6   13 |-RB7
    ;    RB1-| 7   12 |-RB6
    ;    RB2-| 8   11 |-RB5
    ;    RB3-| 9   10 |-RB4
    ;         ----------
    ;  
        list    p=16f628a
        include    <p16f628A.inc>
        radix    hex
        __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _XT_OSC
    ;
    ;...... Register Label Equates ...............................................
    ;
    porta    EQU    05        ; Port A Data Register
    portb    EQU    06        ; Port B Data Register
    timer    EQU    0C        ; Spare register for delay
    ; Input Bit Label Equates ....................................................
    ;inres    EQU    0        ; 'Reset' input button = RA0
    ;inrun    Equ    1        ; 'Run' input button = RA1
    ;
        cblock    0x20      
        inres            ; 'Reset' input button = RA0
        inrun            ; 'Run' input button = RA1
        endc
        movlw    .0
        movwf    inres
        movlw    .1
        movwf    inrun
    ;
    ;*****************************************************************************
    ; Initialise Port B (Port A defaults to inputs) ..............................
    ;
        MOVLW    b'00000000'    ; Port B Data Direction Code
        TRIS    portb        ; Load the DDR code into F86
        GOTO    reset
    ;
    ; 'delay' subroutine .........................................................
    ;
    delay    MOVWF    timer        ; Copy W to timer register
    down    DECFSZ    timer        ; Decrement timer register
        GOTO    down        ; and repeat until zero
        RETURN            ; Jump back to main program
    ;
    ; Start main loop ............................................................
    ;
    reset    CLRF    portb        ; Clear Port B Data
    ;
    start    BTFSS    porta,inres    ; Test RA0 input button
        GOTO    reset        ; and reset Port B if pressed
        BTFSC    porta,inrun    ; Test RA1 input button
        GOTO    start        ; and run count if pressed
    ;
        INCF    portb        ; Increment count at Port B
        MOVLW    0FF        ; Delay count literal
        CALL    delay        ; Jump to subroutine 'delay'
    ;
        GOTO    start        ; Repeat main loop always
        END            ; Terminate source code
     
    The issue is these restricted memory errors in the watch windows. How do I solve this?

    RestrictedMemeoryError.PNG


    Using MPLAB IDE 8.92 with MPLAB SIM

    Why can I not watch RA0 and RB0 ? Suggestions anyone.
     
  2. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,802
    Likes:
    958
    Location:
    Rochdale UK
    The watch window is for registers The three symbols you have used have no address signed to them
    All you have is PORTA = address 5 and the binary view.. You can't put bit values in...

    RB2 = 0x0C ... Obviously wrong.. never use the watch... I just use the SFR viewer..
     
  3. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,710
    Likes:
    421
    Location:
    Brisbane Australia
    RA0 is bit zero of port A, so you are looking at address zero which is INDF which is a restricted area.

    Mike.
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  5. Inquisitive

    Inquisitive Super Moderator

    Joined:
    Aug 31, 2011
    Messages:
    1,096
    Likes:
    100
    Location:
    Georgia, USA
    I just cannot get this program to work. It produces no error messages on compile. But logically it does not produce the correct result.

    Bin4Schematic.PNG
     
  6. Beau Schwabe

    Beau Schwabe Member

    Joined:
    Jun 4, 2017
    Messages:
    107
    Likes:
    9
    You need to watch out for things like .... "INCF portb" .... without specifying the file register it defaults to the W register ...

    INCF portb, F ... is probably what you want, but again there still could be an issue. Sometimes you can't write directly to a port like that.

    instead try something like...

    INCF tempVariable,F
    MOVF tempVaraible,W
    MOVWF portb
     
    • Thanks Thanks x 1
  7. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,802
    Likes:
    958
    Location:
    Rochdale UK
    Oh.... You have forgotten to turn of the comparator...
    C:
    CMCON = 0x7;

    ASM:
    banksel CMCON
    movlw 0x7
    movfw CMCON
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  9. Inquisitive

    Inquisitive Super Moderator

    Joined:
    Aug 31, 2011
    Messages:
    1,096
    Likes:
    100
    Location:
    Georgia, USA
    No, not forgotten. That is a sample straight out of a textbook. Hence I do not have enough background information yet to solve the issue and the plea for mentoring. I searched for errata on the publishers website and came up empty.

    CMCON has not even been mentioned in the textbook as of yet.
     
  10. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,802
    Likes:
    958
    Location:
    Rochdale UK
    Well.. If you want to use RA0 and RA1 as digital inputs you'll have to turn it off..
     
    • Thanks Thanks x 1
  11. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,619
    Likes:
    697
    Location:
    Derbyshire, UK
    ONLINE
    Is your book specific to the 16F628? (highly unlikely), CMCON is pretty well specific to that device and MUST be turned OFF to use the port as normal.

    If you check my tutorials (which use the 628) you'll see all programmes do exactly that - http://winpicprog.co.uk/pic_tutorial1.htm
     
  12. Inquisitive

    Inquisitive Super Moderator

    Joined:
    Aug 31, 2011
    Messages:
    1,096
    Likes:
    100
    Location:
    Georgia, USA
    Heard the 16F628A was identical to the 16F84A. The tutorial is based on a 16F84A and I was converting it to 628A. I have stacks of books based on the 16F84A and never had the time to get to them. Shame to throw them out.

    Thanks for your insight.
     
  13. Inquisitive

    Inquisitive Super Moderator

    Joined:
    Aug 31, 2011
    Messages:
    1,096
    Likes:
    100
    Location:
    Georgia, USA
    I see now I should have offered more information
     
  14. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,619
    Likes:
    697
    Location:
    Derbyshire, UK
    ONLINE
    That's why my tutorials say:

    Code (text):

    org    0x0000            ;org sets the origin, 0x0000 for the 16F628,
                       ;this is where the program starts running  
       movlw    0x07
       movwf    CMCON            ;turn comparators off (make it like a 16F84)
     
    Notice it's the VERY first thing the program does.
     
    • Thanks Thanks x 1

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice