CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to setup internal OSC in PIC16F616?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
martinj
Guest







How to setup internal OSC in PIC16F616?
PostPosted: Sun Jun 29, 2008 11:10 am     Reply with quote

Could anyone tell how to setup PIC16F616 to use internal oscillator 8Mhz and have 2MHz output at OSC2?


Many thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 29, 2008 11:53 am     Reply with quote

The program shown below should work. The OSCTUNE register has to
be set to 0, to work around a bug in the start-up code in vs. 4.075.
The OSCTUNE register is being set as if it was the OSCCON register,
except that there is no OSCCON register in this PIC.

The following program will blink an LED on pin C5.
Code:

#include <16F616.H>
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay (clock=8000000)

#byte OSCTUNE = 0x90

//=================================
void main()
{
OSCTUNE = 0;


while(1)
  {
   output_high(PIN_C5);
   delay_ms(500);
   output_low(PIN_C5);
   delay_ms(500);
  }

}
martinj
Guest







PostPosted: Sun Jun 29, 2008 12:04 pm     Reply with quote

Thanks!

Then what is IOSC4 and IOSC8 doing if INTRC was used?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 29, 2008 12:15 pm     Reply with quote

The IOFCS bit in the Config word is set by the compiler, based upon
the #fuses statement and the #use delay() statement in your program.

Here are the settings that the compiler uses for the program that I posted:
Quote:

Configuration Fuses:
Word 1: 3FE5 INTRC NOPROTECT IOSC8 MCLR NOWDT PUT BROWNOUT
martinj
Guest







PostPosted: Sun Jun 29, 2008 1:01 pm     Reply with quote

Thank you.

But looks IOSC8 is not a must, the code works fine without it.

My code is :
#fuses INTRC
#fuses NOPROTECT
#fuses PUT
#fuses NOWDT
#byte OSCTUNE = 0x90
#use delay(clock=8000000)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 29, 2008 1:15 pm     Reply with quote

I am going to say this one last time.

You don't directly control the IOSCx setting. It is set (or cleared) by
the compiler, based upon your settings for the oscillator and the #use
delay() frequency.


Quote:
#fuses INTRC
#fuses NOPROTECT
#fuses PUT
#fuses NOWDT
#byte OSCTUNE = 0x90
#use delay(clock=8000000)

The fuse settings shown above produce the following Config bits.
These show that the compiler does set the IOSC8 bit for your code.
Code:
Configuration Fuses:
   Word  1: 3FE5   INTRC NOPROTECT IOSC8 MCLR NOWDT PUT BROWNOUT
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group