I wrote a little program for switching LED's on and off with a 4 led resistor hooked up directly to a parallel port.
/*
parled - changes the bit state of four LED resistor to flash LEDs on or off
Copyright (C) 2001 Myron Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include
#include
#include
*/
#include
#include
#include
#include "system.h"
#include
#include
#include "cmdline.h"
#define BASEPORT 0x378 /*lp0 */
#define EXIT_FAILURE 1
#define LED1 0x01
#define LED2 0x02
#define LED3 0x04
#define LED4 0x08
#define ALL 0x15
char *xmalloc ();
char *xrealloc ();
char *xstrdup ();
int
main(int argc, char **argv)
{
unsigned int signal=0;
unsigned int verbose=0;
int loop=1;
int delay=0;
int i=0;
Cmdline *cmd = parseCmdline(argc, argv);
if (cmd->show_helpP) usage();
if (cmd->show_versionP)
{
printf("%s %s\n", argv[0], VERSION);
exit(0);
}
if (cmd->verboseP)
{
verbose=1;
}
if (cmd->blinkP)
{
loop=atoi(cmd->blink[0]);
delay=atoi(cmd->blink[1]);
/* Okay the blink variable was set */
}
/* Request access to the parallel port */
if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
/* Read the current status of the parallel port */
signal=inb(BASEPORT);
if (verbose==1)
{
printf("status: %d\n", signal);
}
for(i=0;i
{
/* This LED is the iS1 LED */
if (strcmp(cmd->led1,"on")==0)
signal |= LED1;
if (strcmp(cmd->led1,"off")==0)
signal &= ~LED1;
if (strcmp(cmd->led1,"toggle")==0)
signal ^= LED1;
/* Do something to LED 1 */
}
if (cmd->led2P)
{
/* This LED is the green bottom LED */
if (strcmp(cmd->led2,"on")==0)
signal |= LED2;
if (strcmp(cmd->led2,"off")==0)
signal &= ~LED2;
if (strcmp(cmd->led2,"toggle")==0)
signal ^= LED2;
}
if (cmd->led3P)
{
if (strcmp(cmd->led3,"on")==0)
signal |= LED3;
if (strcmp(cmd->led3,"off")==0)
signal &= ~LED3;
if (strcmp(cmd->led3,"toggle")==0)
signal ^= LED3;
}
if (cmd->led4P)
{
if (strcmp(cmd->led4,"on")==0)
signal |= LED4;
if (strcmp(cmd->led4,"off")==0)
signal &= ~LED4;
if (strcmp(cmd->led4,"toggle")==0)
signal ^= LED4;
}
if (cmd->allP)
{
if (strcmp(cmd->all,"on")==0)
signal |= ALL;
if (strcmp(cmd->all,"off")==0)
signal &= ALL;
if (strcmp(cmd->all,"toggle")==0)
signal ^= ALL;
}
if (verbose==1)
{
printf("sending %d\n",signal);
}
outb(signal, BASEPORT);
// outb(signal,BASEPORT+2);
if (verbose==1)
{
printf("status: %d\n", inb(BASEPORT));
}
usleep(delay);
}
/* Sleep for a while (100 ms) */
usleep(100000);
/* We don't need the ports anymore *
*/
if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
exit (0);
}
Saturday, September 1, 2001
wrote a cool little program for switching led's on and off
at
Saturday, September 01, 2001
Posted by
Myron Davis
0
comments
Subscribe to:
Posts (Atom)
