Leandro Colen <lcrocha@yahoo.com> wrote:
Hi,
i’m trying to send a simple out8() to the parallel port of my x86, i put an
osciloscope in the port to monitor the signal but i can’t see if it was
successfull.
It’s because the devc-par actually have the control of the port? And every
time that i try to send the signal the devc-par override it?
Can i disable the devc-par to do my tests?
Sure; you can kill it (slay devc-par), or simply put it on hold.
I used the parallel port under Neutrino to drive an antique paper tape reader 
Here’s the code – note some of the initializations, etc:
(tabstops are every 4 characters)
/*
- main.c
-
- QNX 6, main.c shell version 0.005
-
- (C) Copyright 2002, 1230599 Ontario Inc., dba PARSE Software Devices.
- All rights reserved. Use subject to terms in LICENSE file.
-
- This module represents the main module for the PR-68E paper tape
- interface program.
-
- This program will cause the paper tape reader to read characters.
-
- The hardware is organized such that it’s driven off the parallel port,
- with the parallel port’s STROBE signal driving the stepper motor
- circuit. The STROBE signal is inverted, so it has to be set in software
- as a 1 to 0 transition to step. The stepper motor needs 4 steps for
- one sprocket step.
-
- With a 1 ms delay, this means 2 ms elapse for each step, which means
- 8 ms elapse per sprocket step. 1/8ms = 125 Hz – theoretically, the
- paper tape reader can do 300 Hz.
-
- 2002 04 29 R. Krten created
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <sys/neutrino.h>
#include <hw/inout.h>
#define LPT_DATA_REG 0
#define LPT_STAT_REG 1
#define LPT_CTRL_REG 2
#define MAX_TIME 200
static void optproc (int, char **);
const char *progname = “pr68”;
const char *blankname= " ";
extern char *version; // version.c
int optp; // port; default 0x378
int optv;
int
main (int argc, char **argv)
{
int x;
int timeout;
optproc (argc, argv);
if (ThreadCtl (_NTO_TCTL_IO, 0) == -1) {
fprintf (stderr, “%s: can’t do ThreadCtl for _NTO_TCTL_IO, errno %d\n”, progname, errno);
perror (NULL);
}
out8 (optp + LPT_CTRL_REG, 0x21); // 0x20 programs the parallel port for read, LSB is the inverted STROBE pin output
while (1) {
// while sprocket hole not preset…
timeout = 0;
while ((in8 (optp + LPT_STAT_REG) & 0x20) == 0) {
out8 (optp + LPT_CTRL_REG, 0x21);
nanospin_ns (2000); // 2000 ns = 2us
out8 (optp + LPT_CTRL_REG, 0x20);
delay (1);
timeout++;
if (timeout > MAX_TIME) {
fprintf (stderr, “%s: EOT\n”, progname);
exit (EXIT_SUCCESS);
}
}
// at this point the sprocket hole showed up; data must be valid
x = in8 (optp + LPT_DATA_REG);
printf ("%d%d%d%d%d%d%d%d\n", !! (x & 0x80), !! (x & 0x40), !! (x & 0x20), !! (x & 0x10), !! (x & 0x08), !! (x & 0x04), !! (x & 0x02), !! (x & 0x01));
// printf ("%d%d%d%d%d%d%d%d\n", !! (x & 0x01), !! (x & 0x02), !! (x & 0x04), !! (x & 0x08), !! (x & 0x10), !! (x & 0x20), !! (x & 0x40), !! (x & 0x80));
fflush (stdout);
// now wait for sprocket hole to go away…
timeout = 0;
while ((in8 (optp + LPT_STAT_REG) & 0x20) == 0x20) {
out8 (optp + LPT_CTRL_REG, 0x21);
nanospin_ns (2000); // 2000 ns = 2us
out8 (optp + LPT_CTRL_REG, 0x20);
delay (1);
timeout++;
if (timeout > MAX_TIME) {
fprintf (stderr, “%s: EOT\n”, progname);
exit (EXIT_SUCCESS);
}
}
}
return (EXIT_SUCCESS);
}
static void
usageError (void)
{
fprintf (stderr, “%s: error in use, type “use %s” for usage\n”, progname, progname);
exit (1);
}
static void
optproc (int argc, char **argv)
{
int opt;
if (!argc) {
usageError ();
}
optp = 0x378;
while ((opt = getopt (argc, argv, “p:v”)) != -1) {
switch (opt) {
case ‘p’:
sscanf (optarg, “%x”, &optp);
break;
case ‘v’:
optv++;
if (optv > 1) {
printf (“Verbosity is %d\n”, optv);
}
break;
default:
usageError ();
break;
}
}
for (; optind < argc; optind++) {
printf (“additional parameters [%d] -%s-\n”, optind, argv [optind]);
}
}
\
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.