Gestione dell' interfaccia RS232 del PC

L'interfaccia seriale generalmente composta da una UART 8250 o dalla pi recente UART 16550 .

Nel PC possono coesistere sino a 4 seriali, ognuna risponde ad un determinato campo di indirizzi I/O:

Porta Indirizzo
COM1 da 3F8 a 3FF
COM2 da 2F8 a 2FF
COM3 da 3E8 a 3EF
COM4 da 2E8 a 2EF

Il pilotaggio di tale periferiche si pu effettuare direttamente tramite:

INT 14h, 00h (00) Initialize Serial Port Parameters
INT 14h, 01h (1) Send One Character
INT 14h, 02h (2) Receive One Character
INT 14h, 03h (3) Get Serial Port Status

Gli interrupt si possono richiamare in programmazione assembler ma anche con linguaggi evoluti sotto vi un esempio col Turbo Pascal.


INT 14h, 00h (00) Initialize Serial Port Parameters

Initializes the baud rate, parity, stop-bit, and word length parameters for a serial port, and returns the status for the port.

On entry: AH 00h
AL Communications parameters (see below)
  Serial port number (0 - COM1, 1 - COM2, etc.)
Returns: AX Line and modem status (see Service 03h)

 

7 6 5 Baud rate 4 3 Parity 2 Stop bits 1 0 Word Length
0 0 0 110 0 0 None 0 One 1 0 7 bits
0 0 1 150 0 1 Odd 1 Two 1 1 8 bits
0 1 0 300 1 0 None          
0 1 1 600 1 1 Even          
1 0 0 1200                
1 0 1 2400                
1 1 0 4800                
1 1 1 9600                

INT 14h, 01h (1) Send One Character

Sends one character to the specified serial port.

On entry: AH 01h
  AL Character
  DX Serial port number (0 - COM1, 1 - COM2, etc.)
Returns: AH Line status (see Service 03h)

If an error occurs, bit 7 of AH will be set. SInce bit 7 is used as a general error flag, this service is unable to identify a time-out error. For complete diagnostic information, use Service 03h (Get serial port status).

Osservazioni:
Abilita RTS e DTR (+12V) e prima di spedire il carattere aspetta che DSR e CTS diventino attivi (+12V). L'attesa dei due segnali dura per il tempo in secondi definito nella tabella
Time-Out Values for RS-232 Communications Lines dopo di che se l'esito negativo risponde con errore di Time-Out.


INT 14h, 02h (2) Receive One Character

Receives one character at the specified serial port.

On entry: AH 02h
DX Serial port number (0 - COM1, 1 - COM2, etc.)
Returns: AL Character
AH Line status (See service 03h)

Notes:
This service waits for a character. If no character is available or an error occurs, no character is returned and bit 7 of AH is set. If an error occurs, bit 7 of AH is set. SInce bit 7 is used as a general error flag, this service is unable to identify a time-out error.
For complete diagnostic information, use Service 03h (Get serial port status).

Osservazioni:
Abilita DTR ed aspetta DSR ed il flag di buffer carattere pieno poi legge il dato ricevuto.


INT 14h, 03h (3) Get Serial Port Status

Returns line status and modem status information for a specified serial port.

On entry: AH 03h
  DX Serial port number (0 - COM1, 1 - COM2, etc.)
Returns: AX Line and Modem status (See below)

Status information is returned in AX, as follows:

AH (Line status) AL (Modem status)
7 6 5 4 3 2 1 0   7 6 5 4 3 2 1 0  
1 . . . . . . . Time-out error 1 . . . . . . . Received line signal detect
. 1 . . . . . . Transfer shift register empty . 1 . . . . . . Ring indicator
. . 1 . . . . . Transfer holding register empty . . 1 . . . . . Data set ready
. . . 1 . . . . Break-detect error . . . 1 . . . . Clear to send
. . . . 1 . . . Framing error . . . . 1 . . . Change in receive line signal detected
. . . . . 1 . . Parity error . . . . . 1 . . Trailing edge ring detector
. . . . . . 1 . Overrun error . . . . . . 1 . Change in data set ready
. . . . . . . 1 Data ready . . . . . . . 1 Change in clear to send

If bit 7 of the Line status byte (AH) is set, then the rest of the bits in AH and AL are unpredictable.

Notes:
Early versions of the ROM-BIOS for the original PC had a programming error that would cause "time-out" errors to be reported as "transfer shift register empty" and "break-detect" errors. This has been corrected in all other versions of the ROM-BIOS.


0:47Ch Time-Out Values for RS-232 Communications Lines

Length: 4 bytes

These bytes are used to test when the RS-232 Communications lines will time-out.

These bytes are used to test when the RS-232 Communications lines will time-out. These values are usually 01h. On the PC and XT, these values tend to represent the number of seconds before a time-out. On other machines, such as the AT, these values are still 01h, but in the time-out test, these values are multiplied by 4 to compensate for the increased speed of the AT. However, the actual number of seconds before a time-out situation is about twice the time-out values stored here. In any case, these values should NOT be looked on as the number of seconds before a time-out, but instead should represent the amount of time needed to detect a time-out situation.

0:47Ch Serial Port #1 Time-out Value (COM1)
0:47Dh Serial Port #2 Time-out Value (COM2)
0:47Eh Serial Port #3 Time-out Value (COM3)
0:47Fh Serial Port #4 Time-out Value (COM4)

Programma per gestione degli interrupt tramite Pascal

uses crt,dos,convers;
var
  reg:registers;
  ax:word;
  c:byte;

Function Stato(Porta:byte):word;
Begin
  reg.ah:=3;
  reg.dx:=Porta;
  intr($14,reg);
  Stato:=Reg.Ax;
end;

Procedure AzzeraDtr(Porta:byte);
Begin
  Port[$3FC-(Porta*$100)]:=Port[$3FC-(Porta*$100)] and ($ff-1)
end;

procedure InitSer(Porta,Modo:Byte);
Begin
  reg.al:=Modo;
  reg.ah:=0;
  reg.dx:=Porta;
  intr($14,reg);
end;

Function Trasmette(Porta,c:Byte):boolean;
begin
  reg.al:=c;
  reg.ah:=1;
  reg.dx:=Porta;
  intr($14,reg);
  if reg.ah and $80>0 then
  Begin
    ax:=Stato(Porta);
    if ax and $20=0 then Writeln('Manca DSR in trasmissione');
    if ax and $10=0 then Writeln('Manca CTS in trasmissione');
    Trasmette:=False;
  end
  else
    Trasmette:=True;
end;

Function Riceve(Porta:byte;Var c:Byte):boolean;
begin
  reg.ah:=2;
  reg.dx:=Porta;
  intr($14,reg);
  if reg.ah and $80>0 then
  Begin
    ax:=Stato(Porta);
    if ax and $20=0 then Writeln('Manca DSR in ricezione');
    if ax and $100=0 then Writeln('Rx Buffer vuoto');
    Riceve:=False;
  end
  else
    Riceve:=True;
  c:=reg.al;
end;
begin 
end.