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 CCS Technical Support

External Oscillator with PIC MCU

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



Joined: 03 Dec 2008
Posts: 24

View user's profile Send private message

External Oscillator with PIC MCU
PostPosted: Tue Dec 23, 2008 5:50 am     Reply with quote

Hi,

I am using PIC microcontroller. If I wish to use an external crystal oscillator for my project, then is it necessary to include some lines of code in my program to tell that I'm using an external oscillator now? If it is needed, then how to write this in CCS C language?

Thanks a lot.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Dec 23, 2008 6:36 am     Reply with quote

For the different oscillator configurations you have to specify a Configuration bit. CCS calls these settings 'fuses'

Code:
External crystal   0    - 200kHz: LP
External crystal 200kHz -   4MHz: XT
External crystal   4MHz -  25MHz: HS
External Oscillator:              EC (or use 'EC_IO' to free the OSC2 output for normal I/O)

Depending on the processor model you are using there will be more options available, see the top of the header file for your chip. Also read the chapter 'Oscillator Configurations' in your chip's data sheet.

Example:
Code:
#include <18F458.H>
#fuses HS,NOWDT,NOLVP
#use delay(clock=16M)
winson



Joined: 03 Dec 2008
Posts: 24

View user's profile Send private message

PostPosted: Thu Dec 25, 2008 10:37 pm     Reply with quote

Quote:

#include <18F458.H>
#fuses HS,NOWDT,NOLVP
#use delay(clock=16M)


Thanks ckielstra.

Can i know what is NOLVP?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 8:05 am     Reply with quote

NOLVP = No Low Voltage Programming
NOWDT = No Watch Dog Timer

LVP allows the PIC to generate its own high voltage for programming instead of taking it from the MCLR pin. This can cause accidental programming under certain circumstances, which trashes your programmed code.
_________________
The search for better is endless. Instead simply find very good and get the job done.
winson



Joined: 03 Dec 2008
Posts: 24

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 1:38 pm     Reply with quote

Thanks SherpaDoug.

So every time just put

#fuses HS,NOWDT,NOLVP

Then can throw all the headache away.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 2:39 pm     Reply with quote

Well it depends on what you are doing. If your clock is a crystal slower than 4 MHz you don't want HS (see ckielstra's post), and if your product is running in the real world you may want the Watch Dog enabled.... All those choices are useful for somebody.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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