home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / ucsdmagiscan2 / rs232.text < prev    next >
Text File  |  2011-08-11  |  3KB  |  162 lines

  1.  
  2. (*$S+*)
  3.  
  4. { This unit contains the subroutines necessary for
  5.   accessing/using the RS232 interface of the Magiscan }
  6.  
  7. Unit RS232;
  8.  
  9.  Written by H Balen 1-Aug-85 
  10.  Modified by H Balen 23-Sep-85 
  11.  
  12. Interface
  13.  
  14.  
  15. Uses
  16.   M2Types,M2IpRoot,M2Sys;
  17.  
  18. var
  19.   MuxDelay    : integer;
  20.  
  21.   procedure InitM;
  22.  
  23.   function ISTATR : boolean;
  24.  
  25.   function ISTBRR : boolean;
  26.  
  27.   function ISTBOR : boolean;
  28.  
  29.   function ISTBFE : boolean;
  30.  
  31.   function ISTBTR : boolean;
  32.  
  33.   procedure SNDBBT( BT : char );
  34.  
  35.   procedure SNDABT( BT : char );
  36.  
  37.   function RCVBBT : Char;
  38.  
  39.  
  40.  
  41. Implementation
  42.  
  43. { All the routines below have the same function as those
  44.   in the text file WDPROCS for the UCM version of kermit }
  45.  
  46. const
  47.   RxBit   = 4;
  48.   TxBit   = 5;
  49.   Uart    = 56;
  50.   Control = 57;
  51.   Status  = 57;
  52.  
  53.   { RS232 dependant constants for the status registar }
  54.   OverError = 4;
  55.   FrameError = 5;
  56.  
  57. type
  58.   RegByte = record
  59.                case Boolean of
  60.                  True : ( Value : integer );
  61.  
  62. (* ---------------------------------------------------- *)
  63.  
  64. function ISTBOR;
  65.   Is it true that data OverRun occurred ?,
  66.  
  67. var
  68.   Byte : RegByte;
  69.  
  70. begin
  71. Byte.Value := IORead(Status);
  72. ISTBOR := Byte.B[OverError]
  73. end{ISTBOR};
  74.  
  75. (* ---------------------------------------------------- *)
  76.  
  77. function ISTBFE;
  78.  Is it true that Framing-Error occured? 
  79.  
  80. var
  81.   Byte  : RegByte;
  82.  
  83. begin
  84. Byte.Value := IORead(Status);
  85. ISTBFE := Byte.B[FrameError]
  86. end{ISTBFE};
  87.  
  88. (* ---------------------------------------------------- *)
  89.  
  90. function ISTBTR;
  91.  Is it true that transmit is ready ? 
  92.  
  93. begin
  94. ISTBTR := not IOStatus(TxBit)
  95. end{ISTBR};
  96.  
  97. (* ---------------------------------------------------- *)
  98.  
  99. procedure InitM;
  100.  This initialises the RS232 port 
  101.  
  102. begin
  103. IOWrite(64,Control); { Internal Reset }
  104. IOWrite(78,Control); { Set the mode }
  105. IOWrite(55,Control); { Error Reset }
  106. BaudRate(1200);
  107. MuxDelay := 0;
  108. end{RSInit};
  109.  
  110. (* ---------------------------------------------------- *)
  111.  
  112. procedure SNDBBT;
  113. { After getting back a TRUE result from isttr, this function
  114.   SNDBBT is used to actually send the byte of data from the
  115.   CPU to the device. Note that any attempt to call SNDBBT before
  116.   getting TRUE from isttr can result in clobering the previous
  117.   data }
  118.  
  119. var
  120.   i   : integer;
  121.  
  122. begin
  123. for i := 0 to (10 * MuxDelay) do;
  124. [UnitWrite(8,i,1);
  125. IOWrite(ord(BT),Uart);
  126. end{SendToUART};
  127.  
  128. (* ---------------------------------------------------- *)
  129.  
  130. procedure SNDABT;
  131.  Same as the SNDBBT except this is for the keyboard 
  132.  
  133. const
  134.   Ret  = 13;
  135.   LF   = 10;
  136.  
  137. begin
  138. if ord(BT) <> Ret then
  139.   if ord(BT) = LF then{ If we have a LF then }
  140.     write(chr(Ret)) { send a CR instead }
  141.    else
  142.      write(BT) { else send the character itself }
  143. end{SNABT};
  144.  
  145. (* ---------------------------------------------------- *)
  146.  
  147. function RCVBBT;
  148.  
  149. var
  150.   Ch    : char;
  151.  
  152. begin
  153. RCVBBT := chr( IORead(Uart) )
  154. {UnitRead(7,Ch,1);
  155. RCVBBT := Ch}
  156. end{RxUART};
  157.  
  158. (* ---------------------------------------------------- *)
  159.  
  160. end{RS232}.
  161.  
  162.