[目次]

 1.概要 ------------------------------------------------------------------ 1

 2.ソースリスト
  2.1 エントリ・プログラム (c_entry.s) -------------------------------- 2
  2.2 通信関係のシンボル定義 (duscc.h) -------------------------------- 4
  2.3 シンボル定義 (tmp_def.h) ---------------------------------------- 5
  2.4 メインプログラム (tmp.c) ---------------------------------------- 8
  2.5 メニューファイル (menu.c) --------------------------------------- 12
  2.6 マンマシンインタフェースボードの試験(mmi.c) --------------------- 13
  2.7 ロータリエンコーダ・タッチセンサボードの試験(re_ts.c)------------- 17
  2.8 PWM回路の試験(pwm.c)------------------------------------------- 22
  2.9 赤外線センサ回路の試験(ps.c)-------------------------------------- 25
  2.10 超音波センサ回路の試験(sss.c)------------------------------------- 28
  2.11 電源・勝敗判定装置の試験(pow.c)----------------------------------- 33
  2.12 下位関数群(tmp_sub.c)--------------------------------------------- 34

 3.メイク・ファイル (tmp.mak) -------------------------------------------- 37

 4.コマンド・ファイル (tmp.cmd) ------------------------------------------ 38


1.概要

 ここでは、「個別保守診断プログラムのソースリスト」は個別保守診断プログラムを構成する全てのソースリスト、及び実行ファイル作成に必要なメイクファイル、コマンドファイルを掲載する。


2.ソース・リスト

2.1 エントリ・プログラム(c_entry.s)

 *****************************************************************************
 *                                                                           *
 *          Department of Electronics & Control Engineering  N.C.T.          *
 *---------------------------------------------------------------------------*
 *                    c_entry.s -- C Start-up Routine   (for all C programs) *
 *****************************************************************************

	OPT	CASE

ENTRY	IDNT
	SECTION	code,,C

	XDEF	ENTRY

	XREF	????STACKTOP
	XREF	__initcopy			* Initialize variables copy ()
	XREF	_main				* C's main()

	DC.L	????STACKTOP			* SSP on Cold Start
	DC.L	$0F00008			* Entry Point

ENTRY:
	MOVEA.L	#????STACKTOP,SP		* Stack Pointer
	MOVEA.L	#0,A6				* Frame Pointer Initialization
	MOVE	#$2700,SR			* Disable interrupt

*
*	THE FOLLOWING CODE CLEARS THE ZEROVARS SECTION
*
*		from /mirs/sawa/demo68k/entry.s
*
	LEA	.STARTOF.(zerovars),A0		* START OF THE SECTION
	MOVE.L	#.SIZEOF.(zerovars),D1		* LENGTH OF THE SECTION
	MOVE.L	D1,D0				* SAVE IN D0 ALSO
	LSR.L	#2,D1				* NUMBER OF LONG WORDS TO MOVE
	BRA.S	CLROVARS1			* SKIP FIRST CLEAR
CLROVARS:
	CLR.L	(A0)+				* CLEAR THE ADDRESS
CLROVARS1:
	DBF	D1,CLROVARS			* DECREMENT LONG WORD COUNT & TEST
	SUBI.L	#$10000,D1			* SIMULATE BORROW FROM LOW 16 BITS
	CMPI.L	#-1,D1				* IS LONG WORD COUNT == -1
	BNE.S	CLROVARS			* NO -- KEEP CLEARING
*
	ANDI.L	#3,D0				* SHOULD INDIVIDUAL BYTES BE CLEAR
	BRA.S	CLROVARS2			* SKIP FIRST CLEAR
CLROVARS3:
	CLR.B	(A0)+				* CLEAR ONE MORE BYTE
CLROVARS2:
	DBF	D0,CLROVARS3			* DECREMENT BYTE COUNT & TEST


	JSR	__initcopy(PC)			* ROM INITIALIZATION

	JSR	_main				* Call main()

LSTOP:	
	STOP	#$2700				* Halt until Level 7 Interrupt
	BRA.S	LSTOP
	RTS
*
*	end of SECTION code
*

	SECTION zerovars,,D			* DATA SECTION

*
*	FORCE SECTION vars TO FOLLOW SECTIONS code AND zerovars IN
*	MEMORY. THIS IS DONE EVEN THOUGH THERE IS NO CODE IN
*	SECTION vars.
*
	SECTION vars,,D				* INITIALIZED DATA


	END	ENTRY

 * end of c_entry.s *


2.2 通信機能関係のシンボル定義(duscc.h)

/*	duscc.h		*/
/*	Definition of DUSCC Register Address	*/

#define	CMR1	0xfdfc81	/*	Channel Mode Register1	*/
#define	CMR2	0xfdfc83	/*	Channel Mode Register2	*/
#define	S1R	0xfdfc85	/*	SYN 1/Secondary Address 1 Register	*/
#define	S2R	0xfdfc87	/*	SYN 2/Secondary Address 2 Register	*/
#define	TPR	0xfdfc89	/*	Transmitter Parameter Register	*/
#define	TTR	0xfdfc8b	/*	Transmitter Timing Register	*/
#define	RPR	0xfdfc8d	/*	Receiver Parameter Register	*/
#define	RTR	0xfdfc8f	/*	Receiver Timing Register	*/
#define	CTPRH	0xfdfc91	/*	Counter/Timer Preset Register High	*/
#define	CTPRL	0xfdfc93	/*	Counter/Timer Preset Register Low	*/
#define	CTCR	0xfdfc95	/*	Counter/Timer Control Register	*/
#define	OMR	0xfdfc97	/*	Output and Miscellaneous Register	*/
#define	CTH	0xfdfc99	/*	Counter/Timer High	*/
#define	CTL	0xfdfc9b	/*	Counter/Timer Low	*/
#define	PCR	0xfdfc9d	/*	Pin Configuration Register	*/
#define	CCR	0xfdfc9f	/*	Channel Command Register	*/
#define	TxFIFO	0xfdfca1	/*	Transmitter FIFO	*/
#define	RxFIFO	0xfdfca9	/*	Receiver FIFO	*/
#define	RSR	0xfdfcb1	/*	Receiver Status Register	*/
#define	TRSR	0xfdfcb3	/*	Transmitter and Receiver Status Register	*/
#define	ICTSR	0xfdfcb5	/*	Input and Counter/Timer Status Register	*/
#define	GSR	0xfdfcb7	/*	General Status Register	*/
#define	IER	0xfdfcb9	/*	Interrupt Enable Register	*/
#define	ICR	0xfdfcbf	/*	Interrupt Control Register	*/

#define	IVR	0xfdfcbd	/*	Interrupt Vector Register - Unmodified	*/
#define	IVRM	0xfdfcfd	/*	Interrupt Vector Register - Modified	*/


/*	Definition of DUSCC Command	*/

#define	RST_Tx		0x00	/*	Reset Tx	*/
#define	RST_TxCRC	0x01	/*	Reset TxCRC	*/
#define	EBL_Tx		0x02	/*	Enable Tx	*/
#define	DEBL_Tx		0x03	/*	Disenable Tx	*/
#define	RST_Rx		0x40	/*	Reset Rx	*/
#define	EBL_Rx		0x42	/*	Enable Rx	*/
#define	DEBL_Rx		0x43	/*	Disenable Rx	*/

/*	Definition of Vector Number for DUSCC	*/

#define	VCT	64

/*	other	symboles	*/

#define	BUFSIZE	255
#define	CR	0x0d
#define	NULL	0x00
#define	ACTIVE	1


2.3 シンボル定義(tmp_def.h)

/*	addresses of PI/T 0 registers	*/

