/************************************************/
/*      TASK04			task_m04.c	*/
/*		Ultrasonic Sensor		*/
/*				mirs9503	*/
/************************************************/

#include"hard.h"

int uss_no;

void inzt04()
{
	uss_init();
	sys0(4, 0x1011);
	sys2(4, 5, 0, 0);
	sys5(4, 0, USS_INT_VCT, 0, 0);

	sys8(4, 1, 0);		/* uss_l */
	sys8(4, 2, 0);		/* uss_m */
	sys8(4, 3, 0);		/* uss_r */
	sys8(4, 4, 0);		/* counter */
	sys11(1);
}

void nrmt04(a, b)
int a, b;
{}

void timt04(a, b)
int a, b;
{
	uss_stop();
	uss_no = 1;
	uss_start(uss_no);
}

interrupt void intt04()
{
	int dip;
	int data, counter;

	dip = sys9(1, 3);

	uss_stop();
	if(uss_chk_int())
	{
		if(uss_chk_conect())
		{
			data = 999;
		}
		else
		{
			data = uss_data();
		}
	}
	else
	{
		data = 988;
	}

	if((dip == 0x00) || (dip == 0x01)){
		if((data > 3) && (data < 600)){ 
			sys8(4, uss_no, data);
		}
	}else{
		sys8(4, uss_no, data);
	}

	if(uss_no == 3)
	{
		counter = sys9(4, 4) + 1;
		sys8(1, 4, counter);
		uss_no = 1;
	}
	else
	{
		uss_no++;
		uss_start(uss_no);
	}
}