Electronic – PIC 16F887 and the thesterious System Clock Select bit (SCS)

clockmicrochipmicrocontrollerpicprogramming

I'm using a PIC 16F887 and I'd like to use the internal oscillator HFINTOSC. To accomplish this, I set the IRCF 2:0 bits to 110 (4Mhz prescaler) and the FOSC 2:0 config bits to INTOSC.

Now I should do something I really can't understand: according to the datasheet (see pag. 61) I should set the bit SCS in order to use the internal clock source (see the final MUX on the diagram on pag. 61).
Because the SCS bit is in the OSCON register I should set it programmatically on my code but the code itself needs a clock source to be executed! How can I execute a code to set a bit to use a clock if the code needs a clock source in the first place?????

I quote the datasheet for the SCS bit:

4.6.1 SYSTEM CLOCK SELECT (SCS) BIT The System Clock Select (SCS) bit of the OSCCON register selects the system clock source that is used
for the CPU and peripherals. • WhentheSCSbitoftheOSCCONregister=0, the
system clock source is determined by configuration of the FOSC<2:0>
bits in the Configuration Word Register 1 (CONFIG1). •
WhentheSCSbitoftheOSCCONregister=1, the system clock source is chosen
by the internal oscillator frequency selected by the IRCF<2:0> bits of
the OSCCON register. After a Reset, the SCS bit of the OSCCON register
is always cleared.

Best Answer

You don't need to also write the SCS bit if you already selected the internal oscillator in the Configuration bits.

bit 0 SCS: System Clock Select bit

  • 1 = Internal oscillator is used for system clock
  • 0 = Clock source defined by FOSC<2:0> of the CONFIG1 register

The SCS bit is 0 by default, so the system clock is selected by the FOSC<2:0> CONFIG1 bits.

You don't even have to set the IRCF<2:0> bits, because their reset value is 110 = 4 MHz.

Related Topic