
#include <REGX52.H>
#define PACKETLEN	5

void comhandle(void);

unsigned char combuf[PACKETLEN];//com buffer
unsigned char bufcntr=0;

void serialhandler(void) interrupt 4
{
	TI=0;
	if(RI)
	{
		comhandle();
		RI=0;
	}
}

void comhandle(void)
{
	combuf[bufcntr]=SBUF;
	bufcntr++;
	
	if(bufcntr>=PACKETLEN)
	bufcntr=0;	
}

void serialbaud(void) interrupt 5//timer 2 interrupt
{
}

void initser(void)
{
	IE|=0xB0;//timer 2 and serial interrupts enabled
	T2CON=0x30;//rclk and tclk enabled
	
	SCON=0x50;//serial mode 1
	
	RCAP2L=0x64;//reload values for 2403 baud
	RCAP2H=0xFF;

	TR2=1;//start the baud rate generator
}

void main(void)
{
	initser();
	while(1);
}