View previous topic :: View next topic |
Author |
Message |
tomtln Guest
|
need code for internal oscilator for 16f88 |
Posted: Tue Feb 17, 2004 1:20 am |
|
|
Hello everyone.
I need a simple code to set up for 4Mhz internal oscilator for 16f88 mcu |
|
|
Al
Joined: 13 Nov 2003 Posts: 28 Location: Belfast
|
Re: need code for internal oscilator for 16f88 |
Posted: Tue Feb 17, 2004 3:06 am |
|
|
tomtln wrote: | Hello everyone.
I need a simple code to set up for 4Mhz internal oscilator for 16f88 mcu |
I guess it is no the same as it would be for any other PIC, eg:
#include <16F88.h>
#use delay(clock=4000000) _________________ Alan Murray |
|
|
neil
Joined: 08 Sep 2003 Posts: 128
|
try this.... |
Posted: Tue Feb 17, 2004 5:20 am |
|
|
Hi Tom, try including the fuse: INTRC_IO, or INTRC if you want clkout on pin 15. As for selecting the speed, I don't think the #use delay will do this, as it is only there to tell the compiler how to generate its delay functions. See quote from manual: Quote: | Tells the compiler the speed of the processor and enables the use of the built-in functions: delay_ms() and delay_us(). Speed is in cycles per second. An optional restart_WDT may be used to cause the compiler to restart the WDT while delaying.
| If you are not using the internal delay functions (I try not to!) I don't think you will need this line! I can't find a command to configure the clock speed, I would expect it to be in the fuses line, but it is not. Try using assembler to setup the clock speed. See pages 38-41 on datasheet. Try the #use delay... line and see if it configures the speed, looking at the frequency on the clkout pin. (Use INTRC as the fuse). If this fails, try putting this code right at the start of your code:
Code: | #asm
movlw 0x6A; // put clock config word in W reg.
iorwf 0x8F; // OR config word with 'OSCCON' register (8Fh).
#endasm
|
There must be an easier way though? Anyone?!
Neil. |
|
|
bwhiten
Joined: 26 Nov 2003 Posts: 151 Location: Grayson, GA
|
|
Posted: Tue Feb 17, 2004 9:05 am |
|
|
You need to declare the Oscillator Control Register address, so in my include file I have these two lines:
#byte OSCCON = 0x8F
#use delay(clock=4000000)
Then to set the frequency to 4MHz, according to the data sheet, in my main() I have the following line:
OSCCON = 0x6C; |
|
|
Guest
|
|
Posted: Thu Aug 19, 2004 5:34 pm |
|
|
newest version of ccs compiler has a built in function for this
Code: |
#FUSES INTRC,...
#use delay(clock=8000000)
void main(){
setup_oscillator(OSC_8MHZ | OSC_INTRC);
}
|
the different options are listed in the header |
|
|
|