/*----------------------------------------------------------------------*/
/* filename=demo_02.c							*/
/*									*/
/* test the input/output port						      */
/* IO BASE address = 0x2C0, DIP=101100 : in ON position=0		*/
/*----------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>

#define  BASE 0x2C0	/* IO BASE address = 0x2C0 */

void main( void )	/* PORT A <--> PORT D */
{			/* PORT B <--> PORT E */
			/* PORT C <--> PORT F */

int DO1,DO2,DO3,DO4,DI1,DI2,DI3,DI4,t,tt;

outportb(BASE+3,0x83);	/* PORT A,C_UPPER =  output port */
			/* PORT B,C_LOWER =  input  port */
outportb(BASE+7,0x98);	/* PORT D,F_UPPER =  input  port */
			/* PORT E,F_LOWER =  output port */

DO1=0;
for (;;)
	{
	DO2=DO1&0x0f; t=DO2<<4;
	DO3=DO1;
	DO4=DO1&0x0f;
	outportb(BASE  ,DO1);	/* send a value to PORT_A	*/
	outportb(BASE+2,t  );	/* send a value to PORT_C_UPPER */
	outportb(BASE+5,DO3);	/* send a value to PORT_E	*/
	outportb(BASE+6,DO4);	/* send a value to PORT_F_LOWER */
	printf("\nDEMO_01.EXE --> DO=[%x,%x,%x,%x]",DO1,DO2,DO3,DO4);
	DI1=inportb(BASE+1)&0xff;	/* read from PORT_B	  */
	DI2=inportb(BASE+2)&0x0f;	/* read from PORT_C_LOWER */
	DI3=inportb(BASE+4)&0xff;	/* read from PORT_D	  */
	t  =inportb(BASE+6)&0xf0;	/* read from PORT_F_UPPER */
	DI4=t>>4;
	printf(" , DI=[%x,%x,%x,%x], press any key to stop",DI1,DI2,DI3,DI4);

	delay(100);		/* delay 0.1 second */
	if (kbhit()!=0) {getch(); return;}
	DO1++;			/* UP counter */
	DO1=DO1&0xff;		/* 8 bit counter */
	}
}

