[PARPORT] status register problem..

From: Angela (busybird@ihug.co.nz)
Date: Tue Sep 04 2001 - 07:36:43 EDT

  • Next message: Tim Waugh: "[PARPORT] PPSCSI still looking for a new maintainer"

    hi all,

    i'm doing a project for my engineering degree & a part of it requires me to be able to read & write things onto a rippet board through the parallel port. (the rippet board is a circuit board with lots of things attached to it eg. lcds & keypad) i'm quite desperate as my project is due soon... i need to use ioperm instead of comedi which was what the original code uses & has been tested to work correctly. i've successfully been able to write to the lcd using ioperm & outbs but is yet unable to read anything from the keypad due to problems with the status register..

    description of my problem:-

    my readnumber() uses getkey() to get the number typed in by the keypad. getkey() then uses inp() to obtain the values from the status register. it got stuck in the while loop inside getkey() because inp() keeps on getting the same value (15) from the status register even though i've pressed a key.. it just keeps on waiting for a key to be pressed. i'm certain that my keypad is working properly & i know that it probably is due to problems reading the bits in the status register. but i've no idea how to change it. please help.

    it would also be quite helpful if someone can tell me how exactly the status register works when something happens, i've a general idea but that's it. thx in advance.

    angela

    main code:-
    ---------------------------------------------
    f (ioperm(DATA,3,1)) {
        printf("Sorry, you were not able to gain access to the ports.\n");
        printf("You must be root to run this program.\n"); exit(1);
    }
    num=readnumber();
    ----------------------------------------------
    // Read from pport status register
    //int inp (void)
    int char inp (void)
    {
       int value;
       value = inb(STATUS);
       value^=0x10;
       value>>=1;
       value&=0x0f;
       return (value);
    }

    // Inputs up to 4-digit number from the keypad.
    // Converts it to a float type.
    // the * key is used as a decimal point
    // Use the # key to 'enter' the number.
    float readnumber (void)
    {
       float f;
       int i;
       char valuestr[5];
       cursor (CURON);
       for (i=0; i<4; i++)
       {
          valuestr[i]=itoa (getkey (BUSYWAIT)); // cannot finish getkey..

    ..... not finished........

    // This function either busy waits until a key has been pressed,
    // or scans the keypad once
    // use input parameter of BUSYWAIT or SINGLE.
    // param = BUSYWAIT = 1 will wait till a key is pressed
    // param = SINGLE = 2 checks that key is pressed
    int getkey (int param)
    {
       int i; unsigned char i;
       unsigned char value, row, col, addr=-1;
       int cnt = 0;
       out_c (1);
       for (i=1, col=3; ; i<<=1, col--)
       {
            printf("inside getkey loop, i = %d col = %d\n", i,col);
          if (param==BUSYWAIT && i==8) { i=1; col=3; }
          else if (param==SINGLE && i==8) break;
          out_d(i);
          usleep(1);
          value=inp ();
          if (value)
          {
             if (value&0x8) row=2;
             else if (value&0x4) row=3;
             else if (value&0x2) row=1;
             else if (value&0x1) row=0;
             addr=row*3+col;
             break;
          }
       }
       while (1)
       {
          value=inp(); // got stuck in here bec value received from status register is always 15 even though a key is pressed
          cnt++;
          if (value==0) break;
       }
       return addr;
    }

    -- To unsubscribe, send mail to: linux-parport-request@torque.net --
    -- with the single word "unsubscribe" in the body of the message. --



    This archive was generated by hypermail 2b29 : Tue Sep 04 2001 - 07:39:13 EDT