Searching \ for '[PIC]: PCLATH Bug in MPLAB-SIM ?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=mplab
Search entire site for: 'PCLATH Bug in MPLAB-SIM ?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: PCLATH Bug in MPLAB-SIM ?'
2001\06\24@193127 by Christian Dorner

flavicon
face
Hi everyone!

Currently i try to write a little training program to learn more about
jumping between page boundaries. (inspirated by a Msg from Olin who do this
with linker sections ...)

But when i try my code in MPLAB-SIM the jumps/calls between the pages work
fine just the return dosn't work like documented in the PIC-Datasheets. The
problem seems to be that MPLAB-SIM dosn't restore the PCLATH (from the
stack).

Is this a known Bug in MPLAB-SIM or do i something wrong?

TIA

Christian

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\24@195812 by Eric Smith

flavicon
face
Christian Dorner <.....docKILLspamspam@spam@AUSTROSOL.COM> writes:
> But when i try my code in MPLAB-SIM the jumps/calls between the pages work
> fine just the return dosn't work like documented in the PIC-Datasheets. The
> problem seems to be that MPLAB-SIM dosn't restore the PCLATH (from the
> stack).
>
> Is this a known Bug in MPLAB-SIM or do i something wrong?

Where in the data sheet do you find any claim that doing a return modifies
PCLATH?

On the parts that I've worked with, return has no effect on PCLATH.
I usually wind up with something like:

; in first 2KW region:
       ...
       movlw   r2sub>>8
       movwf   pclath
       call    r2sub
       clrf    pclath          ; restore PCLATH to point to page 0
       ...
       call    r0sub
       ...

r0sub:  ...
       return
       ...

; in second 2KW region:

       org     0800h
       ...
r2sub:  ...
       return

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\24@201101 by Christian Dorner

flavicon
face
> Where in the data sheet do you find any claim that doing a return modifies
> PCLATH?
>
> On the parts that I've worked with, return has no effect on PCLATH.
> I usually wind up with something like:

Thanks for the fast answer but i've found the problem. (You also descriped
above).
I don't read the datasheet careful enought. (might be a problem of my bad
english, too)

I've fixed it with a small macro which checks the program location (page)
where it inserted and "restores" (set it with the right values) the PCLATH.

If anyone cares about, there it is:

---- snip -----------------------------------------------
poppclath macro

if $ >= 0x0000 & $ <= 0x07ff
  bcf PCLATH,3  ; Set PCLATH to Page 0
  bcf PCLATH,4
endif

if $ >=0x0800 & $ <= 0x0fff
  bsf PCLATH,3  ; Set PCLATH to Page 1
  bcf PCLATH,4
endif

if $ >=0x1000 & $ <= 0x17ff
  bcf PCLATH,3  ; Set PCLATH to Page 2
  bsf PCLATH,4
endif

if $ >=0x1800 & $ <= 0x1fff
  bsf PCLATH,3  ; Set PCLATH to Page 3
  bsf PCLATH,4
endif

endm
---- snip -----------------------------------------------

After a CALL i insert this "POPPCLATH" to fix the PCLATH.

cu, Christian

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2001\06\24@201725 by Tony Nixon

flavicon
picon face
Christian Dorner wrote:
{Quote hidden}

MPLAB or the processor does not restore the PCLATH after a CALL or GOTO
instruction.

Here is a little snippet I use to demonstrate ROM addressing. This one
will not work because the PCLATH register is not set for the call...


       Title  "mICros PCLATH Program 2"

            list p=16f873        ; processor type
;
; The purpose of this program is to demonstrate the PCLATH register
; jumping over a page boundary
;
PCLATH        equ 0x0A           ; define PCLATH register
;
; -------------
; PROGRAM START
; -------------
;
       org 0000h               ; code starts at address 0

Loop    call Delay      ; execute Delay subroutine
       goto Loop               ; repeat forever
       nop
       nop
Error1  goto Error1
;
; Delay subroutine starts at 0800h
;
       org 0800h

Error2  goto Error2
       nop
       nop
       nop
Delay   nop             ; very small delay subroutine
       nop
       return


       end

This one will not work either because the PCLATH is not restored after
the call...

       Title  "mICros PCLATH Program 3"

            list p=16f873        ; processor type
;
; The purpose of this program is to demonstrate the PCLATH register
; jumping over a page boundary
;
PCLATH        equ 0x0A           ; define PCLATH register
;
; -------------
; PROGRAM START
; -------------
;
       org 0000h               ; code starts at address 0

