/*
 *          __
 *         / /_______________  ____  ___
 *        / __/ ___/ ___/ __ \/ __ \/ _ \
 *       / /_(__  ) /__/ /_/ / /_/ /  __/
 *       \__/____/\___/\____/ .___/\___/
 *                         /_/
 *
 * michael stevens
 * 
 * test parallel driver
 * returns status of the registry
 * only needed when developing a response box 
 *
 * info about the parallel port can be found at
 *  http://www.ctv.es/pckits/tutorial.html#parallel
 * 
 *  tscope keys / bits / pins on the parallel ports
 *      (bits are counted from 0)
 *      
 *  status byte of parallel port 1 (0x379):
 *  P1 -> bit3 -> pin15 (1=high)
 *  P2 -> bit4 -> pin17 (1=high)
 *  P3 -> bit5 -> pin12 (1=high)
 *  P4 -> bit6 -> pin10 (1=high)
 *  P5 -> bit7 -> pin11 (1=high)
 *      
 *  status byte of parallel port 2 (0x279):
 *  PP1 -> bit3 -> pin15 (1=high)
 *  PP2 -> bit4 -> pin17 (1=high)
 *  PP3 -> bit5 -> pin12 (1=high)
 *  PP4 -> bit6 -> pin10 (1=high)
 *  PP5 -> bit7 -> pin11 (1=high)
 *      
 *  status byte of parallel port 3 (0x3BD):
 *  PPP1 -> bit3 -> pin15 (1=high)
 *  PPP2 -> bit4 -> pin17 (1=high)
 *  PPP3 -> bit5 -> pin12 (1=high)
 *  PPP4 -> bit6 -> pin10 (1=high)
 *  PPP5 -> bit7 -> pin11 (1=high)
 */


#include <tscope.h>
#include <tscope/internal.h>

int main()
{
    // initialize the screen
    ts_scrsize(SIZE1);
    ts_defkey(KEY_SPACE);
    ts_textmode(0);

    // open parallel ports without tscope 
    if (ioperm(PAR1STATUS, 1, 1))
        ts_fatal("error opening parallel port");
    if (ioperm(PAR2STATUS, 1, 1))
        ts_fatal("error opening parallel port");
    if (ioperm(PAR3STATUS, 1, 1))
        ts_fatal("error opening parallel port");

    // some instructions
    ts_printf_centre(0, YMAX - 20, "testpport.c");
    ts_printf_centre(0, YMAX - 20, "Status of the parallel ports:");

    ts_printf(-XMAX + 20, -YMAX + 170,
              "If a button is ON when pressed, use a P(PP)1-P(PP)5 definition");
    ts_printf(-XMAX + 20, -YMAX + 160,
              "If a buttons is OFF when pressed, use a IP(PP)1-IP(PP)5 definition");

    ts_printf(-XMAX + 20, -YMAX + 120,
              "If no box is connected, the values are undefined");

    ts_printf(-XMAX + 20, -YMAX + 80, "Read the source of this program");
    ts_printf(-XMAX + 20, -YMAX + 70, "for more information about");
    ts_printf(-XMAX + 20, -YMAX + 60, "the parallel posrt.");
    ts_printf(-XMAX + 20, -YMAX + 20, "Press space to exit.");


    ts_printf_centre(0, 180, "parallel port 1");
    ts_printf_centre(0, 100, "parallel port 2");
    ts_printf_centre(0, 20, "parallel port 3");

    // poll port
    int i, resp, boxhex;
    do {

        // pressing the spacebar stops the program
        resp = ts_respstatus();

        for (i = 0; i < 3; i++) {

            // read status byte of parallel port
            if (i == 0) {
                boxhex = inb(PAR1STATUS);
            } else if (i == 1) {
                boxhex = inb(PAR2STATUS);
            } else {
                boxhex = inb(PAR3STATUS);
            }

            if ((boxhex & 8) >> 3)
                ts_fgcolor(RED);
            else
                ts_fgcolor(WHITE);
            ts_printf_centre(0, 160 - 80 * i, "P(PP)1 (pin 15 / bit 3)");

            if ((boxhex & 16) >> 4)
                ts_fgcolor(RED);
            else
                ts_fgcolor(WHITE);
            ts_printf_centre(0, 150 - 80 * i, "P(PP)2 (pin 17 / bit 4)");

            if ((boxhex & 32) >> 5)
                ts_fgcolor(RED);
            else
                ts_fgcolor(WHITE);
            ts_printf_centre(0, 140 - 80 * i, "P(PP)3 (pin 12 / bit 5)");

            if ((boxhex & 64) >> 6)
                ts_fgcolor(RED);
            else
                ts_fgcolor(WHITE);
            ts_printf_centre(0, 130 - 80 * i, "P(PP)4 (pin 10 / bit 6)");

            if ((boxhex & 128) >> 7)
                ts_fgcolor(RED);
            else
                ts_fgcolor(WHITE);
            ts_printf_centre(0, 120 - 80 * i, "P(PP)5 (pin 11 / bit 7)");
        }
    } while (resp != 1);

    // close ports and exit
    ioperm(PAR1DATA, 3, 0);
    ioperm(PAR2DATA, 3, 0);
    ioperm(PAR3DATA, 3, 0);
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information