//Easy 51Pro编程器
//E51p.c
#include <at89x52.h>
#include <e51pro.h>



void Delay(ULONG nTimer)
{
	for(nTimer;nTimer!=0;nTimer--)
	{
	}
}

BOOL WaitComm()
{
	BYTE n=0;
	UINT nTimeOut;
	while(!RI){}
	ComBuf[n]=SBUF;
	RI=0;
	n++;
	for(n;n<=17;n++)
	{
		nTimeOut=0;
		while(!RI)
		{
			if(nTimeOut>10000) 
				return 0;
			nTimeOut++;
				
		}
		ComBuf[n]=SBUF;
		RI=0;
	}
	return 1;
}

void SendData()
{
	BYTE n=0;
	for(n;n<=17;n++)
	{
		TI=0;
		SBUF=ComBuf[n];
		while(!TI){}
		TI=0;
	}
}

void main()
{
	SP=0x60;
	SCON=0x00;
	TCON=0x00;
	PCON=0x80;
	IE=0x00;
	//TMOD: GATE|C/!T|M1|M0|GATE|C/!T|M1|M0
	//        0    0   1  0   0    0   0  0
	TMOD=0x20;
	TH1=0xff;
	TL1=0xff;
	//SCON: SM0|SM1|SM2|REN|TB8|RB8|TI|RI
    //        1   1   0   1   0   0  0  0
	SCON=0xd0;
	TR1=1;
	while(1)
	{
		if(!WaitComm())
		{
			Delay(10000);
			ComBuf[0]=0;
			SendData();
			continue;
		}
		switch(ComBuf[1])//根据FID跳到不同的函数处理编程过程
		{
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			default:
				break;
		}
	}
}