Loop    movlw High(Delay)
       movwf PCLATH
       call Delay      ; execute Delay subroutine
       goto Loop               ; repeat forever
       nop
       nop
Error1  goto Error1
;
; Delay subroutine starts at 0800h
;
       org 0800h

Error2  goto Error2
       nop
       nop
       nop
Delay   nop             ; very small delay subroutine
       nop
       return


       end

This one will work because PCLATH was set before the call and restored
after the call...

       Title  "mICros PCLATH Program 4"

            list p=16f873        ; processor type
;
; The purpose of this program is to demonstrate the PCLATH register
; jumping over a page boundary
;
PCLATH        equ 0x0A           ; define PCLATH register
;
; -------------
; PROGRAM START
; -------------
;
       org 0000h               ; code starts at address 0

Loop    movlw High(Delay)
       movwf PCLATH
       call Delay      ; execute Delay subroutine
       clrf PCLATH
       goto Loop               ; repeat forever
       nop
       nop
Error1  goto Error1
;
; Delay subroutine starts at 0800h
;
       org 0800h

Error2  goto Error2
       nop
       nop
       nop
Delay   nop             ; very small delay subroutine
       nop
       return


       end


There is a more detailed explanation in the project file at...

http://www.bubblesoftonline.com/projects.zip



--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
salesspamspam_OUTbubblesoftonline.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\25@120804 by Olin Lathrop

face picon face
> Currently i try to write a little training program to learn more about
> jumping between page boundaries. (inspirated by a Msg from Olin who do
this
> with linker sections ...)
>
> But when i try my code in MPLAB-SIM the jumps/calls between the pages work
> fine just the return dosn't work like documented in the PIC-Datasheets.
The
> problem seems to be that MPLAB-SIM dosn't restore the PCLATH (from the
> stack).

That's because the PIC doesn't restore PCLATH on a return.  You have to
manually "restore" it to the current page after the return from a call.
Yes, I think this sucks too.  Take a look at my GCALL (Global CALL) macro in
STD.INS.ASPIC at http://www.embedinc.com/pic.  It sets PCLATH to the target,
does the CALL, then sets PCLATH back to the current page after the return.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, KILLspamolinKILLspamspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\06\25@120813 by Olin Lathrop

face picon face
> I've fixed it with a small macro which checks the program location (page)
> where it inserted and "restores" (set it with the right values) the
PCLATH.

There is a pseudo-op called PAGESEL that does this.  The advantage of
PAGESEL is that it works with the linker so that you don't need to know what
page you're on at assembly time.

Please fix your reply address so that the default is to the list instead of
you.  I'm getting tired of fixing it manually every time.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, spamBeGoneolinspamBeGonespamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


2001\06\25@193658 by Christian Dorner

flavicon
face
Hello!

> There is a pseudo-op called PAGESEL that does this.  The advantage of
> PAGESEL is that it works with the linker so that you don't need to know
what
> page you're on at assembly time.

Thanks for the help and for the hint.

Also thanks to all other piclister who explained me my missunderstud of
PCLATH and CALL/RETURN.

> Please fix your reply address so that the default is to the list instead
of
> you.  I'm getting tired of fixing it manually every time.

Done.

cu, Christian

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamTakeThisOuTmitvma.mit.edu


2001\06\26@090629 by Olin Lathrop

face picon face
> > Please fix your reply address so that the default is to the list instead
> of
> > you.  I'm getting tired of fixing it manually every time.
>
> Done.

No, you still have REPLY: set to you.  I had to manually edit the TO:
address of this reply to make it go to the list.  Yes, I know the PIClist
server should do this automatically, but unfortunately it doesn't.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, olinEraseMEspam.....embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\06\26@092535 by Kevin Blain

flavicon
face
better still, set your reply to address to nothing (I notice you're using
outlook 5.5).

Then the mailserver will insert a reply to for you, and when you send
private mails to individuals, they can reply direct to you.


Regards, Kevin

{Original Message removed}

2001\06\26@185510 by Christian Dorner

flavicon
face
> No, you still have REPLY: set to you.  I had to manually edit the TO:
> address of this reply to make it go to the list.  Yes, I know the PIClist
> server should do this automatically, but unfortunately it doesn't.

Olin, in this case you're wrong. Check out the msg header, the REPLY-TO
header entry is set to PICLIST ... the only thing is that my name appears in
the TO line in your mail program. (But this does not affect the function of
the reply)

I've configurated now my mail-server to change this, too. I hope now for the
future everything in my mails will be right. (Except for the content of the
msg, i can't guarantee to ask further stupid questions, but i'll do my best
to avoid this :-)

cu, Christian

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...