 
#include <DS89C4xx.h>
#include <stdio.h>

void initSerialPorts(){
	EA=1;//enable interrupts
	ES0=1;//enable serial port interrupts
	ES1=1;
	SCON0= 0xD2;//put serial ports into mode 3
	SCON1= 0xD2;
	TMOD |=0x20;//put timer 1 into mode 2
	TH1=244;//value to set timer to after it rolls over
	TR1=1;//start timer 1 running
	TB8_0=0;//9th data bit
	SMOD_1=1;//doubler bits for both serial ports
	PCON |= 0x80;
	TI_0=1;//initialize transmission interrupt bits
	TI_1=1;
	EWDI = 0;//disable watchdog timer interrupt
	//CKMOD |= 0x08;//set input clock freq divider to 1
	//CKCON |= 0x10;//don't care about value, but set it anyway.
}

int serial1InIndex=0;//for queued serial comms
int serial1OutIndex=0;
int serial1InQueue[16];//data queued to go out on UART 0
int serial1OutQueue[16];//data queued to be processed from UART 0
int serial1InStatus=1;//1 for ready, 2 for in-progress, 3 for transaction complete but unserviced
int serial1OutStatus=1;//

static void serialOneService(void) interrupt 5{//services serial comms to and from scan tool
	SBUF0=0x41;
}

//responses to first
int response1Array[5]={0x04, 0x08, 0xFF, 0x10, 0x02};
int response2Array[5]={0x04, 0x6C, 0xF1, 0x10, 0x60};

int i=0;
void main(void){
	initSerialPorts();
	//serial1OutQueue={0x04, 0x08, 0xFF, 0x10, 0x02};
	for(i=0; i<5; i++){
		serial1OutQueue[i]=response1Array[i];
	}
	SBUF0=0x00;
	TI_0=1;
	while(1){
		TI_0=1;
	}
}