#define	PGCR0	0xfdfc01	/*	Port General Control Reg.	*/
#define	PSRR0	0xfdfc03	/*	Port Select Request Reg.	*/
#define	PADDR0	0xfdfc05	/*	Port A Data Direction Reg.	*/
#define	PBDDR0	0xfdfc07	/*	Port B Data Direction Reg.	*/
#define	PCDDR0	0xfdfc09	/*	Port C Data Direction Reg.	*/
#define	PIVR0	0xfdfc0b	/*	Port Interrupt Vector Reg.	*/
#define	PACR0	0xfdfc0d	/*	Port A Control Reg.		*/
#define	PBCR0	0xfdfc0f	/*	Port B Control Reg.		*/
#define	PADR0	0xfdfc11	/*	Port A Data Reg.		*/
#define	PBDR0	0xfdfc13	/*	Port B Data Reg.		*/
#define	PAAR0	0xfdfc15	/*	Port A Alternate Reg.		*/
#define	PBAR0	0xfdfc17	/*	Port B Alternate Reg.		*/
#define	PCDR0	0xfdfc19	/*	Port C Data Reg.		*/
#define	PSR0	0xfdfc1b	/*	Port Status Reg.		*/
#define	TCR0	0xfdfc21	/*	Timer Control Reg.		*/
#define	TIVR0	0xfdfc23	/*	Timer Interrupt Vector Reg.	*/
#define	CPR0	0xfdfc25	/*	Counter Preload Reg.		*/
#define	CNTR0	0xfdfc2d	/*	Counter Reg.			*/
#define	TSR0	0xfdfc35	/*	Timer Status Reg.		*/


/*	I/O Base Address	*/

#define	IO_BASE	0xfc6000

/*	IP A base address	*/

#define	IP_A	IO_BASE


/*	addresses of rotary encoder/touch sensor	*/

#define	EDRL	IP_A+0x01	/*	Encoder Data of Right (Low)	*/ 
#define	EDRH	IP_A+0x03	/*	Encoder Data of Right (High)	*/
#define	EDLL	IP_A+0x05	/*	Encoder Data of Left (Low)	*/
#define	EDLH	IP_A+0x07	/*	Encoder Data of Left (High)	*/
#define	CRST	IP_A+0x09	/*	Counter Reset			*/
#define	TSIE	IP_A+0x0b	/*	Touch Sensor Interrupt Enable	*/


/*	IP B base address	*/

#define IP_B	IO_BASE+0x0100


/*	addresses of PI/T 1 (called 'X') registers	*/

#define	PGCR1	IP_B+0x01	/*	Port General Control Reg.	*/
#define	PSRR1	IP_B+0x03	/*	Port Select Request Reg.	*/
#define	PADDR1	IP_B+0x05	/*	Port A Data Direction Reg.	*/
#define	PBDDR1	IP_B+0x07	/*	Port B Data Direction Reg.	*/
#define	PCDDR1	IP_B+0x09	/*	Port C Data Direction Reg.	*/
#define	PIVR1	IP_B+0x0b	/*	Port Interrupt Vector Reg.	*/
#define	PACR1	IP_B+0x0d	/*	Port A Control Reg.		*/
#define	PBCR1	IP_B+0x0f	/*	Port B Control Reg.		*/
#define	PADR1	IP_B+0x11	/*	Port A Data Reg.		*/
#define	PBDR1	IP_B+0x13	/*	Port B Data Reg.		*/
#define	PAAR1	IP_B+0x15	/*	Port A Alternate Reg.		*/
#define	PBAR1	IP_B+0x17	/*	Port B Alternate Reg.		*/
#define	PCDR1	IP_B+0x19	/*	Port C Data Reg.		*/
#define	PSR1	IP_B+0x1b	/*	Port Status Reg.		*/
#define	TCR1	IP_B+0x21	/*	Timer Control Reg.		*/
#define	TIVR1	IP_B+0x23	/*	Timer Interrupt Vector Reg.	*/
#define	CPR1	IP_B+0x25	/*	Counter Preload Reg.		*/
#define	CNTR1	IP_B+0x2d	/*	Counter Reg.			*/
#define	TSR1	IP_B+0x35	/*	Timer Status Reg.		*/


/*	addresses of PI/T 2 (called 'Y') registers	*/

#define	PGCR2	IP_B+0x41	/*	Port General Control Reg.	*/
#define	PSRR2	IP_B+0x43	/*	Port Select Request Reg.	*/
#define	PADDR2	IP_B+0x45	/*	Port A Data Direction Reg.	*/
#define	PBDDR2	IP_B+0x47	/*	Port B Data Direction Reg.	*/
#define	PCDDR2	IP_B+0x49	/*	Port C Data Direction Reg.	*/
#define	PIVR2	IP_B+0x4b	/*	Port Interrupt Vector Reg.	*/
#define	PACR2	IP_B+0x4d	/*	Port A Control Reg.		*/
#define	PBCR2	IP_B+0x4f	/*	Port B Control Reg.		*/
#define	PADR2	IP_B+0x51	/*	Port A Data Reg.		*/
#define	PBDR2	IP_B+0x53	/*	Port B Data Reg.		*/
#define	PAAR2	IP_B+0x55	/*	Port A Alternate Reg.		*/
#define	PBAR2	IP_B+0x57	/*	Port B Alternate Reg.		*/
#define	PCDR2	IP_B+0x59	/*	Port C Data Reg.		*/
#define	PSR2	IP_B+0x5b	/*	Port Status Reg.		*/
#define	TCR2	IP_B+0x61	/*	Timer Control Reg.		*/
#define	TIVR2	IP_B+0x63	/*	Timer Interrupt Vector Reg.	*/
#define	CPR2	IP_B+0x65	/*	Counter Preload Reg.		*/
#define	CNTR2	IP_B+0x6d	/*	Counter Reg.			*/
#define	TSR2	IP_B+0x75	/*	Timer Status Reg.		*/


/*	addresses of RTC(real time clock)	*/

#define	MSR	0xfdfe01	/*	RTC Main Status Reg.		*/
#define	RTMR	0xfdfe03	/*	RTC Real Time Mode Reg.		*/
#define	ROMR	0xfdfe05	/*	RTC Output Mode Reg.		*/
#define	ICR0	0xfdfe07	/*	RTC Interrupt Control Reg. 0	*/
#define	ICR1	0xfdfe09	/*	RTC Interrupt Control Reg. 1	*/

/*	VMEbus IRQ-mask register	*/

#define	VIMR	0xfdff01



/*	data for menu	*/

#define	MAX_MENU_NO	6	/*	max menu number	*/






/*	data of timer interrupt reset	*/

#define	TMRST	0x44		/*	Timer Interrupt Reset		*/


/*	data for MMI		*/

#define	LED_WAIT	100000	/*	count to LED ON		*/
#define	LED_NO		4	/*	Number of 7seg.LED	*/
#define	RED		0x40	/*	Data for green LED	*/
#define	GREEN		0x80	/*	Data for red LED	*/


/*	data for PWM	*/

#define	D_MAX	(128-1)		/*	Maximum data for PWM		*/
#define	CW	0		/*	Data of clockwise		*/
#define	CCW	1		/*	Data of counterclockwise	*/
#define	STPWHL	0		/*	data to stop wheel		*/
#define	LOWSPD	(D_MAX * 1/8)	/*	PWM data for switching test	*/


/*	data for supersonic wave sensor		*/

#define	SSS_MAX		4	/*	Number of supersonic wave sensor	*/
#define	SSS_LIMIT	(int)(3 * 8000000/32 /340 *2)	/*	count for ss-wave to go & return 3m	*/

/*	data for photo sensor	*/

#define	PS_MAX	8	/*	Number of photo sensor	*/


/*	general purpose data */

#define	NON	-1	/*	Non_adaptive	*/


2.4 メインプログラム(tmp.c)

#include	"tmp_def.h"
#include	"duscc.h"

extern int	inportb(),outportb(),inportl(),outportl();
extern void	pwm_init();	/*	stop wheel at initialize	*/

void	rs_init(),rs_snd(),rs_rcv();	/*	RS-232C Drivers		*/
void	init();				/*	initialize module	*/
void	rtc_clr();
void	end();				/*	end module		*/


int	sw_ctr = 0;		/*	switch interrupt counter			*/
int	ts_ctr = 0;		/*	touch sensor interrupt counter			*/
int	sss_ctr = 0;		/*	ss sensor interrupt counter			*/
int	ps_ctr = 0;		/*	photo sensor interrupt counter			*/

