📄 osc.c
字号:
#ifndef _OSC_C_
#define _OSC_C_
#include <c8051f000.h>
#include "osc.h"
//-----------------------------------------------------------------------------
// F0xx_Osc_Init.c
//-----------------------------------------------------------------------------
// Copyright 2003 Cygnal Integrated Products, Inc.
//
// AUTH: FB
// DATE: 27 DEC 02
//
// This program shows an example of configuring the internal
// and external oscillators.
//
// Target: C8051F00x and C8051F01x
// Tool chain: KEIL C51 6.03 / KEIL EVAL C51
//
//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// fSYSCLK_IntOsc_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use the internal oscillator
// at its maximum frequency.
//
void fSYSCLK_IntOsc_Init (void)
{
OSCICN = 0x87; // Set internal oscillator to
// maximum frequency and enable missing
// clock detector
}
//-----------------------------------------------------------------------------
// fSYSCLK_Crystal_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use a 22.1184MHz crystal
// as its clock source. Assumes a 22.1184 MHz crystal and associated loading
// capacitors are connected at XTAL1 and XTAL2.
//
void fSYSCLK_Crystal_Init (void)
{
int i; // delay counter
OSCXCN = 0x67; // start external oscillator with
// 22.1184MHz crystal
for (i=0; i < 256; i++) ; // XTLVLD blanking interval (>1ms)
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
OSCICN = 0x88; // select external oscillator as SYSCLK
// source and enable missing clock
// detector
}
//-----------------------------------------------------------------------------
// fSYSCLK_C_RC_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use an external RC network
// or a single capacitor as its clock source. Assumes an RC network is
// connected to XTAL1 or a single capacitor is connected to XTAL1 and
// XTAL2.
//
void fSYSCLK_C_RC_Init (void)
{
OSCXCN = 0x47; // start external oscillator in
// C/RC mode with XFCN = 7
OSCICN = 0x88; // select external oscillator as SYSCLK
// source and enable missing clock
// detector
}
//-----------------------------------------------------------------------------
// fSYSCLK_CMOS_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to the external oscillator in
// CMOS clock mode. Assumes a CMOS clock generator is connected to XTAL1.
//
void fSYSCLK_CMOS_Init (void)
{
OSCXCN = 0x20; // start external oscillator in
// CMOS clock mode.
OSCICN = 0x88; // select external oscillator as SYSCLK
// source and enable missing clock
// detector
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -