RS232COM.H
上传用户:gofo119
上传日期:2007-01-03
资源大小:5k
文件大小:2k
源码类别:

串口编程

开发平台:

DOS

  1. *****Listing 1*****
  2. /*
  3.  *  COM.H
  4.  *
  5.  *  Copyright (C) Mark R. Nelson 1990
  6.  *
  7.  * This file contains the structure definitions, constants,
  8.  * and function prototypes needed to use the RS-232
  9.  * interface code supplied in COM.C.  It should be included
  10.  * by any routine using COM.C procedures.
  11.  */
  12. /*
  13.  * This structure defines the 256 byte buffer used for
  14.  * I/O buffers by the COM routines.  By using a buffer
  15.  * size of 256 bytes, updating the indices is simplified.
  16.  */
  17. typedef struct {
  18.                  char buffer[256];
  19.                  unsigned char write_index;
  20.                  unsigned char read_index;
  21.                } BUFFER;
  22. /*
  23.  * This structure defines a COM port.  It is initialized
  24.  * when the port is opened with port_open().
  25.  */
  26. typedef struct {
  27.                  void (interrupt far * old_vector)();
  28.                  int                   uart_base;
  29.                  int                   irq_mask;
  30.                  int                   interrupt_number;
  31.                  BUFFER                in;
  32.                  BUFFER                out;
  33. } PORT ;
  34. /*
  35.  * the ifdef M_186 is checking for Microsoft C/QuickC.
  36.  * Borland and Microsoft differ slightly on the names of
  37.  * some of the DOS specific procedure names, and the
  38.  * fixing up is done here.
  39.  */
  40. #ifdef M_I86
  41. #define inportb inp
  42. #define outportb outp
  43. #define getvect _dos_getvect
  44. #define setvect _dos_setvect
  45. #define enable _enable
  46. #endif
  47. /*
  48.  * The fully qualified function prototypes.  All of these
  49.  * routines actually reside in COM.C
  50.  */
  51. PORT *port_open( int address, int interrupt_number );
  52. void port_set( PORT *port,
  53.                long speed,
  54.                char parity,
  55.                int data,
  56.                int stopbits );
  57. void port_close( PORT *port );
  58. int port_putc( unsigned char c, PORT *port );
  59. int port_getc( PORT *port );
  60. /*
  61.  * These are the standard UART addresses and interrupt
  62.  * numbers for the two IBM compatible COM ports.
  63.  */
  64. #define COM1_UART         0x3f8
  65. #define COM1_INTERRUPT    12
  66. #define COM2_UART         0x2f8
  67. #define COM2_INTERRUPT    11