char	getbuf[BUFSIZE];	/*	buffer for receive				*/
char	*end_get = getbuf;	/*	pointer which points end of received data	*/
char	stpflg = !ACTIVE;	/*	stop flag for communication			*/
char	crflg = !ACTIVE;	/*	CR flag for communication			*/
char	nextflg = !ACTIVE;	/*	next flag for TMP				*/

char	endflg = !ACTIVE;	/*	end flag	*/

char	buffer[BUFSIZE];	/*	buffer for general purpose	*/
char	err_msg[BUFSIZE];	/*	buffer for error message	*/

char	led_data[LED_NO];	/*	buffer for 7seg.LED data	*/
int	ps_data;		/*	photo sensor data		*/


main()
{	
	init();			/*	initialize DUSCC & RTC	*/

	asm(
"	MOVE	#$2000,SR	* Enable interrupt	"
	);

	while ( endflg != ACTIVE ) { 
		stpflg = !ACTIVE;

		switch ( menu() ) {
			case 1:
				mmi();		/*	Man-Machine Interface Board test	*/
				break;
			case 2:
				re_ts();	/*	Rotary Encoder/Touch Sensor Board Test	*/
				break;
			case 3:
				pwm();		/*	PWM Circuit Test			*/
				break;
			case 4:
				ps();		/*	Photo Sensor Circuit Test		*/	
				break;
			case 5:
				sss();		/*	Supersonic Wave Sensor Circuit Test		*/
				break;
			case 6:
				pow();		/*	Power Distributor/Judgement Unit Test	*/
				break;
			case 0:
				endflg = ACTIVE;
				break;
			default:
				break;
		}
	}

	end();
}


/*	RS-232C controle function -------- initialize	*/
void	rs_init()
{
	outportb(CCR,RST_Tx);
	outportb(CCR,RST_TxCRC);
	outportb(CCR,RST_Rx);

	outportb(CMR1,0x17);	/*	asynchronous mode with even parity	*/
	outportb(CMR2,0x38);	
	outportb(PCR,0x20);	
	outportb(TPR,0x73);
	outportb(TTR,0x39);	/*	bit rate 1200 bps	*/
	outportb(RPR,0x03);	/*	receiver parameter (character length 8 bit)	*/
	outportb(RTR,0x29);
	outportb(OMR,0x10);	/*	TxRDY is active when TxFIFO is empty
					RxRDY is active when RxFIFO is not empty	*/
	asm(
	"	MOVEA.L		#$100,A0	* address = VCT * 4",
	"	MOVE.L		#_rs_get,(A0)"
	);
	outportb(IVR,VCT);		
	outportb(IER,0x10);	/*	interrupts cause by RxRDY	*/
	outportb(ICR,0x02);	/*	vector is fixed	*/

	outportb(CCR,EBL_Tx);
	outportb(CCR,EBL_Rx);
}


/*	RS-232C controle function -------- receive	*/
void	rs_rcv( char *str_buf )
{
	char	*p = str_buf;
	char	*cur_get = getbuf;

	while ( (*cur_get != NULL) && (stpflg != ACTIVE) && (nextflg != ACTIVE) )
		*p++ = *cur_get++;
	*p = NULL;
	
	if ( stpflg != ACTIVE )
		end_get = getbuf;	
}


/*	RS-232C controle function -------- send	*/
void	rs_snd( char *send_str )
{
	char	*cur_put = send_str;	

	while( (*cur_put != NULL) && (stpflg != ACTIVE) && (nextflg != ACTIVE) )
	{
		if ( ((inportb(GSR) & 0x02)>>1) == ACTIVE )
			outportb(TxFIFO,*cur_put++);		
	}
}


/*	RS-232C controle function -------- key input interrupt	*/
interrupt void	rs_get()
{
	char	c;

	c = inportb(RxFIFO);
	
	switch ( c ) {
		case '@':
			*end_get = NULL;
			stpflg = ACTIVE;
			break;
		case CR:
			*end_get = NULL;
			crflg = ACTIVE;
			break;
		case '?':
			*end_get = NULL;
			nextflg = ACTIVE;
			break;
		default:
			*end_get = c;
			break;
	}
	end_get++;
}


void	init()
{
	rs_init();	/*	initialize RS-232C	*/
	rtc_clr();	/*	clear RTC		*/
	pwm_init();	/*	stop wheels		*/
}


/*	clear Real Time Clock  registers	*/
void	rtc_clr()
{
	int	rtc_base;
	int	i;

	rtc_base=0xfdfe00;

	outportb(MSR,0x44);
	for ( i=3 ; rtc_base+ i<0xfdfe40 ; i+=2 ) outportb(rtc_base+i,0x00);

	outportb(MSR,0x04);
	for ( i=3 ; rtc_base+ i<0xfdfe0a ; i+=2 ) outportb(rtc_base+i,0x00);
}


/*	end function of TMP	*/
void	end()
{
	rs_snd("\n  --  END of TMP  --------------------------");
	rs_snd("\n  ////  O.K.  //// \n");

	endflg = !ACTIVE;

	while(1);
}


2.5 メニュー表示(menu.c)

#include	"tmp_def.h"
#include	"duscc.h"

extern void	rs_snd();
extern int	inp();

extern char	stpflg,nextflg;


int	menu()
{
	int	selected_no;


	nextflg = !ACTIVE;

	rs_snd("\n Please Select Menu No. below\n\n");

	rs_snd("     1:Man-Machine Interface Board \n\n");

	rs_snd("     2:Rotary Encorder/Touch Sensor Board \n\n");

	rs_snd("     3:PWM Circuit \n\n");

	rs_snd("     4:Infrared Ray Sensor Circuit \n\n");

	rs_snd("     5:Supersonic Wave Sensor Circuit \n\n");

	rs_snd("     6:Power Distributor/Judgement Unit \n\n");


	rs_snd("     0:End of Test \n\n");

	
	selected_no = NON;
	while ( selected_no == NON && stpflg != ACTIVE ) {
		rs_snd(" Number >> ");
		selected_no = inp();
		if ( selected_no < 0 || MAX_MENU_NO < selected_no ) selected_no = NON; 
	}

	return(selected_no);
}


2.6 マンマシンインタフェースボードの試験(mmi.c)

#include	"tmp_def.h"
#include	"duscc.h"
#include	
#include	

extern void	rs_rcv(),rs_snd();
extern int	inportb(),outportb(),outportl(),yes(),ret();
extern void	skipspace(),wait();

extern char	stpflg,crflg;
extern char	err_msg[],buffer[],led_data[];
extern int	sw_ctr;

void	mmi_init(),led_set();
int	led_chk(),sw_chk();

int	green = 0;
int	red = 0;


