home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / baudctrl.bas < prev    next >
Encoding:
BASIC Source File  |  1994-05-01  |  2.8 KB  |  62 lines

  1. '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  2. '  Msg#: 474                                          Date: 26 Apr 94  11:28:00
  3. '  From: Mark Pruitt                                  Read: Yes    Replied: No 
  4. '    To: Robert Fisher                                Mark:                     
  5. '  Subj: Baud
  6. '──────────────────────────────────────────────────────────────────────────────
  7. 'JK>RF> How come QB only accepts the speed 9600bps?  Is it possible
  8.  
  9. OPEN "COM1:300" FOR RANDOM AS #10 
  10. BaudControl(1,1,57600,ErrCode%) 
  11.  
  12. '*AND* if you're in a really really good mood, open COM2 too: 
  13. OPEN "COM2:300" FOR RANDOM AS #10 
  14. BaudControl(1,2,115200,ErrCode%) 
  15.  
  16. SUB BaudControl (Func%, Port%, X.Baud&, ErrCode%) STATIC 
  17.    'INPUT: Func%=0  -  return the current baud rate in BAUD 
  18.    '       Func%=1  -  set the baud rate from BAUD 
  19.    'See the Serial/Parallel Adapter TechRef for details 
  20.  
  21.     baud& = X.Baud& 
  22.     ErrCode% = 0 
  23.    'the error trapping isn't necessary for most applications. 
  24.    'these errors should be found in the debug cycle 
  25.     IF (Port% < 1 OR Port% > 2) THEN  'bad port params 
  26.       ErrCode% = -1 
  27.     ELSEIF baud& < 100 THEN 
  28.       ErrCode% = -2 
  29.     ELSEIF Func% < 0 OR Func% > 1 THEN  'added error code completes 
  30.                                         'trapping 
  31.       ErrCode% = -3 
  32.     ELSE 
  33.       Addr% = &H4F8 - (&H100 * Port%)    ' base address of port reg's 
  34.       AddrLCR% = Addr% + 3               ' Line Control Register 
  35.       AddrDivLatchLSB% = Addr% + 0       ' Divisor Latch LSB & MSB 
  36.       AddrDivLatchMSB% = Addr% + 1       ' Divisor Latch LSB & MSB 
  37.       ValLCR% = INP(AddrLCR%)            ' get old LCR value 
  38.       OUT AddrLCR%, ValLCR% AND &H7F     ' Disable DLAB to get to inters 
  39.       ValInt% = INP(AddrDivLatchMSB%)    ' Get the int enable statuses 
  40.       OUT AddrDivLatchMSB%, 0            ' Disable all modem intertupts 
  41.       OUT AddrLCR%, ValLCR% OR &H80      ' Enable DLAB to gain access 
  42.       SELECT CASE Func%
  43.  
  44.         CASE 1  'set baud 
  45.           Divisor% = 115200 \ baud&       'magic number for baud rate 
  46.           MSB = Divisor% \ 256 
  47.  
  48.           LSB = Divisor% MOD 256 
  49.           OUT AddrDivLatchMSB%, MSB 
  50.           OUT AddrDivLatchLSB%, LSB      ' put out the new baud rate 
  51.         CASE 0                           'get the current baud rate 
  52.           MSB = INP(AddrDivLatchMSB%) 
  53.           LSB = INP(AddrDivLatchLSB%)    'get old baud rate 
  54.           Divisor% = MSB * 256 + LSB 
  55.           X.Baud& = 115200 / Divisor% 
  56.       END SELECT 
  57.       OUT AddrLCR%, ValLCR% AND &H7F      'Disable DLAB to get to inters 
  58.       OUT AddrDivLatchMSB%, ValInt%       'Replace orig inter values 
  59.       OUT AddrLCR%, ValLCR%               'Replace orig LCR values 
  60.     END IF 
  61. END SUB 
  62.