parallel port programming simple problem

M

Marco

Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm


/////////////////////////////////////////////////////////////////////
#include <dos.h>
#include <string.h>
#include <stdio.h>

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

void main(void)
{
char string[] = {"Testing 1,2,3 "
"It' Works ! "};
char init[10];
int count;
int len;
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */

outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port -
Make sure Forward Direction */

outportb(CONTROL, inportb(CONTROL) | 0x08); /* Set Select Printer
(Register Select) */

for (count = 0; count <= 2; count++)
{
outportb(DATA, init[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/
delay(20); /* Larger Delay for INIT
*/
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe
(Enable)*/
delay(20); /* Larger Delay for INIT
*/
}

outportb(CONTROL, inportb(CONTROL) & 0xF7); /* Reset Select Printer
(Register Select) */

len = strlen(string);

for (count = 0; count < len; count++)
{
outportb(DATA, string[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
delay(2);
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
delay(2);
}
}
////////////////////////////////////////////////////////////////////////////////


--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'outportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'inportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(30) : error C2065:
'delay' : undeclared identifier
 
A

Andrew Poelstra

Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm


/////////////////////////////////////////////////////////////////////
#include <dos.h>
#include <string.h>
#include <stdio.h>

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

void main(void)
{
char string[] = {"Testing 1,2,3 "
"It' Works ! "};
char init[10];
int count;
int len;
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */

outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port -
Make sure Forward Direction */

outportb(CONTROL, inportb(CONTROL) | 0x08); /* Set Select Printer
(Register Select) */

for (count = 0; count <= 2; count++)
{
outportb(DATA, init[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/
delay(20); /* Larger Delay for INIT
*/
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe
(Enable)*/
delay(20); /* Larger Delay for INIT
*/
}

outportb(CONTROL, inportb(CONTROL) & 0xF7); /* Reset Select Printer
(Register Select) */

len = strlen(string);

for (count = 0; count < len; count++)
{
outportb(DATA, string[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
delay(2);
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
delay(2);
}
}
////////////////////////////////////////////////////////////////////////////////


--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'outportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'inportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(30) : error C2065:
'delay' : undeclared identifier

It looks suspiciously like you tried to use functions that you haven't
declared or defined.
 
M

Marco

--------------------Configuration: Text1 - Win32
It looks suspiciously like you tried to use functions that you haven't
declared or defined.


I want to know whether outportb, delay and inportb are function in
general function in C? (I have no experience in C at all.) If they are
general function in C, how I can define them?
Thanks
 
R

Rouben Rostamian

Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm ....

--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'outportb' : undeclared identifier

Read the sentence just after the program listing in the website
you have cited.
 
M

Marco

Read the sentence just after the program listing in the website
you have cited.

I change the program to the following, but still have error
Could you please tell me (A new C programmer) why that happen?
thanks


//////////////////////////////////////////////////
#include <stdio.h>
#include <dos.h>
#include <string.h>

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

void main(void)
{
char string[] = {"Testing 1,2,3 "
"It' Works ! "};
char init[10];
int count;
int len;
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */

outp(CONTROL, inp(CONTROL) & 0xDF); /* Reset Control Port - Make sure
Forward Direction */

outp(CONTROL, inp(CONTROL) | 0x08); /* Set Select Printer (Register
Select) */

for (count = 0; count <= 2; count++)
{
outp(DATA, init[count]);
outp(CONTROL,inp(CONTROL) | 0x01); /* Set Strobe (Enable)*/
delay(20); /* Larger Delay for INIT
*/
outp(CONTROL,inp(CONTROL) & 0xFE); /* Reset Strobe (Enable)*/
delay(20); /* Larger Delay for INIT
*/
}

outp(CONTROL, inp(CONTROL) & 0xF7); /* Reset Select Printer (Register
Select) */

len = strlen(string);

for (count = 0; count < len; count++)
{
outp(DATA, string[count]);
outp(CONTROL,inp(CONTROL) | 0x01); /* Set Strobe */
delay(2);
outp(CONTROL,inp(CONTROL) & 0xFE); /* Reset Strobe */
delay(2);
}
}
/////////////////////////////////////////////////

--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
c:\program files\microsoft visual studio\text1.c(22) : warning C4013:
'outp' undefined; assuming extern returning int
c:\program files\microsoft visual studio\text1.c(22) : warning C4013:
'inp' undefined; assuming extern returning int
c:\program files\microsoft visual studio\text1.c(30) : warning C4013:
'delay' undefined; assuming extern returning int

Text1.obj - 0 error(s), 3 warning(s)
 
A

Andrew Poelstra

I want to know whether outportb, delay and inportb are function in
general function in C? (I have no experience in C at all.) If they are
general function in C, how I can define them?
Thanks

They are not Standard functions. If they are library functions (which
they appear to be), you must #include the appropriate header. Otherwise,
you would declare and define them just as any other function.
 
A

Andrew Poelstra

I change the program to the following, but still have error
Could you please tell me (A new C programmer) why that happen?
thanks

...
void main(void)

main returns int. Get that right before asking other questions.
 
R

Rouben Rostamian

--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
c:\program files\microsoft visual studio\text1.c(22) : warning C4013:
'outp' undefined; assuming extern returning int
c:\program files\microsoft visual studio\text1.c(22) : warning C4013:
'inp' undefined; assuming extern returning int
c:\program files\microsoft visual studio\text1.c(30) : warning C4013:
'delay' undefined; assuming extern returning int

The functions outp and inp are not Standard C functions.
You won't get further useful information in this newsgroup.
Try asking in:

comp.os.ms-windows.programmer.win32
 
P

pnreddy1976

Hi,Macro.
How are you...
Please mention on which operating system your compiling this programme.
 
M

Marco

MS VC++





(e-mail address removed) 寫é“:
Hi,Macro.
How are you...
Please mention on which operating system your compiling this programme.
Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm


/////////////////////////////////////////////////////////////////////
#include <dos.h>
#include <string.h>
#include <stdio.h>

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

void main(void)
{
char string[] = {"Testing 1,2,3 "
"It' Works ! "};
char init[10];
int count;
int len;
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */

outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port -
Make sure Forward Direction */

outportb(CONTROL, inportb(CONTROL) | 0x08); /* Set Select Printer
(Register Select) */

for (count = 0; count <= 2; count++)
{
outportb(DATA, init[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/
delay(20); /* Larger Delay for INIT
*/
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe
(Enable)*/
delay(20); /* Larger Delay for INIT
*/
}

outportb(CONTROL, inportb(CONTROL) & 0xF7); /* Reset Select Printer
(Register Select) */

len = strlen(string);

for (count = 0; count < len; count++)
{
outportb(DATA, string[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
delay(2);
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
delay(2);
}
}
////////////////////////////////////////////////////////////////////////////////


--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'outportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'inportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(30) : error C2065:
'delay' : undeclared identifier
 
M

Martin Ambuhl

Marco said:
Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm

There are many things that could cause your problems. The program uses
many things which are not part of C and must be provided from some
outside source. Some of these seem not to be provided by your (or many
other implementations). This makes the program implementation-specific,
and there are no doubt MS-specific newsgroups to address those problems.

In addition, there are constructs which are not C at all.

#include <dos.h>
This header does not exist as a standard C header. Think about it: for
how many systems does the whole concept of "dos" make no sense at all,
or for which "dod" doesn't mean some variant of MS-DOS (some of my old
PDP-8s ran "DOS", for example).

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

This and the three defines based on it suggest that you are trying to
directly access hardware. Nothing in C guarantees you can do this, and
many operating systems forbid you to do this.
void main(void)

main does *not* have a return type of void. main returns an int.
Defining it otherwise makes your program beyond the pale, and the
compiler need not produce anything useful.
outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port -
Make sure Forward Direction */

There are no standard functions outportb() or inportb(). If they exist
on your implementation, they may well need to be linked. Whether they
exist or not or your implementation, a program using them is not
portable, possibly not even to another version of the same compiler on
the same platform. Your error messages suggest that your implementation
does not have them, at least not without linking some
implementation-specific code, which linking you have not done.
delay(20); /* Larger Delay for INIT

There is no standard function delay(). The comments above apply.

Finally, you should (and must in pre-C99 C) return a value from main.
Since you do not include <stdlib.h>, the only return value with portably
defined meaning is 0. With <stdlib.h> included, the return values
portably defined include in addition EXIT_SUCCESS and EXIT_FAILURE.
 
D

Default User

Marco wrote:

I want to know whether outportb, delay and inportb are function in
general function in C? (I have no experience in C at all.) If they are
general function in C, how I can define them?
Thanks


These are old DOS functions that some compilers used to provide. They
are standard, and aren't usually available for Windows (you mention
VC++ elsewhere).




Brian
 
G

Gordon Burditt

Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm ....
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'outportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'inportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(30) : error C2065:
'delay' : undeclared identifier

outportb(), inportb(), and delay() are not standard C functions.

Further, assuming that outportb() and inportb() do not have anything
to do with ship navigation and refer to Intel *86 I/O ports, these
functions require privileges no reasonable OS will allow an ordinary
user to have - so even if you get it to compile, it won't run for
an unprivileged user. Reasonable OS: UNIX, Linux, recent versions
of Windows. Unreasonable OS: Windows 3.1 (I think), MS-DOS, CP/M
86.

Gordon L. Burditt
 
N

Neil

Marco said:
Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm


/////////////////////////////////////////////////////////////////////
#include <dos.h>
#include <string.h>
#include <stdio.h>

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

void main(void)
{
char string[] = {"Testing 1,2,3 "
"It' Works ! "};
char init[10];
int count;
int len;
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */

outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port -
Make sure Forward Direction */

outportb(CONTROL, inportb(CONTROL) | 0x08); /* Set Select Printer
(Register Select) */

for (count = 0; count <= 2; count++)
{
outportb(DATA, init[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/
delay(20); /* Larger Delay for INIT
*/
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe
(Enable)*/
delay(20); /* Larger Delay for INIT
*/
}

outportb(CONTROL, inportb(CONTROL) & 0xF7); /* Reset Select Printer
(Register Select) */

len = strlen(string);

for (count = 0; count < len; count++)
{
outportb(DATA, string[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
delay(2);
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
delay(2);
}
}
////////////////////////////////////////////////////////////////////////////////


--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'outportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'inportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(30) : error C2065:
'delay' : undeclared identifier


Beside the programming issues posted, you have a worse problem.
You have MS-DOS code. Windows, NT, 2000, & XP will not let a user app
write to hardware. The code can not be fixed to do what you want.
You need to find one of the Parallel port drivers available on the net.
 
S

Sjouke Burry

Neil said:
Marco said:
Could anyone please tell me why the program has the following error? I
copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm


/////////////////////////////////////////////////////////////////////
#include <dos.h>
#include <string.h>
#include <stdio.h>

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

void main(void)
{
char string[] = {"Testing 1,2,3 "
"It' Works ! "};
char init[10];
int count;
int len;
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */

outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port -
Make sure Forward Direction */

outportb(CONTROL, inportb(CONTROL) | 0x08); /* Set Select Printer
(Register Select) */

for (count = 0; count <= 2; count++)
{
outportb(DATA, init[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/
delay(20); /* Larger Delay for INIT
*/
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe
(Enable)*/
delay(20); /* Larger Delay for INIT
*/
}

outportb(CONTROL, inportb(CONTROL) & 0xF7); /* Reset Select Printer
(Register Select) */

len = strlen(string);

for (count = 0; count < len; count++)
{
outportb(DATA, string[count]);
outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
delay(2);
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
delay(2);
}
}
////////////////////////////////////////////////////////////////////////////////



--------------------Configuration: Text1 - Win32
Debug--------------------
Compiling...
Text1.c
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'outportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(22) : error C2065:
'inportb' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\Text1.c(30) : error C2065:
'delay' : undeclared identifier


Beside the programming issues posted, you have a worse problem.
You have MS-DOS code. Windows, NT, 2000, & XP will not let a user app
write to hardware. The code can not be fixed to do what you want.
You need to find one of the Parallel port drivers available on the net.
Yes it can,google for userport.zip
Sometimes computers are used to control
hardware :)
Outportb and inportb might be outp and inp.
 
P

pnreddy1976

Hi macro,
while ur using these functions don't use directly.
u replace like
Ex :
inp as _inp;
outp as _outp
may be thse will work for u
Reddy
 
K

Keith Thompson

Marco said:
I want to know whether outportb, delay and inportb are function in
general function in C? (I have no experience in C at all.) If they are
general function in C, how I can define them?

No, outportb, delay, and inportb are not standard C functions.
They're system-specific. If you need more information about them,
you'll need to ask in a system-specific newsgroup, possibly
comp.os.msdos.programmer. (That's assuming that Rouben Rostamian to
read the information on the web site doesn't solve your problem.)
 
P

pete

These are old DOS functions that some compilers used to provide. They
are standard, and aren't usually available for Windows (you mention
VC++ elsewhere).

I don't know what you think you mean by "They are standard",
but those functions are not described in the C standard.
 
C

Chris Dollin

pete said:
I don't know what you think you mean by "They are standard",
but those functions are not described in the C standard.

I think "are" is a negatypo for "aren't".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top