void	mmi()
{
	rs_snd("\n **** MMI Board Test **** \n");
	
	rs_snd("\n  MMI board is ready ? \n");
	if ( yes() != 0 ) return;

	mmi_init();

	led_set(0,0);
	led_set(1,0);
	led_set(2,0);
	led_set(3,0);

	/*	[1] Counter Test	*/
	strcpy(err_msg,"\n ---- Check MMI:Counter ---- \n");
	rs_snd("\n [1] Counter Test \n"); 
	outportb(TCR0,0x00);		/*	clear TCR0	*/
	outportl(CPR0,0x01e848);	/*	TOUT = 1Hz	*/
			/*	0x1e848 =   1/2    sec /(1/8MHz) / 32 prescaler	*/
	outportb(TCR0,0x41);		/*	square wave	*/
	rs_snd("\n  Counter CLK is changed to 1 Hz.");
	rs_snd("\n  Watch whether 7seg.LEDs are on in turn.");
	if ( yes() != 0 ) return;
	outportb(TCR0,0x00);		/*	clear TCR0	*/	
	outportl(CPR0,0x00003f);	/*	TOUT = 2kHz	*/
			/*	0x3f  = (1/2000)/2 sec /(1/8MHz) / 32 prescaler	*/
	outportb(TCR0,0x41);		/*	square wave	*/
	rs_snd("\n  Counter CLK is returned to 2 kHz. \n");

	/*	[2] 7seg.LED Test 	*/
	rs_snd("\n [2] 7seg.LED Test \n");
	if ( led_chk(0) != 0 ) return;	/*	7seg.LED(0)	*/
	if ( led_chk(1) != 0 ) return;	/*	7seg.LED(1)	*/
	if ( led_chk(2) != 0 ) return;	/*	7seg.LED(2)	*/
	if ( led_chk(3) != 0 ) return;	/*	7seg.LED(3)	*/	

	/*	[3] Green/Red LED Test	*/
	strcpy(err_msg,"\n ---- Check MMI:Green/Red LED ---- \n");
	rs_snd("\n [3] Green/Red LED Test \n");
	outportb(PADR0,0);				/*	Green->OFF,RED->OFF	*/
	rs_snd("\n  Green LED is off, Red LED is off. ");
	if ( yes() != 0 ) return;
	outportb(PADR0,RED);				/*	Green->OFF,RED->ON	*/
	rs_snd("\n  Green LED is off, Red LED is on. ");
	if ( yes() != 0 ) return;
	outportb(PADR0,GREEN);				/*	Green->ON ,RED->OFF	*/
	rs_snd("\n  Green LED is on, Red LED is off. ");
	if ( yes() != 0 ) return;
	outportb(PADR0,RED+GREEN);			/*	Green->ON ,RED->ON	*/
	rs_snd("\n  Green LED is on, Red LED is on. ");
	if ( yes() != 0 ) return;
	outportb(PADR0,0);				/*	Green->OFF,RED->OFF	*/
	rs_snd("\n  Green LED is off, Red LED is off. ");
	if ( yes() != 0 ) return;

	/*	[4] Switch Read Test	*/
	strcpy(err_msg,"\n ---- Check MMI:Switch ---- \n");
	rs_snd("\n [4] Switch Read Test \n");
	if ( sw_chk(0x00) != 0 ) return;
	if ( sw_chk(0x01) != 0 ) return;
	if ( sw_chk(0x02) != 0 ) return;
	if ( sw_chk(0x04) != 0 ) return;
	if ( sw_chk(0x08) != 0 ) return;
	if ( sw_chk(0x05) != 0 ) return;
	if ( sw_chk(0x0a) != 0 ) return;

	/*	[5] Push Button Test	*/
	strcpy(err_msg,"\n ---- Check MMI:Push Button ---- \n");
	rs_snd("\n [5] Push Button Test \n");
	sw_ctr = 0;
	rs_snd("\n  Push the push button for interrupt.(If there is no responce, hit F1 key for break.)\n");


	outportb(TCR0,0x00);	/*	timer stop	*/
	
	outportb(PBCR0,0x84);	/*	interrupt enable	*/ 
	while ( sw_ctr == 0 && stpflg != ACTIVE );
	outportb(PBCR0,0x80);	/*	interrupt disable	*/ 

	if ( stpflg == ACTIVE ) {
		rs_snd(err_msg);
		return;
	}
	rs_snd("  O.K. \n");

	rs_snd("\n **** MMI Board Test is Complete **** \n");	
}


void	mmi_init()
{
	/*	PI/T 0	*/
	outportb(PGCR0,0x00);	/*	clear PGCR0	*/
	outportb(PSRR0,0x1e);
	outportb(PACR0,0xa0);	/*	submode 1x	*/
	outportb(PADDR0,0xff);	/*	all output	*/
	outportb(PBCR0,0x80);	/*	submode 1x	*/
	outportb(PBDDR0,0x10);
	outportb(PGCR0,0x22);	/*	mode 0		*/
	outportb(TCR0,0x00);	/*	clear TCR0	*/
	outportl(CPR0,0x00003f);	/*	TOUT 2kHz	*/
			/*	0x3f = (1/2000)/2 sec /(1/8MHz) /32 prescaler	*/
	outportb(TCR0,0x41);	/*	square wave	*/

	/*	set vector for switch interrupt	*/
	asm(
"	MOVEA.L		#$06c,A0	* LEVEL 3  PI/T interrupt ",
"	MOVE.L		#_swint,(A0)"
	);
}


void	led_set( led_no, data )
int	led_no,data;
{
	outportb(PADR0,green*0x80+red*0x40+led_no*0x10+data);
	outportb(PACR0,0xa0);
	outportb(PACR0,0xa8);
	outportb(PACR0,0xa0);

	led_data[led_no] = data;
}


int	led_chk( led_no )
int	led_no;
{
	int	c;		/*	number to be displayed	*/

	itoa(led_no,buffer);
	rs_snd("\n  7seg.LED(");
	rs_snd(buffer);
	rs_snd(") is selected. ");
	rs_snd("\n  It varies from '0' to '9' cyclically. ");
	rs_snd("\n  If it is O.K. , hit key 'Y'. >> ");
	c = 0;
	while ( (crflg != ACTIVE) && (stpflg != ACTIVE) ) {
		led_set(led_no,c);
		c++;
		if ( c > 9 ) c = 0;
		wait(LED_WAIT);		/*	turn ON   1,2sec	*/
	}
	crflg = !ACTIVE;
	if ( stpflg == ACTIVE ) return(1);
	rs_rcv(buffer);
	skipspace();
	if ( strcmp(buffer,"y") != 0 && strcmp(buffer,"Y") != 0 ) {
		rs_snd("\n ---- Check MMI:7seg.LED(");
		rs_snd(buffer);
		rs_snd(") ---- \n");
		return(1);
	}
	rs_snd("  O.K. \n");
	return(0);
}


int	sw_chk( data )
int	data;
{
	int	sw_data;	

	itostr((unsigned int)data,buffer,16);
	rs_snd("\n  Set switch ");
	rs_snd(buffer);
	rs_snd("(hex)");
	if ( ret() != 0 ) return(1);
	sw_data = inportb(PBDR0) & 0x0f;
	itostr((unsigned int)sw_data,buffer,16);
	rs_snd("\n  Switch data = ");
	rs_snd(buffer);
	rs_snd("(hex)\n");
	if ( (sw_data & 0x0f) != data ) {	/* switch has 4 bits	*/
		rs_snd(err_msg);
		return(1);
	}
	rs_snd("  O.K. \n");
	return(0);
}


/*	switch interrupt function	*/
interrupt void	swint()
{
	outportb(PSR0,0x08);	/*	clear H4S  (clear interrupt)	*/
	sw_ctr++;		/*	interrupt counter	*/
}


2.7 ロータリエンコーダ・タッチセンサ回路の試験(re_ts.c)

#include	"tmp_def.h"
#include	"duscc.h"
#include	
#include	

extern void	rs_snd();
extern int	inportb(),outportb(),yes(),ret();

extern char	crflg,stpflg,nextflg;
extern char	err_msg[],buffer[];
extern int	ts_ctr;			/*	interrupt counter	*/

void	re_ts_init(),re(),ts();
int	re_ct_chk(),re_rst_chk();

void	re_ts()
{
	int	sel;	/*	target select value	*/

	rs_snd("\n **** Rotary Encoder/ Touch Sensor Board Test **** \n");

	rs_snd("\n  RE/TS board is ready ? \n");
	if ( yes() != 0 ) return;

	re_ts_init();	/*	initialize	*/

	/*	select target function	*/
	sel = NON;
	while ( sel == NON && stpflg != ACTIVE ) {
		rs_snd("\n  Select target.");
		rs_snd("\n  (1) Rotary Encoder (2) Touch Sensor >> ");
		sel = inp();
		if ( sel < 1 || 2 < sel ) sel = NON; 
	}
	switch( sel ) {
	case 1:
		re();
		break;
	case 2:
		ts();
		break;
	default:
		stpflg = ACTIVE;
		break;
	}

	if ( stpflg != ACTIVE )
	rs_snd("\n ****  Rotary Encoder/ Touch Sensor Board Test is Complete **** \n");	
}	


void	re_ts_init()
{
	/*	RE/TS	*/
	outportb(TSIE,0x00);
	outportb(CRST,0x03);	/*	counter reset	*/	

	/*	set vector for interrupt	*/
	asm(
"	MOVEA.L		#$130,A0	*	130(h) = 76(d) * 4",
"	MOVE.L		#_tsint,(A0)"
	);

}


