help me ! for PCLATH

Post here to discuss the PIC microcontroller tutorials.

Moderators: Chuckt, Garth, bitfogav

Post Reply
ALEX001
newbie
newbie
Posts: 3
Joined: Sat Oct 01, 2016 7:01 am

help me ! for PCLATH

Post by ALEX001 » Sat Oct 01, 2016 9:17 am

erased.....
-------------------------------------------------------------------------------



Excuse me , my question was Confused
So let me put my question: I have a program for micro PIC16F616
MY program is 990 WORD.( less, then 2k Word)

Under what circumstances is in need of change PCLATH:
1. When I use the GOTO statement.
2. When I use the CALL command.
3. When the PCL change. For example: ADDWF PCL, F
Last edited by ALEX001 on Mon Oct 03, 2016 12:58 am, edited 3 times in total.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm

Re: help me ! for PCLATH

Post by brad » Sat Oct 01, 2016 8:36 pm

I haven't used Assembly with PIC's in quite a number of years - however could you give some more detail about your project?

ALEX001
newbie
newbie
Posts: 3
Joined: Sat Oct 01, 2016 7:01 am

Re: help me ! for PCLATH

Post by ALEX001 » Mon Oct 03, 2016 12:22 am

Excuse me , my question was Confused
So let me put my question: I have a program for micro PIC16F616
MY program is 990 WORD.( less, then 2k Word)

Under what circumstances is in need of change PCLATH:
1. When I use the GOTO statement.
2. When I use the CALL command.
3. When the PCL change. For example: ADDWF PCL, F

Garth
I practically live here!
I practically live here!
Posts: 226
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: help me ! for PCLATH

Post by Garth » Mon Oct 03, 2016 12:48 pm

I've brought quite a few products to market with PIC16's, but the last big PIC programming project was finished over two years ago so I'm getting a little rusty on that stuff and I had to look it up to make sure I'm not steering you wrong.

If you are only using page 0, you do not need to write to PCLATH (Program Counter LATch, High byte) for GOTO or CALL.

Even if you never leave page 0, when modifying PCL, you need to write to PCLATH if it might not already point to the same 256-byte page section as the intended destination.

You don't need to modify PCLATH before a RETURN or RETLW; but if later you do call a subroutine or table outside page 0, you'll want to put PCLATH back to the current page after the return so that subsequent GOTOs or CALLs intended for the same page don't go to the other page again.

If you allow interrupts when the program pointer is outside page 0 and the ISR (interrupt-service routine) might modify PCLATH, the ISR will have to save PCLATH's value first and then restore it before the RETFIE.
http://WilsonMinesCo.com/ lots of 6502 resources

ALEX001
newbie
newbie
Posts: 3
Joined: Sat Oct 01, 2016 7:01 am

Re: help me ! for PCLATH

Post by ALEX001 » Wed Oct 05, 2016 2:58 am

Garth wrote:I've brought quite a few products to market with PIC16's, but the last big PIC programming project was finished over two years ago so I'm getting a little rusty on that stuff and I had to look it up to make sure I'm not steering you wrong.

If you are only using page 0, you do not need to write to PCLATH (Program Counter LATch, High byte) for GOTO or CALL.

Even if you never leave page 0, when modifying PCL, you need to write to PCLATH if it might not already point to the same 256-byte page section as the intended destination.

You don't need to modify PCLATH before a RETURN or RETLW; but if later you do call a subroutine or table outside page 0, you'll want to put PCLATH back to the current page after the return so that subsequent GOTOs or CALLs intended for the same page don't go to the other page again.

If you allow interrupts when the program pointer is outside page 0 and the ISR (interrupt-service routine) might modify PCLATH, the ISR will have to save PCLATH's value first and then restore it before the RETFIE.
Many thanks for your very quick reply

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm

Re: help me ! for PCLATH

Post by brad » Wed Oct 05, 2016 7:42 pm

Thanks for the great help there Garth.

I am incredibly rusty on my PIC16 ASM code. 2009 was the last I used it I think and even then, I had very little to do with the high side of the program counter.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests