#include "C8051F020.h"
#include "DataType.h"

void Init_IO_Port ()
{
    XBR2 |= BIT6;  //使能交叉开关
}

void OSC_Init ()
{
    INT16U i;
	OSCICN |= BIT2 + BIT0 + BIT1;  //设置内部时钟为16 MHz, 使能时钟丢失检测
	OSCICN &= ~BIT3;
	OSCICN |= BIT7; 

//使用外部晶振
	OSCXCN = 0x67;                      // Enable external crystal osc.
	for (i=0; i < 1000; i++);           // Wait at least 1ms
	while (!(OSCXCN & BIT7));           // Wait for crystal osc to settle

	OSCICN |= BIT3;                  	// Select external clock source
	OSCICN &= ~BIT2;                 	// Disable the internal osc.			
}

void Close_WDT ()
{
    WDTCN = 0xde; // 关闭看门狗
	WDTCN = 0xad;
}

void Device_Init ()
{
	Close_WDT ();
	OSC_Init ();
	Init_IO_Port ();
}