void	re()
{
	/*	[1] Rotary Encoder Count Test	*/
	strcpy(err_msg,"\n ---- Check RE/TS:RE Count Function ---- \n");
	rs_snd("\n [1] Rotary Encoder Count Test \n");
	if ( re_ct_chk() != 0 ) return;
	
	/*	[2] Rotary Encoder Counter Reset Test	*/
	strcpy(err_msg,"\n ---- Check RE/TS:RE Counter Rest Function ---- \n");
	rs_snd("\n [2] Rotary Encoder Counter Reset Test \n");
	if ( re_rst_chk() != 0 ) return;
}


/*	rotary encoder counter test	*/
int	re_ct_chk()
{
	int	old_data_r,old_data_l,new_data_r,new_data_l;
	int	data_rh,data_rl,data_lh,data_ll;
	int	col;
	char	rebuf[20];


	while ( nextflg != ACTIVE && stpflg != ACTIVE ) {
		rs_snd("\n  Hit return key to start counting. ( Hit F2 key for next. ) : ");
		while ( crflg != ACTIVE && nextflg != ACTIVE && stpflg != ACTIVE );
		crflg = !ACTIVE;

		data_rl = inportb(EDRL) & 0xff;
		data_rh = inportb(EDRH) & 0x0f;
		data_ll = inportb(EDLL) & 0xff;
		data_lh = inportb(EDLH) & 0x0f;

		/*	display rotary encoder data(H)  in 4 coloum	*/
		strcpy(buffer,"0000");
		col = itostr((unsigned int)data_rh,rebuf,2);
		itostr((unsigned int)data_rh,buffer+(4-col),2);
		rs_snd("\n Right(High) : ");
		rs_snd(buffer);

		/*	display rotary encoder data(L)  in 8 coloum	*/
		strcpy(buffer,"00000000");
		col = itostr((unsigned int)data_rl,rebuf,2);
		itostr((unsigned int)data_rl,buffer+(8-col),2);
		rs_snd("\n Right(Low)  : ");
		rs_snd(buffer);

		/*	display rotary encoder data(H)  in 4 coloum	*/
		strcpy(buffer,"0000");
		col = itostr((unsigned int)data_lh,rebuf,2);
		itostr((unsigned int)data_lh,buffer+(4-col),2);
		rs_snd("\n Left(High)  : ");
		rs_snd(buffer);

		/*	display rotary encoder data(L)  in 8 coloum	*/
		strcpy(buffer,"00000000");
		col = itostr((unsigned int)data_ll,rebuf,2);
		itostr((unsigned int)data_ll,buffer+(8-col),2);
		rs_snd("\n Left(Low)   : ");
		rs_snd(buffer);				

		old_data_r = ( data_rh << 8 ) + data_rl;
		if ((old_data_r & 0x800) != 0)			/*	if data is minus	*/
			old_data_r = (old_data_r | 0xfffff000);
		old_data_l = ( data_lh << 8 ) + data_ll;
		if ((old_data_l & 0x800) != 0)			/*	if data is minus	*/
			old_data_l = (old_data_l | 0xfffff000);

		/*	display old data  in decimal	*/
		rs_snd("\n    Right Count (Old) : ");
		itoa(old_data_r,buffer);
		rs_snd(buffer);
		rs_snd("\n    Left Count (Old)  : ");
		itoa(old_data_l,buffer);
		rs_snd(buffer);

		rs_snd("\n\n  Hit return key to stop counting. ( Hit F2 key for next. ) : ");
		while ( crflg != ACTIVE && nextflg != ACTIVE && stpflg != ACTIVE );
		crflg = !ACTIVE;

		data_rl = inportb(EDRL) & 0xff;
		data_rh = inportb(EDRH) & 0x0f;
		data_ll = inportb(EDLL) & 0xff;
		data_lh = inportb(EDLH) & 0x0f;

		new_data_r = ( data_rh << 8 ) + data_rl;
		if ((new_data_r & 0x800) != 0)			/*	if data is minus	*/
			new_data_r = (new_data_r | 0xfffff000);
		new_data_l = ( data_lh << 8 ) + data_ll;
		if ((new_data_l & 0x800) != 0)			/*	if data is minus	*/
			new_data_l = (new_data_l | 0xfffff000);

		/*	display new data  in decimal	*/
		rs_snd("\n    Right Count (New) : ");
		itoa(new_data_r,buffer);
		rs_snd(buffer);
		rs_snd("\n    Left Count (New)  : ");
		itoa(new_data_l,buffer);
		rs_snd(buffer);

		/*	display count difference	*/
		rs_snd("\n\n  [ Count Difference ]");
		rs_snd("\n    Right : ");
		itoa(new_data_r-old_data_r,buffer);
		rs_snd(buffer);
		rs_snd("\n    Left  : ");
		itoa(new_data_l-old_data_l,buffer);
		rs_snd(buffer);
	}
	nextflg = crflg = !ACTIVE;	/*	clear next-flag & CR-flag	*/
	if ( stpflg == ACTIVE ) {
			rs_snd(err_msg);
			return(1);
	}
	rs_snd("  O.K. \n");
	return(0); 
}


int	re_rst_chk()
{
	int	mode,data_r,data_l;

	while ( nextflg != ACTIVE && stpflg != ACTIVE ) {

		/*	mode select	*/
		mode = NON;
		while ( mode == NON && nextflg != ACTIVE && stpflg != ACTIVE) {
			rs_snd("\n  Select reset mode. ( Hit F2 key to return. ) ");
			rs_snd("\n  (1)Right (2)Left (3)Both  >> ");
			mode = inp();
			if ( mode < 1 || 3 < mode ) mode = NON; 
		}

		/*	reset counter	*/
		outportb(CRST,mode);	

		/*	get data	*/
		data_r = ( (inportb(EDRH) & 0x0f)<<8 ) + inportb(EDRL);
		data_l = ( (inportb(EDLH) & 0x0f)<<8 ) + inportb(EDLL);

		/*	display data	*/
		rs_snd("\n    Right Count : ");
		itoa(data_r,buffer);
		rs_snd(buffer);
		rs_snd("\n    Left Count  : ");
		itoa(data_l,buffer);
		rs_snd(buffer);
	}
	nextflg = crflg = !ACTIVE;	/*	clear next-flag & CR-flag	*/
	if ( stpflg == ACTIVE ) {
		rs_snd(err_msg);
		return(1);
	} 

	rs_snd("\n  O.K.");
	return(0);
}

void	ts()
{
	int	data;

	/*	[3] Touch Sensor Sense Test	*/
	strcpy(err_msg,"\n ---- Check RE/TS:Touch Sensor ---- \n");
	rs_snd("\n [3] Touch Sensor Sense Test \n");
	while ( nextflg != ACTIVE && stpflg != ACTIVE ) {
		rs_snd("\n  Hit return key to scan touch senseor states. ( Hit F2 key for next. ) : ");
		while ( crflg != ACTIVE && nextflg != ACTIVE && stpflg != ACTIVE );
		crflg = !ACTIVE;
		data = inportb(EDRH);				/*	get touch sensor data	*/
		if ( (data & 0x80) != 0x00 ) rs_snd("\n  [SF] : ON ");
		else rs_snd("\n  [SF] : OFF ");
		if ( (data & 0x40) != 0x00 ) rs_snd("\n  [L]  : ON ");
		else rs_snd("\n  [L]  : OFF ");
		if ( (data & 0x20) != 0x00 ) rs_snd("\n  [R]  : ON ");
		else rs_snd("\n  [R]  : OFF ");
		if ( (data & 0x10) != 0x00 ) rs_snd("\n  [M]  : ON ");
		else rs_snd("\n  [M]  : OFF ");
	}
	nextflg = !ACTIVE;
	if ( stpflg == ACTIVE ) {
			rs_snd(err_msg);
			return;
	}
	rs_snd("\n  O.K. \n");
	
	/*	[4] Touch Sensor Interrupt Test	*/
	strcpy(err_msg,"\n ---- Check RE/TS:TS Interrupt Function ---- \n");
	rs_snd("\n [4] Touch Sensor Interrupt Test \n");
	ts_ctr = 0;
	rs_snd("\n  Touch one of touch sensors for interrupt.(If there is no response, hit F1 key for break.)\n");

	outportb(TSIE,0x01);	/*	interrupt enable	*/
	outportb(VIMR,0x10);	/*	VME IRQ4  enable	*/

	while ( ts_ctr == 0 && stpflg != ACTIVE );

	outportb(VIMR,0x00);	/*	VME IRQ   disable	*/
	outportb(TSIE,0x00);	/*	interrupt disable	*/
	if ( stpflg == ACTIVE ) {
		rs_snd(err_msg);
		return;
	}

	rs_snd("  O.K. \n");
}

