Memory Restricted In Watch Window

Status
Not open for further replies.

Inquisitive

Super Moderator
I need some assistance getting this solved.

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

Code:
;=============================================================================
;    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?




Using MPLAB IDE 8.92 with MPLAB SIM

Why can I not watch RA0 and RB0 ? Suggestions anyone.
 
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..
 
RA0 is bit zero of port A, so you are looking at address zero which is INDF which is a restricted area.

Mike.
 
I just cannot get this program to work. It produces no error messages on compile. But logically it does not produce the correct result.

 
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
 
Oh.... You have forgotten to turn of the comparator...
C:
CMCON = 0x7;

ASM:
banksel CMCON
movlw 0x7
movfw CMCON
 
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.
 
Well.. If you want to use RA0 and RA1 as digital inputs you'll have to turn it off..
 

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 -
 
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.
 
Heard the 16F628A was identical to the 16F84A.

That's why my tutorials say:

Code:
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…