Here are the error messages for outportb and inportb:
C:\WINDOWS\TEMP\cc5871771.o(.text+0x3e):printer.c: undefined reference to
`outpo
rtb'
C:\WINDOWS\TEMP\cc5871771.o(.text+0x66):printer.c: undefined reference to
`outpo
rtb'
C:\WINDOWS\TEMP\cc5871771.o(.text+0x73):printer.c: undefined reference to
`inpor
tb'
C:\WINDOWS\TEMP\cc5871771.o(.text+0xca):printer.c: undefined reference to
`outpo
rtb'
C:\WINDOWS\TEMP\cc5871771.o(.text+0xd9):printer.c: undefined reference to
`outpo
rtb'
C:\WINDOWS\TEMP\cc5871771.o(.text+0xe8):printer.c: undefined reference to
`outpo
rtb'
And the program in question (note it is meant to be instructional):
/* This method of printer control is much more difficult that just
fprintf-ing
* text to it. If you need to control the printer port for custom devices
or
* the stdprn stream doesn't work with your compiler, this is the way to go.
*
* This code assumes you are using LPT1; if not, change the "LPT1"s in
main()
* to "LPT2"s.
*
* The LPT #defines are not necessarily portable to anything less than an
AT;
* if you want portable code and are a better programmer than I you should
* read for the base port addresses of LPT1 and LPT2, stored at 0040:0008
and
* 0040:000A, respectively.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
#define LPT1_DATA (0x378) /* These declarations set as constants the hex
*/
#define LPT1_STAT (0x379) /* port addresses for LPT1 and LPT2.
*/
#define LPT1_CTRL (0x37A) /* DATA out is for sending text, control
codes.*/
#define LPT2_DATA (0x278) /* STATus is for checking for printer errors.
*/
#define LPT2_STAT (0x279) /* ConTRoL is for strobing the port to tell it
*/
#define LPT2_CTRL (0x27A) /* DATA is ready, as well as other functions.
*/
#define FF 11
main()
{
char *msg="Hello World\n "; /*Note that that 'male' sign is a Form Feed
*/
int i;
/*****INITIALIZE THE PRINTER*****/
outportb(LPT1_CTRL, 12);
for (i = 0; i < 5000; i++); /* Delay loop, preferably for 1/20 sec
*/
outportb(LPT1_CTRL, 8);
/*****MAKE SURE THE PRINTER IS READY*****/
if (inportb(LPT1_STAT) != 223)
{
printf("Printer not ready.");
exit(EXIT_FAILURE);
}
/*****PRINT SOMETHING*****/
for (i = 0; i < strlen(msg); i++)
{
outportb(LPT1_DATA, msg[i]); /* Put the character on the data lines
*/
outportb(LPT1_CTRL, 13); /* Tell the printer the data is ready
*/
outportb(LPT1_CTRL, 12); /* (Turn on and off the strobe bit)
*/
}
}
Thanks for your help.
=+=Steven Shamlian=+=