/*	touch sensor interrupt function	*/
interrupt void	tsint()
{
	ts_ctr++;	/*	interrupt counter	*/
}


2.8 PWM回路の試験(pwm.c)

#include	"tmp_def.h"
#include	"duscc.h"
#include	
#include	

extern void	rs_snd();
extern int	outportb(),yes(),ret(),inp();

extern char	getbuf[],*end_get,stpflg,crflg,nextflg;
extern char	err_msg[],buffer[];

void	pwm_init();
int	duty_set(),switching();


void	pwm()
{	
	rs_snd("\n **** PWM Circuit Test **** \n");
	
	rs_snd("\n  IO Sub board (PWM circuit) is ready ? \n");
	if ( yes() != 0 ) return;
	
	pwm_init();

	/*	[1] Speed Change Test	*/
	strcpy(err_msg,"\n ---- Check PWM:Speed Change Function ---- \n");
	rs_snd("\n [1] Counter Test \n");
	outportb(PADR1,STPWHL);			/*	stop	wheels	*/
	outportb(PBDR1,STPWHL);
	rs_snd("\n  Set a tachometer to right wheel. \n");
	if ( ret() != 0 ) return;
	if ( duty_set(PADR1) != 0 ) return;
	rs_snd("\n  Set a tachometer to left wheel. \n");
	if ( ret() != 0 ) return;
	if ( duty_set(PBDR1) != 0 ) return;
	rs_snd("  O.K. \n");

	/*	[2] CW/CCW Switching Test	*/
 	strcpy(err_msg,"\n ---- Check PWM:CW/CCW Switching Function ---- \n");
	rs_snd("\n [2] CW/CCW Switching Test \n");
	rs_snd("\n  Right wheel test: \n");
	if ( ret() != 0 ) return;
	if ( switching(PADR1) != 0 ) return;
	rs_snd("\n  Left while test: \n");
	if ( ret() != 0 ) return;
	if ( switching(PBDR1) != 0 ) return;

	rs_snd("\n **** PWM Circuit Test is Complete **** \n");
}


void	pwm_init()
{
	/*	PI/T 1	*/
	outportb(PGCR1,0x00);	/*	clear PGCR1	*/
	outportb(PSRR1,0x00);
	outportb(PACR1,0x80);	/*	submode 1x	*/
	outportb(PADDR1,0xff);	/*	all output	*/
	outportb(PBCR1,0x80);	/*	submode 1x	*/
	outportb(PBDDR1,0xff);	/*	all output	*/
	outportb(PGCR1,0x00);	/*	mode 0		*/
	outportb(TCR1,0x00);	/*	clear TCR1	*/
	outportl(CPR1,0x000001);/*	TOUT 125kHz	*/
			/* 0x01 = (1/125kHz)/2 /(1/8MHz)/32 prescaler	*/
	outportb(TCR1,0x41);	/*	square wave	*/
}


int	duty_set( port )
char	*port;
{
	int	duty;

	outportb(port,STPWHL);	/*	stop wheel	*/
	while ( nextflg != ACTIVE && stpflg != ACTIVE ) {
		duty = NON;
		while ( duty == NON && nextflg != ACTIVE && stpflg != ACTIVE ) {
			rs_snd("\n  Input Duty Rate [0-100] ( Hit F2 key for next )  >> ");
			duty = inp();
			if ( duty <0 || duty > 100 ) duty = NON;
		}
		outportb(port,(duty * D_MAX /100)<<1);
		itoa(duty,buffer);
		rs_snd("  Duty rate : ");
		rs_snd(buffer);
	}
	nextflg = !ACTIVE;
	if ( stpflg == ACTIVE ) {
		rs_snd(err_msg);
		return(1);
	}
	rs_snd("  O.K. \n");
	outportb(port,STPWHL);	/*	stop wheel	*/
	return(0);
}


int	switching( port )
char	*port;
{
	char	dir;	
 
	dir = CW;
	outportb(port,(LOWSPD<<1) + dir);
	while( nextflg != ACTIVE && stpflg != ACTIVE ) {
		rs_snd("  Hit return key for switching.( Hit F2 key for next.) ");
		while ( crflg != ACTIVE && nextflg != ACTIVE && stpflg != ACTIVE );
		crflg = !ACTIVE;

		if ( nextflg != ACTIVE && stpflg != ACTIVE ) {
			dir = 1-dir;
			outportb(port,(LOWSPD<<1) + dir);
		}
	}
	nextflg = !ACTIVE;
	if ( stpflg == ACTIVE ) {
		rs_snd(err_msg);
		return(1);
	}
	rs_snd("  O.K. \n");
	outportb(port,STPWHL);	/*	stop wheel	*/
	return(0);
}


2.9 赤外線センサ回路の試験(ps.c)

#include	
#include	
#include	"tmp_def.h"
#include	"duscc.h"

extern void	rs_snd();
extern int	inportb(),outportb(),yes();

extern char	crflg,stpflg,nextflg;
extern char	err_msg[],buffer[];
extern int	ps_ctr;
extern int	ps_data;

void	ps_init();
int	ps_sense();


void	ps()
{
	char	psbuf[20];
	int	col;


	rs_snd("\n **** Photo Sensor Circuit Test **** \n");

	rs_snd("\n  IO Sub board (photo sensor circuit) is ready ? \n");
	if ( yes() != 0 ) return;

	ps_init();

	/*	[1] Photo Sensor Sense Test	*/
	strcpy(err_msg,"\n ---- Check PS:Photo Sense Function ---- \n");
	rs_snd("\n [1] Photo Sensor Sense Test \n");
	if ( ps_sense() != 0 ) return;

	/*	[2] Photo Sensor Interrupt Test	*/
	strcpy(err_msg,"\n ---- Check PS:PS Interrupt Function ---- \n");
	rs_snd("\n [2] Photo Sensor Interrupt Test \n");
	ps_ctr = 0;
	rs_snd("\n  Take lights to photo sensor for interrupt.(If there is no response, hit F1 key for break.)\n");
	outportb(PSR2,0x0f);	/*	HnS Clear		*/
	outportb(PBCR2,0x32);	/*	interrupt enable	*/
	outportb(VIMR,0x02);	/*	VME IRQ1  enable	*/


	while ( ps_ctr == 0 && stpflg != ACTIVE );

	outportb(VIMR,0x00);	/*	VME IRQ   disable	*/
	outportb(PBCR2,0x30);	/*	interrupt disable	*/

	if ( stpflg == ACTIVE ) {
		rs_snd(err_msg);
		return;
	}
	outportb(TCR1,0x00);	/*	PI/T(X)TOUT stop	*/

	/*	display sensor data  in 8 coloum	*/
	strcpy(buffer,"00000000");
	col = itostr( (unsigned int)ps_data, psbuf, 2);
	itostr( (unsigned int)ps_data, buffer+(8-col), 2 );
	rs_snd("\ndata =");
	rs_snd(buffer);
	rs_snd("\n");

	rs_snd("  O.K. \n");

	rs_snd("\n ****  Photo Sensor Circuit Test is Complete **** \n");
}


