I'm trying to program a PIC16F88 in C. I am new to using C for PICs so this question might seem trivial to many of you.
The thing is that my PIC is always running on the lowest frequency, 31.250Hz. I use this line : #use delay(clock=4000000) to tell the delay loop the expected frequency. At first I thought that this would also take care of the OSCCON register that I used to set the freq in ASM. To me it looks like it doesn't.
The only thing I could do was to connect an external Xtal Clock to get the PIC to run on the frequency I wanted. That's not cool - so my question is:
How on earth do I adjust the frequency of the internal osc in C?
Thanks in advance
Steini
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
Posted: Sun Sep 09, 2007 7:20 am
Code:
#use delay(clock=4000000)
This instruction tells the compiler the actual clock speed of your processor so it can create correct timings for the delay_us() and delay_ms() functions. The naming of this instruction is not very good in the CCS compiler as in newer functions of the compiler the same command is used to define the timing for more functions like RS232 and internal oscillator configuration.
If your processor is to run at 31.250Hz, than set that value in the above command. Don't set it to 4Mhz.
You can specify the clock speed using the setup_oscillator() function. If you have set the #fuses to ITRC or INTRC_IO then the compiler will set the correct configuration for you in the OSCCON register. I have confirmed this with a test in both v3.249 and v4.038.
For a clock of 31.250Hz the above code is missing because this is already the default value after a hardware reset.
If your code is not working double check you have the INTRC or INTRC_IO fuses specified.
Also read the manual for the Setup_osscilator() function as there are some special concerns related to clock speed switching.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum