Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2258896
  • 博文数量: 187
  • 博客积分: 1457
  • 博客等级: 上尉
  • 技术积分: 2423
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-13 09:41
个人简介

如需要绘制PCB,设计电路可以和我联系。sunhenu@163.com.

文章分类

全部博文(187)

文章存档

2017年(2)

2016年(2)

2015年(7)

2014年(13)

2013年(80)

2012年(83)

分类: LINUX

2012-06-28 14:54:14

C8051F系列的,它的单片机很多,最重要的就是,它改变了经典51的速度,将经典51的系统12分频给取消了,就是1分频了。新的名字叫做CIP-51.

从它们的datasheet截图下来的,增加了XRAM,系统1分频或者2分频,还有就是它增加了一些经典51没有的外设接口,比如ADC,DAC,SMBUS(IIC),JTAG和芯片内部温度传感器,等等。

我就以C8051F021芯片为例说明一下,首先供电电压,经典51那就是5V,这个芯片不是5V,下面的表格说的很清楚了,我们就选择3.3V,不过它IO都是可以耐压5V,但是有些IO不可以的,要注意。

 

 

第二,说一下它的时钟配置,学习一个新的芯片,写代码之前要搞定它的时钟。如果没有,你还是别去写代码,先搞懂时钟。我只说配置为外部CMOS时钟输入的情况,晶振,RCC,或者自己内部时钟,请读者自己看说明书吧。

这个图足以说明一切,但是我还是要说,就是上面的那段英文,如果配置CMOS外部时钟为时钟源,XTAL1要接时钟输入脚,XTAL2可以悬空,还要注意这个时候XTAL1XTAL2都不可以接5V,也就是说输入电压在3.3以下,你可以接5V,反正是你设计电路,烧芯片也是你负责呀。呵呵。

2个寄存器比较重要OSCXCNOSCICN.

只有bit6-bit4有用,其他的对该配置无用。啥意思,自己看。

各项的意思,我不翻译英文,自己看。

接下来,我们具体看看C语言如何配置

//-----------------------------------------------------------------------------

// F02x_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: C8051F02x

// Tool chain: KEIL C51 6.03 / KEIL EVAL C51

//

//-----------------------------------------------------------------------------

// Includes

//-----------------------------------------------------------------------------

#include // SFR declarations

//-----------------------------------------------------------------------------

// 16-bit SFR Definitions for ‘F02x

//-----------------------------------------------------------------------------

sfr16 DP = 0x82; // data pointer

sfr16 TMR3RL = 0x92; // Timer3 reload value

sfr16 TMR3 = 0x94; // Timer3 counter

sfr16 ADC0 = 0xbe; // ADC0 data

sfr16 ADC0GT = 0xc4; // ADC0 greater than window

sfr16 ADC0LT = 0xc6; // ADC0 less than window

sfr16 RCAP2 = 0xca; // Timer2 capture/reload

sfr16 T2 = 0xcc; // Timer2

sfr16 RCAP4 = 0xe4; // Timer4 capture/reload

sfr16 T4 = 0xf4; // Timer4

sfr16 DAC0 = 0xd2; // DAC0 data

sfr16 DAC1 = 0xd5; // DAC1 data

//-----------------------------------------------------------------------------

// Global CONSTANTS

//-----------------------------------------------------------------------------

sbit LED = P1^6; // LED=’1’ means ON

sbit SW1 = P3^7; // SW1=’0’ means switch pressed

//-----------------------------------------------------------------------------

// Function PROTOTYPES

//-----------------------------------------------------------------------------

void SYSCLK_IntOsc_Init (void);

void SYSCLK_Crystal_Init (void);

void SYSCLK_C_RC_Init (void);

void SYSCLK_CMOS_Init (void);

//-----------------------------------------------------------------------------

// MAIN Routine

//-----------------------------------------------------------------------------

void main (void) {

WDTCN = 0xde; // disable watchdog timer

WDTCN = 0xad;

// select one of the following functions to initialze the system clock

SYSCLK_IntOsc_Init ();

// SYSCLK_Crystal_Init ();

// SYSCLK_C_RC_Init ();

// SYSCLK_CMOS_Init ();

while (1);

}

//-----------------------------------------------------------------------------

// Initialization Subroutines

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

// SYSCLK_IntOsc_Init

//-----------------------------------------------------------------------------

//

// This routine initializes the system clock to use the internal oscillator

// at its maximum frequency.

//

void SYSCLK_IntOsc_Init (void)

{

OSCICN = 0x87; // Set internal oscillator to

// maximum frequency and enable missing

// clock detector

}

//-----------------------------------------------------------------------------

// SYSCLK_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 SYSCLK_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

}

//-----------------------------------------------------------------------------

// SYSCLK_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 SYSCLK_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

}

//-----------------------------------------------------------------------------

// SYSCLK_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 SYSCLK_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

}

配置为CMOS时钟源,就这两条语句就行了。

 

阅读(2900) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~