void	ps_init()
{
	/*	PI/T 1	*/
	outportb(TCR1,0x00);	/*	clear TCR1	*/
	outportl(CPR1,0x000001);/*	TOUT 125kHz	*/
			/*	0x01 = (1/125kHz)/2 /(1/8MHz)/32 prescaler	*/
	outportb(TCR1,0x41);	/*	square wave	*/


	/*	PI/T 2	*/
	outportb(PGCR2,0x00);	/*	clear PGCR2	*/
	outportb(PSRR2,0x1c);
	outportb(PBCR2,0x30);	/*	submode 00	*/
	outportb(PBDDR2,0x00);	/*	all input	*/
	outportb(PGCR2,0x28);	/*	mode 0	,H3 enable	*/

	/*	set vector for interrupt	*/
	asm(
"	MOVEA.L		#$128,A0	*	128(h) = (72+2)(d) * 4",
"	MOVE.L		#_psint,(A0)"
	);
	outportb(PIVR2,72+2 );	/*	infrared ray sensor interrupt causes by H3	*/
}


int	ps_sense()
{
	int	i;

	while ( nextflg != ACTIVE && stpflg != ACTIVE ) {
		rs_snd("\n  Hit return key to watch photo sensor data. ( Hit F2 key for next. ) : ");
		while ( crflg != ACTIVE && nextflg != ACTIVE && stpflg != ACTIVE );
		crflg = !ACTIVE;
		ps_data = inportb(PBDR2);
		rs_snd("\n  Photo Sensor Data : ");
		for ( i= 7 ; i >= 0 ; i-- ) {
			rs_snd("\n  [");
			itoa(i,buffer);
			rs_snd(buffer);
			rs_snd("] : ");
			if ( (ps_data & (0x01 << i)) != 0 ) rs_snd("ON ");
			else rs_snd("OFF ");
		}
	}
	nextflg = !ACTIVE;
	if ( stpflg == ACTIVE ) {
			rs_snd(err_msg);
			return(1);
	}
	rs_snd("  O.K. \n");
	return(0); 
}


/*	infrared ray sensor interrupt	*/
interrupt void	psint()
{
	outportb(PSR2,0x04);			/*	clear H3S	*/
	ps_data = (inportb(PBDR2) & 0xff);	/*	sensor data	*/
	ps_ctr++;				/*	interrupt counter */
}


2.10 超音波センサ回路の試験(sss.c)

#include	
#include	
#include	"tmp_def.h"
#include	"duscc.h"

extern void	rs_snd();
extern int	inportb(),outportb(),yes(),ret();

extern char	crflg,stpflg,nextflg;
extern char	err_msg[],buffer[];
extern int	sss_ctr;		/*	interrupt counter	*/

void	sss_init();
int	sss_sel();

double	dist;		/*	distance measured by supersonic wave sensor	*/
int	h,m,l;		/*	High,Middle,Low byte of  ss sensor data		*/
int	int_sss_no;		/*	ss sensor number for interrupt			*/

void	sss()
{
	int	sss_no,	/*	ss sensor number		*/
		underflg;	/*	underflow flag		*/


	rs_snd("\n **** Supersonic Wave Sensor Circuit Test **** \n");

	rs_snd("\n  IO Sub board (supersonic wave sensor circuit) is ready ? \n");
	if ( yes() != 0 ) return;

	sss_init();

	/*	[1] SSS	Select Signal Check	*/
	strcpy(err_msg,"\n ---- Check SSS:SSS Select Function ---- \n");
	rs_snd("\n [1] SSS Select Signal Check \n");
	rs_snd("\n  Set logic analizer. %% \n");
	if ( ret() != 0 ) return;

	for (sss_no=0; sss_no< SSS_MAX; sss_no++)
		if ( sss_sel(sss_no,0) != 0 ){
			rs_snd(err_msg);
			return;
		}

	/*	[2] SSS Send Test	*/
	strcpy(err_msg,"\n ---- Check SSS:SSS Send Circuit ---- \n");
	rs_snd("\n [2] SSS Send Test \n");
	rs_snd("\n  Conect supersonic wave sensor send circuit. \n");
	if ( ret() != 0 ) return;

	for (sss_no=0; sss_no< SSS_MAX; sss_no++)
		if ( sss_sel(sss_no,1) != 0 ){
			rs_snd(err_msg);
			return;
		}

	/*	[3] SSS Receive Test	*/
	strcpy(err_msg,"\n ---- Check SSS:SSS Receive Circuit ---- \n");
	rs_snd("\n [3] SSS Receive Test \n");
	rs_snd("\n  Set horns for test. Set logic analizer. %% \n");
	if ( ret() != 0 ) return;

	for (sss_no=0; sss_no< SSS_MAX; sss_no++)
		if ( sss_sel(sss_no,0) != 0 ){
			rs_snd(err_msg);
			return;
		}


	/*	[4] SSS Interrupt Test	*/
	strcpy(err_msg,"\n ---- Check SSS:SSS Interrupt Function ---- \n");
	rs_snd("\n [4] SSS Interrupt Test \n");
	rs_snd("\n  Set the horn, and input the sensor number >> ");

	/*	select sensor	*/
	int_sss_no = NON;
	while ( int_sss_no == NON && nextflg != ACTIVE && stpflg != ACTIVE ) {
		int_sss_no = inp();
		if ( int_sss_no < 0 || SSS_MAX < int_sss_no ) int_sss_no = NON;
	}
	nextflg != ACTIVE;
	if ( ret() != 0 ) return;

	sss_ctr = 0;	/*	clear interrupt counter	*/
	underflg = 0;	/*	clear underflow-flag	*/

	outportb(PACR2,0x7b);	/*	interrupt enable	*/
	outportb(TCR2,0xb3);	/*	Timer enable	*/
	outportb(VIMR,0x02);	/*	VME IRQ1  enable	*/

	while ( sss_ctr < 2 &&  stpflg != ACTIVE &&  underflg == 0 )
		underflg = inportb(PADR2) & 0x04;

	outportb(TCR2,0xb2);	/*	Timer disable	*/
	outportb(VIMR,0x00);	/*	VME IRQ   disable	*/
	outportb(PACR2,0x79);	/*	interrupt disable	*/

	/*	get sss data	*/
	h = inportb(CNTR2 +2) & 0xff;
	m = inportb(CNTR2 +4) & 0xff;
	l = inportb(CNTR2 +6) & 0xff;
	dist = (SSS_LIMIT - ( (h<<16) + (m<<8) +l ) ) * 32/(double)8000000 * 340 /2;
	/*	count difference * (1/8MHz) * 32 prescaler * 340 m/s /2 (go & return)	*/

	/*	display sss data	*/
	itostr( (unsigned int)(dist*100),buffer,10);
	rs_snd("\n distance :");
	rs_snd(buffer);
	rs_snd(" cm.\n");

	if ( stpflg == ACTIVE ) {
		rs_snd("\n STOP \n");
		rs_snd(err_msg);
		return;
	}

	underflg = inportb(PADR2) & 0x04;
	if ( underflg != 0 ) {
		rs_snd("\n  Underflow. \n");
		rs_snd(err_msg);
		return;
	}
	rs_snd("  O.K. \n");

	/*	[5] SSS Underflow Test	*/
	strcpy(err_msg,"\n ---- Check SSS:SSS Underflow Function ---- \n");
	rs_snd("\n [5] SSS Underflow Test \n");
	rs_snd("\n  Input the sensor number >> ");

	/*	select sensor	*/
	int_sss_no = NON;
	while ( int_sss_no == NON && nextflg != ACTIVE && stpflg != ACTIVE ) {
		int_sss_no = inp();
		if ( int_sss_no < 0 || SSS_MAX < int_sss_no ) int_sss_no = NON;
	}
	nextflg != ACTIVE;
	if ( ret() != 0 ) return;

	sss_ctr = 0;	/*	clear interrupt counter	*/
	underflg = 0;	/*	clear underflow-flag	*/

	outportb(PACR2,0x7b);	/*	interrupt enable	*/
	outportb(TCR2,0xb3);	/*	Timer enable	*/
	outportb(VIMR,0x02);	/*	VME IRQ1  enable	*/

	while ( sss_ctr < 2 &&  stpflg != ACTIVE &&  underflg == 0 )
		underflg = inportb(PADR2) & 0x04;

	outportb(TCR2,0xb2);	/*	Timer disable	*/
	outportb(VIMR,0x00);	/*	VME IRQ   disable	*/
	outportb(PACR2,0x79);	/*	interrupt disable	*/

	if ( stpflg == ACTIVE ) return;
	if ( underflg == 0 ) {
		rs_snd("\n  Not underflow. \n");
		rs_snd(err_msg);
		return;
	}
	rs_snd("  O.K. \n");
}


