/*使用C8051F020，外部晶振11.0592M*/
#include "C8051F020.h"

 //**********************************************************

//系统时钟初始化	

//**********************************************************
void OSCILLATOR_Init (void)
{
   int i;                              // Software timer

   OSCICN |= 0x80;                     // Enable the missing clock detector

   // Initialize external crystal oscillator to use 22.1184 MHz crystal

   OSCXCN = 0x67;                      // Enable external crystal osc.
   for (i=0; i < 256; i++);            // Wait at least 1ms
   while (!(OSCXCN & 0x80));           // Wait for crystal osc to settle
   OSCICN |= 0x08;                     // Select external clock source
   OSCICN &= ~0x04;                    // Disable the internal osc.
}

main(void)
{
	WDTCN = 0xde;                      // Disable watchdog timer
	WDTCN = 0xad;

	XBR2    = 0x40;                    // Enable crossbar and enable
                                       // weak pull-ups	
 	OSCILLATOR_Init ();                // Initialize oscillator
	while (1)
   	{

		if ((P5&0x04) == 0)            // If switch depressed
     	{ 
			P5 &= (~0x01);             // Turn on LED
		}
		else   
		{  
  	       	P5 |= 0x01;                // Else, turn it off
		} 
        
        if ((P5 & 0x08) == 0)          // If switch depressed
      	{ 
			P5 &= (~0x02);             // Turn on LED
		}
		else   
		{  
  	       	P5 |= 0x02;               // Else, turn it off
		}         	      
	}                                 // end of while(1)
}	   
