PROGRAM ACCESS FOR DIFFERENT PROGRAMMING LANGUAGES UNDER MS-DOS. _________________________________________________________________ - Data write to LPT port **************************** Turbo Pascal 7.0 ------------------ Uses Dos; Var addr:word; data:byte; e:integer; Begin addr:=MemW[$0040:$0008]; Val(ParamStr(1),data,e); Port[addr]:=data; End. For determination of port address there is used representation for BIOS, where addr:=MemW[$0040:$0008] presents LPT1 abd address addr:=MemW[$0040:$000A] presents LPT2 port. Assembler: ---------------------- MOV DX,0378H MOV AL,n OUT DX,AL where n means transmitted data (byte) to LPT1 port (0x378). BASIC: ---------------------- OUT &H378, N where n means transmitted data (byte) to LPT1 port (0x378). Programovací jazyk C: ---------------------- outp(0x378,n); nebo outportb(0x378,n); where n means transmitted data (byte) to LPT1 port (0x378). For C language is necessery to write a declaration of variables and libraries. Following example is for Borland C++ 3.1 compiler. #include #include #include /********************************************/ /*This program set the parallel port outputs*/ /********************************************/ void main (void) { clrscr(); /* clear screen */ outportb(0x378,0xff); /* output the data to parallel port */ getch(); /* wait for keypress before exiting */ } FOR CONTROL OF LPT PORT UNDER OS LINUX AND PROGRAMMING LANGUAGE C //////////////////////////////////////////////////// #include #include #include #include #define base 0x378 /* printer port base address */ #define value 255 /* numeric value to send to printer port */ main(int argc, char **argv) { if (ioperm(base,1,1)) fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1); outb(value, base); } If this source code is saved for example into file lpt_test.c, it can be compile by command: gcc -O lpt_test.c -o lpt_test --------------------------------------------------------------------- - Data read from LPT port **************************** Assembler: ----------------------------------- MOV DX,0379H IN AL,DX Resulting value of the register is in accumulator AL. BASIC: ------------------------------------ N = INP(&H379); where N je the resulting read value from register. Programovac jazyk C: ------------------------------------- in = inportb(0x379); nebo in = inp(0x379); where N je the resulting read value. Variable declaration can be achieved in according to previous presented program for value listing for Borland C++ 3.1 compiler.