
#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.
}

unsigned char serial1InIndex=0;//for queued serial comms
unsigned char serial1OutIndex=0;
unsigned char serial1InQueue[16];//data queued to go out on UART 0
unsigned char serial1OutQueue[16];//data queued to be processed from UART 0
//could maybe use bits for status indicators and check completion in main loop?
unsigned char serial1InStatus=1;//1 for ready, 2 for in-progress, 3 for transaction complete but unserviced
unsigned char serial1OutStatus=1;//

/*int serial2InIndex=0;
int serial2OutIndex=0;
int serial2InQueue[16];//data queued to go out on UART 1
int serial2OutQueue[16];//data queued to be processed from UART 1
int serial2InStatus=1;//1 for ready, 2 for in-progress, 3 for transaction complete but unserviced
int serial2OutStatus=1;//*/

static void serialOneService(void) interrupt 5{//services serial comms to and from scan tool
TI_0=false;
SBUF0=0x41;
}

//responses to first
code unsigned char response1Array[5]={0x04, 0x08, 0xFF, 0x10, 0x02};
code unsigned char 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;
	while(1){
//		if(serial1OutStatus==3){//handle the messages from the serial port
	}
}