I'm currently using the PIC18F45K20 for my project. I would like to know if there is any need of configuration of software if I'm using an external clock (8MHz crystal oscillator). The external clock I am using is 2 ceramic capacitor connected to the crystal and the other end of the capacitors are grounded. The software I am using is the MPLAB IDE X v 1.41. If a configuration is needed how do I configure the PIC?

  • \$\begingroup\$ Assembler or C? If C, which compiler? You need to read the data sheet! \$\endgroup\$ – Leon Heller Feb 24 '13 at 20:11
  • \$\begingroup\$ @LeonHeller The compiler is MPLAB. That was in the text of the question from the beginning. \$\endgroup\$ – Nick Alexeev Feb 24 '13 at 20:17
  • 2
    \$\begingroup\$ That is the IDE, not the compiler! \$\endgroup\$ – Leon Heller Feb 24 '13 at 20:21

As Leon said, all of these things are pretty clearly explained in the datasheet.

Page 29: Bits 1-0 of the OSCCON register define the system clock selection.

SCS<1:0>: System Clock Select bits

1x = Internal oscillator block
01 = Secondary (Timer1) oscillator
00 = Primary clock (determined by CONFIG1H[FOSC<3:0>]).

The power up-default for this is 00.

Page 300: The default / unprogrammed value for CONFIG1H as 00xx0111. The last four bits are the FOSC oscillator selection bits:

FOSC<3:0>: Oscillator Selection bits
11xx = External RC oscillator, CLKOUT function on RA6
101x = External RC oscillator, CLKOUT function on RA6
1001 = Internal oscillator block, CLKOUT function on RA6, port function on RA7
1000 = Internal oscillator block, port function on RA6 and RA7
0111 = External RC oscillator, port function on RA6
0110 = HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1)
0101 = EC oscillator, port function on RA6
0100 = EC oscillator, CLKOUT function on RA6
0011 = External RC oscillator, CLKOUT function on RA6
0010 = HS oscillator
0001 = XT oscillator
0000 = LP oscillator

So, unless you change the config bits yourself, the part will expect an external RC oscillator.

You most likely will need to / want to change other things, so from your project go to Window -> PIC Memory Views -> Configuration Bits, set things up as you need them, then copy the generated code into your project.

| improve this answer | |

You should always set the configuration bits in your code. MPLAB may default to something usable when running with a debugger, but any such defaults don't go into the HEX file. You want to make sure that the HEX file can stand on its own, and not require MPLAB and with your special settings to program into a part. Even then, I don't think MPLAB defaults config settings all the time.

Again, not specifying all config bits in your source code is a really bad idea.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.