#include "main.h"
#include "key.h"

extern uint8_t KEY;
extern uint8_t TEMP;   
uint8_t IDLE_FLG = 0;
void main(void)
{
	System_Init();  
	while(1)
	{
		if(IDLE_FLG == 1)
		{
			IDLE_FLG = 0;			
			Change_To_IDLE();
		}
	}		
}

void System_Init(void)
{
	IO_CLR();
//	lcd_off();
	lcd_alloff();
	key_init();
	Change_To_IDLE();
}

void Change_To_IDLE(void)
{	
	ALFSEL1 &= ~(0x80);   //关闭红外
	REMCON &= ~(0x01);
	IEN2 &= ~0x08;
	PWM0CON = 0x00; 
	
	BORCON |= 0x01; //使能BOR
	WDTCON &= 0xFD; //禁止WDT 	
	
	CLKEN0 = 0x00;
	CLKEN1 = 0x40; //仅使能LCD时钟
	SYSCON &= 0x3F;    //系统时钟分频清零
	SYSCON |= (3 << 6); //设置系统时钟不分频
	SYSCON |= 0x02;
	while((CLKSTAT & 0x04) == 0);
	SYSCON &= 0xBF;  //系统时钟四分频
	CLKCFG |= 0x80; 
	SYSCON &= 0xFE;   //禁止IHRC
	IEN2 |= 0x01; //打开外部中断使能
	PCON |= 0x01;    //打开IDLE
}


















