parallel port control
Dec 11, 2011 4:31:50 GMT 1
Post by bigbass on Dec 11, 2011 4:31:50 GMT 1
having fun again with this after so many years have passed since
I did this with Qbasic but now in BaCon !!!
*I tested this and its working with my multi-meter*
pin 25 ground then pins 2-9 are the eight bits we use
where I got the original source code and data * I commented were edits were made
www.epanorama.net/circuits/parallel_output.html
easy use
1.)copy lptout to /usr/sbin
then you run
2.)./ascii-test2
and input 1-8 ( 0 will turn off the led )
here is the C code source
compile with this
Joe
now here is the BaCon app I wrote to test
the port ascii-test2.bac what it does is read the keyboard
for input values of 1-8 and zero to turn off
it converts the ascii key press to decimal and outputs it to the port
this is a simple test program hacking welcomed
I did this with Qbasic but now in BaCon !!!
*I tested this and its working with my multi-meter*
pin 25 ground then pins 2-9 are the eight bits we use
wget http://www.puppy2.org/slaxer/lptout
wget http://www.puppy2.org/slaxer/ascii-test2
where I got the original source code and data * I commented were edits were made
www.epanorama.net/circuits/parallel_output.html
easy use
1.)copy lptout to /usr/sbin
then you run
2.)./ascii-test2
and input 1-8 ( 0 will turn off the led )
here is the C code source
compile with this
gcc -O lptout.c -o lptout
Joe
/* Simple parallel port output control program for Linux */
/* Written and copyright by Tomi Engdahl 1998 */
/* (e-mail: tomi.engdahl@hut.fi) */
/* The program output the data value to PC parallel port data pins */
/* (default lpt1 I/O address 0x378). The data values are given as the */
/* command line parameter to the program. The number can be */
/* in decimal (0..255) or hexadecimal format (0x00..0xFF). */
/*
/* Dec-9-2011 Joe Arose edited to compile to be used in BaCon replaced with #include <sys/io.h> */
/* #include <asm/io.h> replaced with #include <sys/io.h> */
#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#define base 0x378 /* printer port base address */
main(int argc, char **argv)
{
int value;
if (argc!=2)
fprintf(stderr, "Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.\n"), exit(1);
if (sscanf(argv[1],"%i",&value)!=1)
fprintf(stderr, "Error: Parameter is not a number.\n"), exit(1);
if ((value<0) || (value>255))
fprintf(stderr, "Error: Invalid numeric value. The parameter number must be between 0 and 255\n"), exit(1);
if (ioperm(base,1,1))
fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);
outb((unsigned char)value, base);
}
now here is the BaCon app I wrote to test
the port ascii-test2.bac what it does is read the keyboard
for input values of 1-8 and zero to turn off
it converts the ascii key press to decimal and outputs it to the port
this is a simple test program hacking welcomed
myvar = 0
WHILE myvar < 57 DO
PRINT
PRINT
PRINT "enter a number from 1 to 8 "
INPUT str$
CLEAR
PRINT
'---get the ascii number for the first character ---'
myvar = ASC(str$)
SELECT myvar
CASE 49
PRINT "ASCII Value is ", myvar, " its a 1 "
PRINT "Here we output a binary bit 1"
SYSTEM ("lptout 1")
CASE 50
PRINT "ASCII Value is ", myvar, " its a 2 "
PRINT "Here we output a binary bit 2"
SYSTEM ("lptout 2")
CASE 51
PRINT "ASCII Value is ", myvar, " its a 3 "
PRINT "Here we output a binary bit 3 which is dec 4"
SYSTEM ("lptout 4")
CASE 52
PRINT "ASCII Value is ", myvar, " its a 4 "
PRINT "Here we output a binary bit 4 which is dec 8"
SYSTEM ("lptout 8")
CASE 53
PRINT "ASCII Value is ", myvar, " its a 5 "
PRINT "Here we output a binary bit 5 which is dec 16"
SYSTEM ("lptout 16")
CASE 54
PRINT "ASCII Value is ", myvar, " its a 6 "
PRINT "Here we output a binary bit 6 which is dec 32"
SYSTEM ("lptout 32")
CASE 55
PRINT "ASCII Value is ", myvar, " its a 7 "
PRINT "Here we output a binary bit 7 which is dec 64"
SYSTEM ("lptout 64")
CASE 56
PRINT "ASCII Value is ", myvar, " its a 8 "
PRINT "Here we output a binary bit 8 which is dec 128"
SYSTEM ("lptout 128")
DEFAULT
PRINT "not checking for ASCII Value ", myvar
PRINT "will turn off led"
SYSTEM ("lptout 0")
END SELECT
WEND