Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Programming parallel port

Status
Not open for further replies.

Hammer111

Junior Member level 3
Joined
Jun 14, 2006
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,587
Hi all

I was searching how to program parallel port but I have some errors. I'm using Microsoft Visual C++ 6.0. Here's my code
THIS CODE IS MODIFIED original isn't working either
Code:
/*     file:  ex1.c
       by HarshaPerla for electroSofts.com.
       Displays contents of status register of parallel port.
       Tested with TurboC 3.0 and Borland C 3.1 for DOS.
*/

#include"stdio.h"
#include"conio.h"
#include"dos.h"
short _stdcall Inp32(short portaddr);
void _stdcall Out32(short portaddr, short datum);

#define PORT 0x378

void main()
{
    int data;
    while(!kbhit())
    {
        data=Inp32(PORT+1);
        printf("Data available in status register: %3d (decimal), %3X (hex)\n", data, data);
        printf("\n Pin 15: %d",(data & 0x08)/0x08);
        printf("\n Pin 13: %d",(data & 0x10)/0x10);
        printf("\n Pin 12: %d",(data & 0x20)/0x20);
        printf("\n Pin 11: %d",(data & 0x80)/0x80);
        printf("\n Pin 10: %d",(data & 0x40)/0x40);
    }
}

I was using this site https://electrosofts.com/parallel/index.html and also part 2 on that site which explains how to use inpout32.dll
I copied inpout32.dll in my windows/system folder and in my folder where I saved program and I get this error while trying to run it

Linking...
parallel.obj : error LNK2001: unresolved external symbol "short __stdcall Inp32(short)" (?Inp32@@YGFF@Z)
Debug/parallel.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Also I noiced clrscr() and delay(10) doesn't exist so I deleted that

why did he write /0x08 .../0x10 etc?

I NEED SOME PDF OR SITE WHERE EVERY CODE LINE IS EXPLAINED BECAUSE I'D LIKE TO PROGRAM IT MYSELF.
 

inpout32.lib may be a C++ library. Try compiling your program as C++ instead of C.

The expression "(data & 0x08)/0x08)" is a clumsy way to give 0 or 1 depending on bit 3 of 'data'.
 

Looks like you are using it in DOS. inpout32.dll is a windows dynamic link library, it won't work in DOS
 

how do I use it in dos when I have Microsoft Visual C++ 6.0 and using windows xp?
This code was copied and modified from website link is at my first post.
 

When you say "DOS" I assume you are talking about old MS-DOS, and not the Windows Command Prompt.
VC++ 6.0 builds Windows GUI and Windows console apps. You need a different compiler to create a 16-bit DOS program.
When you create a DOS program, you don't use any DLLs or inpout32.
 

Read more about the dll you are using at:

**broken link removed**

I recommend looking at the Borland C example.

-jonathan
 

Try this its in TC then change acording to your need