void	sss_init()
{
	/*	PI/T 2	*/
	outportb(PGCR2,0x08);	/*	mode 0		*/
	outportb(PSRR2,0x1c);
	outportb(PACR2,0x79);	/*	submode 01	*/
	outportb(PADDR2,0x03);
	outportb(PGCR2,0x18);	/*	mode 0		*/
	outportb(TCR2,0x00);	/*	clear	TCR2	*/
	outportl(CPR2,SSS_LIMIT);	/*	count for ss-wave to go & return 3 meter	*/
	outportb(TCR2,0xb2);	/*	device watchdog		*/

	/*	set vector for interrupt	*/
	asm(
"	MOVEA.L		#$120,A0	*	120(h) = 72(d) * 4 ",
"	MOVE.L		#_sssint,(A0)"
	);

	outportb(PIVR2,72+0);	/*	sss interrupt causes by H1	*/
}


int	sss_sel( sss_no, mode )
int	sss_no;
int	mode;
{
	rs_snd("\n  Supersonic Sensor No.");
	itoa(sss_no,buffer);
	rs_snd(buffer);
	rs_snd(" is selected.");
	rs_snd("\n  Hit return key to start. ( Hit F2 key for next. ) : ");

	nextflg = crflg = !ACTIVE;
	while ( crflg != ACTIVE && nextflg != ACTIVE && stpflg != ACTIVE );
	crflg = !ACTIVE;
	if (nextflg == ACTIVE){
		nextflg = crflg = !ACTIVE;
		return(0);
	}

	switch ( mode ) {
		case 0:			/*	Test [1],[3]	*/
			rs_snd(" Check the signals. \n");
			break;
		case 1:			/*	Test [2]	*/
			rs_snd(" Listen to the selected sensor.\n");
			break;
		default:
			stpflg = ACTIVE;
			break;
	}
	outportb(PADR2,sss_no);		/*	send signal	*/
	if ( yes() != 0 ) return(1);
	return(0);
}


/*	supersonic wave sensor function	*/
interrupt void	sssint()
{

	switch(sss_ctr){
		case	0:			/*	when enable interrupt	*/
			outportb(PADR2,int_sss_no);
			break;

		case	1:			/*	when real first interrupt causes	*/
			outportb(VIMR,0x00);	/*	VME IRQ   disable	*/
			outportb(PACR2,0x79);	/*	interrupt disable	*/
			break;

		default:
			break;
	}
	sss_ctr++;
}


2.11 電源・勝敗判定装置の試験(pow.c)

#include	"tmp_def.h"
#include	"duscc.h"
#include	

extern void	rs_snd();
extern int	inportb(),outportb(),yes(),ret();

extern char	err_msg[];

void	pow_init();


void	pow()
{
	rs_snd("\n **** Power Distributor/Judgement Unit Test **** \n");

	rs_snd("\n  Power Distributor and Judgement Unit are ready ? \n");
	if ( yes() != 0 ) return;

	pow_init();

	/*	[1] Judgement Switch Test	*/
	strcpy(err_msg,"\n ---- Check POW:Judgement Switch ---- \n");
	rs_snd("\n [1] Judgement Switch Test \n");
	if ( (inportb(PBDR0) & 0x40) == 0 ) {
		rs_snd("\n  Push start switch. \n");
		if ( ret() != 0 ) return;
	}
	rs_snd("\n  Now system is active. Push judgement switch. \n");
	if ( ret() != 0 ) return;
	if ( (inportb(PBDR0) & 0x40) != 0 ) {
		rs_snd("\n  System is still active. \n");
		rs_snd(err_msg);
		return;
	}
	rs_snd("\n  System is inactive. O.K. \n");

	rs_snd("\n **** Power Distributor/Judgement Unit Test is Complete **** \n");	 
}


void	pow_init()
{
	/*	PI/T 0	*/
	outportb(PGCR0,0x00);	/*	clear PGCR0	*/
	outportb(PSRR0,0x1e);
	outportb(PACR0,0x79);	/*	submode 01	*/
	outportb(PADDR0,0xff);	/*	all output	*/
	outportb(PBCR0,0x80);	/*	submode 1x	*/
	outportb(PBDDR0,0x20);
	outportb(PGCR0,0x12);	/*	mode 0		*/
}


2.12 下位関数群(tmp_sub.c)

#include	
#include	
#include	"tmp_def.h"
#include	"duscc.h"

extern void	rs_rcv(),rs_snd();

extern char	getbuf[],*end_get,stpflg,crflg,nextflg;
extern char	err_msg[],buffer[];

int	inportb(),outportb(),inportl(),outportl(),yes(),ret(),inp();
void	skipspace(),wait();


/*	port input	Byte	*/
int	inportb( port )
char	*port;
{
	return((int)*port);
}


/*	port output	Byte	*/
int	outportb( port, data )
char	*port;
int	data;
{
	return(*port = data);
}


/*	port input	Long word	*/
int	inportl( port )
char	*port;
{
	int data;
	unsigned char hbyte,mbyte,lbyte;

	hbyte = *(port+0x02);
	mbyte = *(port+0x04);
	lbyte = *(port+0x06);

	data = (int)(hbyte*0x010000+mbyte*0x000100+lbyte);

	return( data );
}

	
/*	port output	Long word	*/
int	outportl( port, data )
char	*port;
int	data;
{
	unsigned char hbyte,mbyte,lbyte;

	hbyte = (unsigned char)((data & 0xff0000)>>16);
	mbyte = (unsigned char)((data & 0x00ff00)>> 8);
	lbyte = (unsigned char) (data & 0x0000ff);

	*(port+0x02) = hbyte;
	*(port+0x04) = mbyte;
	*(port+0x06) = lbyte;

	return( data );
}


/*	delete  spaces before string	*/
void	skipspace()
{
	char *p;

	p = buffer;
	while ( *p != NULL && isspace(*p) != 0 ) p++;
	strcpy(buffer,p);
}


void	wait( time )
int	time;
{
	int i;

	for ( i=0 ; i


3.メイクファイル(tmp.mak)

TARGET = tmp
OBJS= c_entry.o tmp.o menu.o mmi.o pow.o ps.o pwm.o re_ts.o sss.o tmp_sub.o
CMDFILE=tmp.cmd
MCCOPT=-c -g -Gm -nKc -nQ

$(TARGET).x: $(OBJS);
	lnk68k -M -c $(CMDFILE) -o $(TARGET).x
.c.o:
	mcc68k $(MCCOPT) $<
.s.o:
	mcc68k $(MCCOPT) $<


4.コマンドファイル(tmp.cmd)

*
*	command file for lnk68k
*
*		generate absolute-file  for ICE debugging.
*
*				Mar. 9, 1995
*				written by vpro94

debug_symbols			;list p ( not supported command )
listabs publics			;list d (	"		)
listabs internal		;list s (	"		)
listmap crossref		;list c (	"		)
listmap internal		;list t (	"		)
listmap publics			;list x (	"		)

order	code,const

* Sections in ROM
*
sect 	code =		$0F00000    	;Code Section Begin Adrs.
sect	??INITDATA=	$0F04000	;Initialize data for variables
sect	strings =	$0F04200	;String Section Adrs.

* Sections in RAM
*
sect	vars =		$4000		;Initialized    Data Section Adrs.
sect	zerovars =	$6000		;Un-initialized Data Section Adrs.

public	????STACKTOP = $4000 	;Top of the Stack Area

initdata	vars

load 	c_entry.o
load	tmp.o
load	menu.o
load	mmi.o
load	pow.o
load	ps.o
load	pwm.o
load	re_ts.o
load	sss.o

load    tmp_sub.o

load	/usr/mri/lib/mcc68kab.lib


end


'94MIRS V-Project仕様書体系へ戻る