Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC SFR not changing initial values

Status
Not open for further replies.

mrinalmani

Advanced Member level 1
Advanced Member level 1
Joined
Oct 7, 2011
Messages
467
Helped
60
Reputation
121
Reaction score
59
Trophy points
1,318
Location
Delhi, India
Visit site
Activity points
5,348
I am using MPLAB X
The SFRs do not seem to be changing their initial values. After the following code, TRISB should = 0, and PORTB 7
but they do not change. (I am using the simulator)
Please help

Code:
start

    MOVLW   0H
    MOVWF   TRISB
    MOVLW   7H
    MOVWF   PORTB
    GOTO start
    END
 
Last edited by a moderator:

Both TRISB and PORTB registers are located into different banks.
I presume you should insert these macros, as highlighted bellow:

Code:
start

MOVLW 0H
[B]bank1 [/B]
MOVWF TRISB
MOVLW 7H
[B]bank0[/B]
MOVWF PORTB
GOTO start
END
 
Hi,

As shown in the code example in the previous reply you need to use the Banksel Directive to tell the compiler which Memory bank the system and user registers are in.
It cannot decide for itself which memory bank the registers are in so its down to you to tell it from your code instructions, its painful and a bit of a chip design problem, but thats one of the drawbacks of using Assembler; C code deals with it for you.

You can also use Macros, as Andre shows, to make bank changing even simpler.

It would be helpful if you say what chip you are using/ simulating , but look at its Datasheet section /figure Memory 'Data Memory Map' which shows how the registers are organised.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top