[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 580: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 636: sizeof(): Parameter must be an array or an object that implements Countable
Brads Electronic Projects Forum • help me ! for PCLATH
Page 1 of 1

help me ! for PCLATH

Posted: Sat Oct 01, 2016 9:17 am
by ALEX001
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

Re: help me ! for PCLATH

Posted: Sat Oct 01, 2016 8:36 pm
by brad
I haven't used Assembly with PIC's in quite a number of years - however could you give some more detail about your project?

Re: help me ! for PCLATH

Posted: Mon Oct 03, 2016 12:22 am
by ALEX001
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

Re: help me ! for PCLATH

Posted: Mon Oct 03, 2016 12:48 pm
by Garth
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.

Re: help me ! for PCLATH

Posted: Wed Oct 05, 2016 2:58 am
by ALEX001
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

Re: help me ! for PCLATH

Posted: Wed Oct 05, 2016 7:42 pm
by brad
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.