⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cryosc.c

📁 C & Asm source code for cygnal microcontrollers C8051F3xx.
💻 C
字号:
//-----------------------------------------------------------------------------
// Cryosc.c
//-----------------------------------------------------------------------------
// Copyright 2001 Cygnal Integrated Products, Inc.
//
// AUTH: BW
// DATE: 11 OCT 01
//
// This program shows an example of configuring the external oscillator for
// use with a crystal. 
//
// Assumes an 22.1184MHz crystal is attached between XTAL1 and XTAL2.
//
// Target: C8051F30x
// Tool chain: KEIL C51 6.03 / KEIL EVAL C51
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <c8051f300.h>                 // SFR declarations

//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F30x
//-----------------------------------------------------------------------------

sfr16 DP       = 0x82;                 // data pointer
sfr16 TMR2RL   = 0xca;                 // Timer2 reload value
sfr16 TMR2     = 0xcc;                 // Timer2 counter
sfr16 PCA0CP1  = 0xe9;                 // PCA0 Module 1 Capture/Compare
sfr16 PCA0CP2  = 0xeb;                 // PCA0 Module 2 Capture/Compare
sfr16 PCA0     = 0xf9;                 // PCA0 counter
sfr16 PCA0CP0  = 0xfb;                 // PCA0 Module 0 Capture/Compare

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------

#define SYSCLK       22118400          // SYSCLK frequency in Hz

sbit LED = P0^2;                       // LED='1' means ON
sbit SW2 = P0^3;                       // SW2='0' means switch pressed

//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------

void PORT_Init (void);
void SYSCLK_Init (void);

//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------

void main (void) {

   // Disable Watchdog timer
   PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer 
                                       // enable)

   PORT_Init ();                       // initialize ports and GPIO
   SYSCLK_Init ();                     // initialize oscillator

   while (1);
}

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports.
// P0.0 - 
// P0.1 -
// P0.2 - XTAL1
// P0.3 - XTAL2
// P0.4 - UART TX (push-pull)
// P0.5 - UART RX
// P0.6 - 
// P0.7 - C2D
//
void PORT_Init (void)
{
   XBR0    =  0x0c;                    // skip crystal pins in crossbar 
                                       // assignments
   XBR1    =  0x03;                    // UART0 TX and RX pins enabled
   XBR2    =  0x40;                    // Enable crossbar and weak pull-ups
   P0MDIN &= ~0x0c;                    // configure XTAL1 and XTAL2 as analog
                                       // inputs
   P0MDOUT |= 0x10;                    // enable TX0 as a push-pull output
}

//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use a crystal
// as its clock source.  Also enables missing clock detector reset.
//
void SYSCLK_Init (void)
{
   int i;                              // delay counter

   OSCXCN = 0x60;                      // start external oscillator with
                                       // 32.768kHz crystal

   for (i=0; i < 256; i++) ;           // Wait for osc. to start

   while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle

   RSTSRC = 0x40;                      // enable missing clock detector reset
   OSCICN = 0x08;                      // select external oscillator as SYSCLK
                                       // source
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -