$CRYSTAL

Top  Previous  Next

Action

Instruct the compiler to override the crystal frequency options setting.

 

 

Syntax

$CRYSTAL = var

 

 

Remarks

var

A numeric constant with the Frequency of the crystal.

 

The frequency is selectable from the Compiler Settings. It is stored in a configuration file. The $CRYSTAL directive overrides this setting.

It is best to use the $CRYSTAL directive as the used crystal frequency is visible in your program that way.

 

notice The $CRYSTAL directive only informs the compiler about the used frequency. It does not set any fuse bit. The frequency must be know by the compiler for a number of reasons. First when you use serial communications, and you specify $BAUD, the compiler can calculate the proper settings for the UBR register. And second there are a number of routines like WAITMS, that use the execution time of a loop to generate a delay. When you specify $CRYSTAL = 1000000 (1 MHz) but in reality, connect a 4 MHz XTAL, you will see that everything will work 4 times as quick.

 

Most new AVR chips have an internal oscillator that is enabled by default. Check the data sheet for the default value.

 

 

See also

$BAUD , BAUD , CONFIG CLOCKDIV

 

 

Example

$regfile = "m48def.dat"

$crystal = 4000000

$baud = 19200

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

 

Print "Hello world"

End