/*----------------------------------------------------------------------*/
/* filename=demo_01.c							*/
/* signal								*/
/*									*/
/* 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 */
int DO1,DO2,DO3,DI1,DI2,DI3;	/* PORT C <--> PORT F */

outportb(BASE+3,0x80);		/* PORT A,B,C =  output port */
outportb(BASE+7,0x9B);		/* PORT D,E,F =  input	port */

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

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

