LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 855|回复: 3

对并口的理解,即(调试并口程序)

[复制链接]
发表于 2003-10-25 18:35:03 | 显示全部楼层 |阅读模式
好像明白了些什么,如果你不会写正确的软件,那怎样才能弄好并口呢。所以想到要可以自由改变所有的状态位,数据位,控制位,就行了。
发表于 2003-10-25 22:06:52 | 显示全部楼层
再放上一些源码就更好了
 楼主| 发表于 2003-10-26 20:56:15 | 显示全部楼层
我也想,努力看书中
正在想在用户空间能不能实现中断功能。
 楼主| 发表于 2003-10-26 21:46:22 | 显示全部楼层
端口介绍:
http://www.doc.ic.ac.uk/~ih/doc/par/

Input from digital joystick to PC parallel port

Borland C/C++ version

  1. /* program readjs - input from digital joystick to PC parallel port
  2. *
  3. * compiled with Borland C++ version 3.1 under MS-DOS 6.22
  4. *
  5. * Copyright (c) 1997, Ian Harries and Imperial College, London, UK
  6. *
  7. * IBM-PC Parallel Printer Port Data & Status Registers
  8. * ====================================================
  9. *          7   6   5   4   3   2   1   0   I/O Port
  10. *        +---+---+---+---+---+---+---+---+
  11. * Data   | W | E | S | N | B | x | x | x | Base = 278/378/3BC Hex
  12. *        +---+---+---+---+---+---+---+---+
  13. * Status |~W | E | S | N | B | - | - | - | Base + 1
  14. *        +---+---+---+---+---+---+---+---+
  15. */

  16. #include <stdio.h>
  17. #include <conio.h> /* required only for function declarations */

  18. #define Data    0x378
  19. #define Status  Data + 1
  20. #define BS      8 /* ASCII BackSpace */

  21. void main() {
  22.     int JShigh, JSlow, i, oldbyte, newbyte;

  23.     char backspace = BS;

  24.     printf("\n");
  25.     printf("Ian's Parallel Port JoyStick Reader\n");
  26.     printf("===================================\n");
  27.     printf("\n");
  28.     printf("<Centre + Button> to Quit\n");
  29.     printf("\n");

  30.     oldbyte = 0xff; /* different from newbyte */

  31.     outportb(Data,0xf8); /* output TTL High on enable lines */

  32.     do {
  33.         newbyte = inportb(Status);

  34.         if (newbyte != oldbyte) { /* new joystick status */
  35.             oldbyte = newbyte;

  36.             for (i = 1; i <= 20; i++) { /* clear the previous status report */
  37.                 printf("%c",backspace); printf(" "); printf("%c",backspace);
  38.             }

  39.             JSlow  = (newbyte & 0x0f) >> 3; /*    Button Signal */
  40.             JShigh = (newbyte ^ 0x80) >> 4; /* Direction Signal */

  41.             switch (JShigh) {
  42.                 case  0: printf("Centre");
  43.                     break;
  44.                 case  1: printf("North");
  45.                     break;
  46.                 case  2: printf("South");
  47.                     break;
  48.                 case  4: printf("East");
  49.                     break;
  50.                 case  5: printf("NorthEast");
  51.                     break;
  52.                 case  6: printf("SouthEast");
  53.                     break;
  54.                 case  8: printf("West");
  55.                     break;
  56.                 case  9: printf("NorthWest");
  57.                     break;
  58.                 case 10: printf("SouthWest");
  59.             }

  60.             if (JSlow == 1)
  61.                 printf(" + Button");
  62.         }
  63.     }
  64.     while ((JSlow != 1) || (JShigh != 0));

  65.     printf("\n");
  66. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表