home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / sercom / calcparm.c next >
Encoding:
Text File  |  1986-09-04  |  1.3 KB  |  42 lines

  1.  
  2. unsigned char calcparm(baudrate, parity, stop, databits)
  3.  
  4. int baudrate;       /* 110 through 9600                */
  5. int parity;         /* 0 = None, 1 = Odd, 2 = even     */
  6. int stop;           /* 1 or 2                          */
  7. int databits;       /* 7 or 8                          */
  8. {
  9. static int baudlist[] = {110, 150, 300, 600, 1200, 244, 4800, 9600};
  10. register int i = 0;
  11. register int parmbyte;
  12.  
  13.      for (i = 0; i <= 7; ++i) {         /* For each valid baud rate */
  14.           if (baudlist[i] == baudrate) 
  15.                break;
  16.      }
  17.  
  18. /* i now equals a number from zero through 7 representing the baud rate */
  19.      
  20.  
  21.      parmbyte = i << 5;                 /* Shift the value left to the most 
  22.                                            significant three bytes      */
  23.  
  24.      parmbyte |= (parity << 3);         /* Bits 3 and 4 represent 
  25.                                            parity                       */
  26.  
  27.      parmbyte |= ((stop - 1) << 2);     /* Bit 2                        */
  28.  
  29.      parmbyte |= 2;                     /* Bit 1 always 1               */
  30.  
  31.      if (databits == 8) 
  32.           ++parmbyte;                   /* Bit zero                     */ 
  33.  
  34.      return(parmbyte);
  35. }
  36.  
  37.  
  38.  
  39. /* Figure 16.5: Calculate Parameter Byte using ROM-BIOS */
  40.  
  41.  
  42.