There are many options here… so here‘s just one of them…
1. Ensure that your Device Oscillator Configuration Bits are set to INTRC_OSC_NOCLKOUT (if you don’t know how to do this, see the new FAQ section). This option also means that the two OSC pins are made available for I/O. If you need the Oscillator to output on OSC2, then select the appropriate option (again see FAQ section).
2. Somewhere at the start of your program (where you normally initialise your processors registers) add the line…
OSCCON=%01111000
I refer you to the Datasheet section 4, especially Register 4.2 OSCCON to discover what I have done.
3. If stabilising your clock to other events is important to you, then you may need to add this piece of code after the above OSCCON setting (otherwise it is not necessary)…
While OSCCON.2=0:Wend
This will ensure the PIC does not continue processing until the new Oscillator Frequency is stable by introducing a 4mS delay (see datasheet 4.6.5 item 4).
As with ALL the queries regarding the set-up of PICs – Read the Datasheet! – it’s all there waiting for you to discover.
Bookmarks