home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / sercom / comparm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-04  |  1.4 KB  |  62 lines

  1. #define PORTBASE 0x03F8        /* For COM1. 0x02F8 for com2    */ 
  2.  
  3. comparm(baudrate, parity, stop, databits)
  4.  
  5. int baudrate;                   /* 110 through 9600                */
  6. int parity;                     /* 0 = None, 1 = Odd, 2 = even     */
  7. int stop;                       /* 1 or 2                          */
  8. int databits;                   /* 5 through 8                     */
  9. {
  10. unsigned char parmbyte;
  11. unsigned int divisor;
  12. unsigned char lsb, msb;
  13.  
  14. /* First, calculate the baud rate divisor */
  15.  
  16.     divisor = 115200 / baudrate;
  17.     msb = divisor >> 8;
  18.     lsb = (divisor << 8) >> 8;
  19.  
  20. /*
  21. * Enable access to the divisor latches by setting 
  22. * The Divisor Latch Access Bit in the Line Control Register
  23. */
  24.  
  25.     outp(PORTBASE + 3, 128);
  26.  
  27. /* Set the Least Significant Byte */
  28.  
  29.     outp(PORTBASE, lsb);
  30.  
  31. /* Set the Most Significant Byte */
  32.  
  33.     outp(PORTBASE + 1, msb);
  34.  
  35. /* Start to calculate the parameter byte */
  36.  
  37. /* 
  38. * First, the word length. This occupies bits 0 and 1 of the parameter byte
  39. * from 0 0 for 5 bit words to 1 1 for 8 bit words
  40. */
  41.  
  42.     parmbyte = databits - 5;
  43.  
  44. /* Next the stop bits */
  45.  
  46.     parmbyte |= (stop - 1) << 2;
  47.  
  48. /* Now the Parity */
  49.  
  50.     if (parity) parmbyte |= 8;        /* Parity Enable    */
  51.  
  52.     if (parity == 2) parmbyte |= 16;    /* Even         */
  53.  
  54.         outp(PORTBASE + 3, parmbyte);           /* Write it to UART     */   
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. /* Figure 16.6: Set Port Parameters, Direct Control Version */
  62.