Multifunction pins usually have multiple control bits and unfortunately you have to track them all down individually. For the Bible they have a thing called a concordance, which has the following definition:I'm pulling my hair here ... I've set the RA3 pin as an input (the only way it can be set, by the way) and enabled its internal weak pull up. My intention is to use it as an ordinary input only pin. But when I pull the thing down, the device resets itself! ... Said pin is also the /MCLR pin, btw ... but that's not supposed to be relevant during normal operation.
Well duh! ... I just made it work ... what happened is that one is supposed to set both the MCLRE and LVP bits off in the configuration words in order to set said pin as a normal I/O ... but I didn't know that because until now I've never used that pin for anything out of convenience ...Have you declared it an Input Pin?
MCLR = OFF
YesWell duh! ... I just made it work ... what happened is that one is supposed to set both the MCLRE and LVP bits off in the configuration words in order to set said pin as a normal I/O ... but I didn't know that because until now I've never used that pin for anything out of convenience ...
Is that what you were referring to?
Which begs the question ... what's the point of leaving said pin as /MCLR when using this chip in a normal project? ... as a hard reset input?
Yes.Which begs the question ... what's the point of leaving said pin as /MCLR when using this chip in a normal project? ... as a hard reset input?
If set to MCLR even when the pin is unused, you should tie it high with a 10k.In addition, when used as the default MCLR, no external components are required so you don't really have to worry about the pin if it remains unused.
Just to be safe -- of course.If set to MCLR even when the pin is unused, you should tie it high with a 10k.
Not if you enable its internal pull up... it would behave just fine.Well if you set MCLR ON and do not tie it high it can float around and do all kinds of weird stuff!![]()
I am just going by Microchip recommendations.Not if you enable its internal pull up... it would behave just fine.
Now that, I didn't know ... I'll keep it in mind. Thanks for sharing.I am just going by Microchip recommendations.
;Select appropriate program memory page before and after calling a rouinte
Fcall macro Routine
pagesel Routine ;select Routine's program memory page before calling
call Routine ;execute the routine
pagesel $ ;restore the current program memory page
endm
The pleasures of doing your own context switching. This is why most modern PIC's have shadow registers to help in that task. I'd be careful thinking manual saves and restores are the root cause solution.I've just solved a huge PITA that was giving me quite a headache and almost made me lose the last three strands of hair that I have left on my head... so I thought I might as well register it here for posterity's sake.
Ever since my code grew larger than 2K and had to use paging techniques, I've been using the following macro.
Well, this macro had been working fine until my code started to mysteriously and unpredictably crash. To make a long story short, I remembered that the crashes began to happen when I added a couple of subroutine calls from within the interrupt routine. And after some digging around, here's what I found in a forum:Code:;Select appropriate program memory page before and after calling a rouinte Fcall macro Routine pagesel Routine ;select Routine's program memory page before calling call Routine ;execute the routine pagesel $ ;restore the current program memory page endm
Also, if your program's interrupt service routine uses any 'call' or 'goto' instructions, the PCLATH register must be saved on entry to the ISR. It must then be cleared before executing a 'call' or 'goto' to a location within the ISR. Finally, before exiting the ISR, the saved value of PCLATH must be restored to the register.
So that's exactly what I did. I backed up the contents of PCLATH immediately at the start of the interrupt routine, then I cleared the file and proceeded with the rest of the code. And then I restored the original content of PCLATH immediately before executing the retfie instruction.
Voila... problem solved. I hope this at least spares a future poor devil the painful birthing labor that learning to code this architecture has proven to be.
Now I'm off to buy a wig ...
https://www.microchip.com/forums/m1199003.aspx8.5 Automatic Context Saving Upon entering an interrupt, the return PC address is saved on the stack. Additionally, the following registers are automatically saved in the shadow registers:
• W register
• STATUS register (except for TO and PD)
• BSR register
• FSR registers
• PCLATH register
Upon exiting the Interrupt Service Routine, these registers are automatically restored. Any modifications to these registers during the ISR will be lost. If modifications to any of these registers are desired, the corresponding shadow register should be modified and the value will be restored when exiting the ISR. The shadow registers are available in Bank 31 and are readable and writable. Depending on the user’s application, other registers may also need to be saved.