5.5 DEMO2
/* ---------------------------------------------------------------------------------- */
/* DEMO2: D/I/O demo for PIO-DA16/8/4 */
/* Step 1: Connect CON1 & CON2 with a 20-pin 1 to 1 flot cable */
/* Step 2: Run DEMO2.EXE under DOS */
/* --------------------------------------------------------------------------------- */
#include "PIO.H"
void pio_da16_di(WORD *wDi);
void pio_da16_do(WORD wDo);
WORD wBase,wIrq;
int main()
{
int i,j,k;
WORD wBoards,wRetVal,t1,t2,t3,t4,t5,t6;
WORD wSubVendor,wSubDevice,wSubAux,wSlotBus,wSlotDevice;
clrscr();
/* Step 1: find address-mapping of PIO/PISO cards */
.
.
/* Step 2: enable all D/I/O port */
outportb(wBase,1);
/* /RESET -> 1 */
printf("\n\n(2) DEMO2 D/I/O test");
j=1;
for(;;)
{
pio_da16_do(j);
pio_da16_di(&k);
gotoxy(1,9);
printf("DO = %4x , DI = %4x",j,k);
if (k!=j) printf(" <-- Test Error ");
else printf(" <-- Test Ok ");
j++; j=j&0x0ffff;if (j==0) j=1;
if (kbhit()!=0) break;
}
PIO_DriverClose();
}
/* ------------------------------------------------------------------------------ */
void pio_da16_di(WORD *wDi)
{
int in_l,in_h;
in_l=inportb(wBase+0xe0)&0x0ff;
in_h=inportb(wBase+0xe4)&0x0ff;
(*wDi)=(in_h<<8)+in_l;
}
/* ----------------------------------------------------------------------------- */
void pio_da16_do(WORD wDo)
{
outportb(wBase+0xf8,wDo);
/* 0xf8 : low byte of DO port */
outportb(wBase+0xfc,(wDo>>8));
/* 0xfc : high byte of DO port */
}
PIO-DA/PISO-DA Series User Manual (Ver.2.9, Feb. 2011, PMH-009-29 )
63