Code:
#include"stdio.h"
#include"conio.h"
#include"graphics.h"
#include"dos.h"
#include"stdlib.h"
#define esc 27
#define outport 0x378
#define ledon 0xff
#define ledoff 0x00
int static no[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
int c,f=0;
void button (int,int,int,int,char[]);
void blink (int,int,int,int);
void display (void);
void main (void)
{
int dr=DETECT,m,a,b;
initgraph(&dr,&m,"c:\\tc\\bgi");
char ch,name[10];
main:
cleardevice();
display();
button(80,75,130,100," A");
button(80,125,130,150," B");
button(80,175,130,200," C");
button(80,225,130,250," D");
button(80,275,130,300," E");
button(80,325,130,350," F");
button(80,375,130,400,"EXIT");
setcolor(1);
settextstyle(11,0,3);
outtextxy(140,390,"PRESS ESC TO EXIT");
outtextxy(140,90,"GLOW LED OF YOUR CHOICE");
outtextxy(140,140,"LED BLINKING");
outtextxy(140,190,"ROTATE LEFT");
outtextxy(140,240,"ROTATE RIGHT");
outtextxy(140,290,"ROTATE LEFT + RIGHT");
outtextxy(140,340,"ONE ON ONE OFF");
ch=getch();
if(ch==27)     //for exit
{
closegraph();
exit(0);
}
else
if(ch=='a' || ch=='A')   //Enter Led No       A
{
rep:
cleardevice();
display();
setcolor(1);
setfillstyle(1,0);
rectangle(100,100,550,300);     //black
floodfill(120,120,1);
setcolor(1);
rectangle(315,140,330,160);//small blue
setcolor(4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
setcolor(1);
settextstyle(10,0,1);
outtextxy(180,100,"ENTER LED NO 0 - 7");
gotoxy(41,10);
gets(name);
if(name[0]==48)      //led 0 glow
{
outportb(outport,no[0]);
setcolor(4);
setfillstyle(1,4);
floodfill(261,181,4);
}
if(name[0]==49)      //led 1 glow
{
outportb(outport,no[1]);
setcolor(4);
setfillstyle(1,4);
floodfill(281,181,4);
}
if(name[0]==50)      //led 2 glow
{
outportb(outport,no[2]);
setcolor(4);
setfillstyle(1,4);
floodfill(301,181,4);
}
if(name[0]==51)      //led 3 glow
{
outportb(outport,no[3]);
setcolor(4);
setfillstyle(1,4);
floodfill(321,181,4);
}
if(name[0]==52)      //led 4 glow
{
outportb(outport,no[4]);
setcolor(4);
setfillstyle(1,4);
floodfill(341,181,4);
}
if(name[0]==53)      //led 5 glow
{
outportb(outport,no[5]);
setcolor(4);
setfillstyle(1,4);
floodfill(361,181,4);
}
if(name[0]==54)      //led 6 glow
{
outportb(outport,no[6]);
setcolor(4);
setfillstyle(1,4);
floodfill(381,181,4);
}
if(name[0]==55)      //led 7 glow
{
outportb(outport,no[7]);
setcolor(4);
setfillstyle(1,4);
floodfill(401,181,4);
}
setcolor(1);
settextstyle(11,0,10);
outtextxy(210,350,"PRESS R TO RETURN TO MAIN");
outtextxy(240,370,"PRESS ESC TO EXIT");
ch=getch();
if(ch=='r' || ch=='R')
goto main;
else
if(ch==27)     //for exit
{
closegraph();
exit(0);
}
else
goto rep;
}                                // A END
			     ////////// LED NO B
if(ch=='b' || ch=='B')
{

cleardevice();
display();
setcolor(1);
setfillstyle(1,0);
rectangle(100,100,550,300);     //black
floodfill(120,120,1);
setcolor(4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0


setcolor(14);
settextstyle(10,0,1);
outtextxy(145,100,"PRESS ANY KEY TO STOP");
setcolor(1);
settextstyle(11,0,10);
outtextxy(210,350,"PRESS R TO RETURN TO MAIN");
outtextxy(240,370,"PRESS ESC TO EXIT");
int a=4;
while(!kbhit())
{
//harware interface
outportb(outport,ledon);
setcolor(11);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
setfillstyle(1,a);
floodfill(261,181,11);
floodfill(281,181,11);
floodfill(301,181,11);
floodfill(321,181,11);
floodfill(341,181,11);
floodfill(361,181,11);
floodfill(381,181,11);
floodfill(401,181,11);
delay(800);
outportb(outport,ledoff);
a=0;
setcolor(11);
setfillstyle(1,a);
floodfill(261,181,11);
floodfill(281,181,11);
floodfill(301,181,11);
floodfill(321,181,11);
floodfill(341,181,11);
floodfill(361,181,11);
floodfill(381,181,11);
floodfill(401,181,11);
a=4;
delay(800);
}


ch=getch();
if(ch=='r' || ch=='R')
goto main;
else
if(ch==27)     //for exit
{
closegraph();
exit(0);
}
}                             ///////// B END
			     //led no C
if(ch=='c' || ch=='C')
{
cleardevice();
display();
setcolor(1);
setfillstyle(1,0);
rectangle(100,100,550,300);     //black
floodfill(120,120,1);
setcolor(4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
setcolor(14);
settextstyle(10,0,1);
outtextxy(145,100,"PRESS ANY KEY TO STOP");
setcolor(1);
settextstyle(11,0,10);
outtextxy(210,350,"PRESS R TO RETURN TO MAIN");
outtextxy(240,370,"PRESS ESC TO EXIT");
c=401;
while(!kbhit())
{
setcolor(11);
setfillstyle(1,4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
floodfill(c,181,11);
delay(200);
setfillstyle(1,0);
floodfill(c,181,11);
delay(200);
c-=20;
if(c==241)
c=401;

// hardware
for(a=0;a<=7;a++)
{
outportb(outport,no[a]);
delay(800);
}
}
ch=getch();
if(ch=='r' || ch=='R')
goto main;
else
if(ch==27)     //for exit
{
closegraph();
exit(0);
}//////////////    c end
}
 //////////////////////   d
if(ch=='d' || ch=='D')
{
cleardevice();
display();
setcolor(1);
setfillstyle(1,0);
rectangle(100,100,550,300);     //black
floodfill(120,120,1);
setcolor(4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
setcolor(14);
settextstyle(10,0,1);
outtextxy(145,100,"PRESS ANY KEY TO STOP");
setcolor(1);
settextstyle(11,0,10);
outtextxy(210,350,"PRESS R TO RETURN TO MAIN");
outtextxy(240,370,"PRESS ESC TO EXIT");
c=261;
while(!kbhit())
{
setcolor(11);
setfillstyle(1,4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
floodfill(c,181,11);
delay(500);
setfillstyle(1,0);
floodfill(c,181,11);
delay(500);
c+=20;
if(c==421)
c=261;
// hard ware
for(a=7;a>=0;a--)
{
outportb(outport,no[a]);
delay(800);
}
}
ch=getch();
if(ch=='r' || ch=='R')
goto main;
else
if(ch==27)     //for exit
{
closegraph();
exit(0);
}///////////
}                   ////////// d end
 //////////////////////   e
if(ch=='e' || ch=='E')
{
cleardevice();
display();
setcolor(1);
setfillstyle(1,0);
rectangle(100,100,550,300);     //black
floodfill(120,120,1);
setcolor(4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
setcolor(14);
settextstyle(10,0,1);
outtextxy(145,100,"PRESS ANY KEY TO STOP");
setcolor(1);
settextstyle(11,0,10);
outtextxy(210,350,"PRESS R TO RETURN TO MAIN");
outtextxy(240,370,"PRESS ESC TO EXIT");
c=401;
while(!kbhit())
{
setcolor(11);
setfillstyle(1,4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
if(f==0)
{
floodfill(c,181,11);
delay(100);
setfillstyle(1,0);
floodfill(c,181,11);
delay(100);
c-=20;
if(c==241)
{
f=1;
c=261;
}
}
if(f==1)
{
floodfill(c,181,11);
delay(5);
setfillstyle(1,0);
floodfill(c,181,11);
delay(5);
c+=20;
if(c==421)
{
f=0;
c=401;
}
}
// hard ware
for(a=7;a>=0;a--)
{
outportb(outport,no[a]);
delay(800);
}
for(a=0;a<=7;a++)
{
outportb(outport,no[a]);
delay(800);
}
}
ch=getch();
if(ch=='r' || ch=='R')
goto main;
else
if(ch==27)     //for exit
{
closegraph();
exit(0);
}///////////
}                   ////////// e end
 //////////////////////   f
if(ch=='f' || ch=='F')
{
cleardevice();
display();
setcolor(1);
setfillstyle(1,0);
rectangle(100,100,550,300);     //black
floodfill(120,120,1);
setcolor(4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
setcolor(14);
settextstyle(10,0,1);
outtextxy(145,100,"PRESS ANY KEY TO STOP");
setcolor(1);
settextstyle(11,0,10);
outtextxy(210,350,"PRESS R TO RETURN TO MAIN");
outtextxy(240,370,"PRESS ESC TO EXIT");
while(!kbhit())
{
setcolor(11);
setfillstyle(1,4);
circle(400,180,5);//led 7
circle(380,180,5);//led 6
circle(360,180,5);//led 5
circle(340,180,5);//led 4
circle(320,180,5);//led 3
circle(300,180,5);//led 2
circle(280,180,5);//led 1
circle(260,180,5);//led 0
floodfill(401,181,11);
floodfill(361,181,11);
floodfill(321,181,11);
floodfill(281,181,11);
delay(500);
setfillstyle(1,0);
floodfill(401,181,11);
floodfill(361,181,11);
floodfill(321,181,11);
floodfill(281,181,11);
delay(500);
setfillstyle(1,4);
floodfill(381,181,11);
floodfill(341,181,11);
floodfill(301,181,11);
floodfill(261,181,11);
delay(500);
setfillstyle(1,0);
floodfill(381,181,11);
floodfill(341,181,11);
floodfill(301,181,11);
floodfill(261,181,11);
delay(500);

// hard ware

outportb(outport,no[0xaa]) ;
delay(800);
outportb(outport,no[0x55]) ;

}
ch=getch();
if(ch=='r' || ch=='R')
goto main;
else
if(ch==27)     //for exit
{
closegraph();
exit(0);
}///////////
}                   ////////// f end


getch();
closegraph();
}                  // main end

void display (void)
{
int i,f[10]={7,7,100,30,320,60,520,30,629,7};
setcolor(13);
setfillstyle(1,3);
rectangle(1,1,638,478);
floodfill(5,5,13);
setcolor(11);
setfillstyle(7,9);    /* Text Background  */
fillpoly(5,f);        /* Text Fillpoly  */
setcolor(14);
settextstyle(7,0,3);
outtextxy(170,6,"L E D - D I S P L A Y");
setcolor(1);
settextstyle(11,0,3);
outtextxy(150,445,"Copyright Hasan & Atif PRODUCTIONS 2006");
outtextxy(220,457,"  All Rights Reserved");
}

void button (int c1,int r1,int c2,int r2,char ch[])
{
setcolor(0);
rectangle(c1+1,r1+1,c2+2,r2+2);
setcolor(8);
rectangle(c1+2,r1+2,c2+1,r2+1);
setcolor(15);
rectangle(c1-1,r1-1,c2,r2);
setcolor(7);
setfillstyle(1,7);
rectangle(c1,r1,c2,r2);
floodfill(c1+5,r1+5,7);
setcolor(0);
outtextxy(c1+11,r1+7,ch);
}
void blink (int c1,int r1,int c2,int r2)
{
setcolor(8);
rectangle(c1-1,r1-1,c2-2,r2-2);
setcolor(0);
rectangle(c1-2,r1-2,c2-1,r2-1);
setcolor(15);
rectangle(c1,r1,c2+1,r2+1);
setcolor(7);
setfillstyle(1,7);
rectangle(c1,r1,c2,r2);
floodfill(c1+5,r1+5,7);
}[/img]
 

If you want to do it in C you have to install userport first.See the link below and see how to install it
**broken link removed**

Now you do programming

Bibin John
www.bibinjohn.tk
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top