[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: [rtl] linux push-button




Thomas Wuensche <wuensche@ems-wuensche.com> writes:

	The parallel input might produce a default 1 on the input.
	Thats standard TTL behaviour. Try to write a 0 to bit 8
	and test whether this changes the result read from the
	status port.

Indeed, things are opposite from what I expect. I do wish I could have
taken that hardware course after all. And compilers, and graphics, and
so on...

Again, thanks a bunch!

Paul Kienzle
pkienzle@cs.indiana.edu

-----------------------------------------------------------------------
/* Linux parallel port push buttons */
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>

#define LPT_BASE    0x378
#define LPT_DATA    (LPT_BASE)
#define LPT_STATUS  (LPT_BASE+1)
#define LPT_CONTROL (LPT_BASE+2) 

main()
{
  int old, new;

  /* Permit access to parallel port. */
  ioperm(LPT_BASE, 3, 1);

  /* Set data bit 8 low so closing circuit between pin 9 and 10 powers ACK */
  outb(0x7f, LPT_DATA);

  /* Process press/release */
  old = inb(LPT_STATUS);     /* Grab base status byte. */
  printf("Button is %s (stat=%x)\n", !(old&0x40)?"pressed":"released",old);
  for (;;) {
    new = inb(LPT_STATUS);     /* Grab current status byte. */
    if ((new^old)&0x40) {      /* Look for activity on bit 6. */
      printf("Button is %s (stat=%x)\n", !(new&0x40)?"pressed":"released",new);
      old = new;
    }
  }
}


--- [rtl] ---
For more information on Real-Time Linux see:
http://www.rtlinux.org/