Parallel Schnittstelle ansprechen

Post Reply
Message
Author
Matong

Parallel Schnittstelle ansprechen

#1 Post by Matong »

Hey Folks,
ich hab vorhin ein wenig aufgräumt und ein alten Plan gefunden, mit der man ein Schaltung bauen und über die parallele Schnittstelle ansprechen läßt. Lider stehen dort nur die Befehle aus der QBASIC-Sparte, also nur out 388, 0(Allee Acht raus Leitungen auf "0"/AUS).

Mich würde nun interressieren, wie man dies mit C lößt.

THANKS a LOT,
cya Matong

bakunin
Posts: 597
Joined: 16. Aug 1999 6:44
Location: Lorsch (Südhessen)
Contact:

Re: Parallel Schnittstelle ansprechen

#2 Post by bakunin »

Hi!

Das Parallel Programming Howto erklärt das eigentlich ziemlich gut. Aber das Prinzip ist: Mit ioperm() Port freischalten und z.B. mit inb() und outb() zugreifen. Also nicht arg anders als du es kennst.

Cheers,
GNU/Wolfgang

Descartes

Re: Parallel Schnittstelle ansprechen

#3 Post by Descartes »

Also mal ein Beispiel Source wie von GNU/Wolfgang vorgeschlagen mit ioperm() und outb()...
<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
/*
* The code will work on a Linux. As far as SunOS is concerned there
* are two files you need to include (sys/ddi.h) and (sys/sunddi.h) for
* the inb() and outb() functions.
*
* You also need to compile with -O or -O2 or similar. The reason for that
* is that inb() and family are defined as inline macros, and compiling
* them without optimization enabled will cause unresolved references at
* link time (Someone in #c came and kept on asking about it, and I thought
* I would add this part in). [If people would only read the man pages!].
*/

#include <stdio.h>
#include <unistd.h> /* needed for ioperm() */
#include <asm/io.h> /* for outb() and inb() */

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

int main( void )
{
int x = 0x32;
int y = 0x08;

if ( ioperm(DATA,3,1) )
{
printf("Sorry, you were not able to gain access to the ports\<!--no-->n");
printf("You must be root to run this program\<!--no-->n");
exit(1);
}

outb( DATA, x ); /* Sends 0011 0010 to the Data Port */
outb( CONTROL, y^0x0b );

/* SELECT_IN = 1, INIT = 0, /AUTO_FEED = 0, /STROBE = 0 */
return (0);
}
</font><hr></pre></blockquote>

Descartes

Re: Parallel Schnittstelle ansprechen

#4 Post by Descartes »

am einfachsten wird es wohl gehen, wenn du folgende Library verwendest:

parapin -- a Parallel Port Pin Programming Library for Linux
<a href="http://www.circlemud.org/~jelson/software/parapin/" target="_blank"><!--auto-->http://www.circlemud.org/~jelson/softwa ... <!--auto-->

Quellcode Beispiel mit parapin:

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
#include "parapin.h"

#define LPT1 0x378
#define LPT2 0x278

#define VCC LP_PIN02
#define CS LP_PIN03
#define CLK LP_PIN04
#define D0 LP_PIN10 /* input pin */

int main(int argc, char* argv[])
{
int ret = pin_init_user( LPT1 );

if ( ret != 0 )
{
printf("cannot initialize parallel port !");
return 1;
}

/* configure Pin 1, and Pins 2-9 for output mode */
/* The constant LP_DATA_PINS is an alias for Pins 2-9 */
pin_mode(LP_PIN01 | LP_DATA_PINS, LP_OUTPUT);

clear_pin( CS ); /* pull Chip Select low, tell it to acquire */

set_pin( CLK ); /* clock it */
clear_pin( CLK );

/* runway lights: light up pins 1 through 9 in sequence */
while( 1 )
{
for( i=1; i<=9; i++)
{
set_pin( LP_PIN<i> );
usleep( 200 );
clear_pin( LP_PIN<i> );
}
}
return 0;
}
</font><hr></pre></blockquote>

Sonstige Links passend zum Thema:

/usr/src/linux/Documentation/parport-lowlevel.txt
<a href="http://lxr.linux.no/source/Documentatio ... wlevel.txt" target="_blank"><!--auto-->http://lxr.linux.no/source/Documentatio ... <!--auto-->

Linux I/O port programming mini-HOWTO
<a href="http://www.linuxdoc.org/HOWTO/mini/IO-P ... ing-9.html" target="_blank"><!--auto-->http://www.linuxdoc.org/HOWTO/mini/IO-P ... <!--auto-->

External Parallel Port devices and Linux
<a href="http://www.torque.net/linux-pp.html" target="_blank"><!--auto-->http://www.torque.net/linux-pp.html</a><!--auto-->

Parallel Port Central
<a href="http://www.lvr.com/parport.htm" target="_blank"><!--auto-->http://www.lvr.com/parport.htm</a><!--auto-->

Descartes

Re: Parallel Schnittstelle ansprechen

#5 Post by Descartes »

ich sollte doch als vorher die Preview genauer anschauen oder mich einloggen damit ich die Postings noch editieren kann....naja was solls....hier der letzte Part des obigen Listings....die eckigen Klammern bei LP_PIN[<!--no-->i<!--no-->]wurden leider als [<!--no-->i<!--no-->] Tags ausgewertet...

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
...

/* runway lights: light up pins 1 through 9 in sequence */
while( 1 )
{
for( i=1; i<=9; i++)
{
set_pin( LP_PIN[<!--no-->i<!--no-->] );
usleep( 200 );
clear_pin( LP_PIN[<!--no-->i<!--no-->] );
}
}

return 0;
}
</font><hr></pre></blockquote>

Post Reply