Serial port IRQ

Posted on 1997-03-27
Last Modified: 2006-11-17
Could someone teach me how to enable and use the serial port IRQ. I need this to detect whether there a transmitting or receiving error (like parity error, etc). I'm using turbo C on a 286/386 PC. I would appreciate if you could include some examples.

Thanks ;)

Question by:sky123
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

emmons earned 100 total points
ID: 1249778
unsigned _bios_serialcom( unsigned service, unsigned serial_port, unsigned data );
service Communications service
serial_port Serial port to use
data Port configuration bits
#include <bios.h>
The _bios_serialcom routine provides serial communications services using INT 0x14. The serial_port argument is set to 0 for COM1, to 1 for COM2, and so on. The _bios_serialcom routine may not be able to establish reliable communications at baud rates in excess of 1200 baud ( _COM_1200) due to the overhead associated with servicing computer interrupts. Faster data communication rates are possible with more direct programming of serial-port controllers. For more details on serial-communications programming in C, see C Programmer's Guide to Serial Communications. (More information on this book is found in Other Books of Interest)
The service argument can be set to one of the following manifest constants:
·      _COM_INIT Sets the port to the parameters specified in the data argument
·      _COM_SEND Transmits the data characters over the selected serial port
·      _COM_RECEIVE Accepts an input character from the selected serial port
·      _COM_STATUS Returns the current status of the selected serial port
The data argument is ignored if service is set to _COM_RECEIVE or _COM_STATUS. The data argument for _COM_INIT is created by combining (with the OR operator) one or more of the following constants:
·      _COM_CHR7  7 data bits
·      _COM_CHR8 8 data bits
·      _COM_STOP1 1 stop bit
·      _COM_STOP2 2 stop bits
·      _COM_NOPARITY No parity
·      _COM_EVENPARITY Even parity
·      _COM_ODDPARITY Odd parity
·      _COM_110 110 baud
·      _COM_150 150 baud
·      _COM_300 300 baud
·      _COM_600 600 baud
·      _COM_1200 1200 baud
·      _COM_2400 2400 baud
·      _COM_4800 4800 baud
·      _COM_9600 9600 baud
The default value of data is 1 stop bit, no parity, and 110 baud.
Return Value
The function returns a 16-bit integer whose high-order byte contains status bits. The meaning of the low-order byte varies, depending on the service value. The high-order bits, following, have these meanings:
·      15 Timed out
·      14 Transmission-shift register empty
·      13 Transmission-hold register empty
·      12 Break detected
·      11 Framing error
·      10 Parity error
·      9 Overrun error
·      8 Data ready
When service is _COM_SEND, bit 15 is set if data could not be sent. When service is _COM_RECEIVE, the byte read is returned in the low-order bits if the call is successful. If an error occurs, any of the bits 9, 10, 11, or 15 is set. When service is _COM_INIT or _COM_STATUS, the low-order bits are defined as follows:
·      7 Receive-line signal detected
·      6 Ring indicator
·      5 Data set ready
·      4 Clear to send
·      3 Change in receive-line signal detected
·      2 Trailing-edge ring indicator
·      1 Change in data-set-ready status
·      0 Change in clear-to-send status
Note that this function works only with IBM personal computers and true compatibles.
ANSI    MS-DOS    QWIN    UNIX    WIN    WIN DLL        
/* BSERIALC.C: This program checks the status of serial port COM1. */

#include <bios.h>
#include <stdio.h>

void main( void )
   unsigned com1_status;

   com1_status =  _bios_serialcom( _COM_STATUS, 0, 0 );
   printf ( "COM1 status: 0x%.4x\n", com1_status );

Another possiblilty

/* Compile options needed: none
 - The following program is a simple example which sends and receives
   one character to/from COM1:
#include <stdio.h>
#include <bios.h>
void main(void)
    unsigned com1_status;
    unsigned com1_send;
    unsigned com1_rec;
    unsigned com1_init;
    int result, mask;
    /* open serial port at 1200 baud, 8 data bits,
    ** No parity, 1 stop bit */
    com1_init = _bios_serialcom(_COM_INIT, 0,
        _COM_CHR8 | _COM_NOPARITY | _COM_STOP1 | _COM_1200);
    printf("Init status: 0x%4.4X\n", com1_init);
    /* send an '*' to com1 */
    com1_send = _bios_serialcom(_COM_SEND, 0, '*');
    printf("Send status: 0x%4.4X\n", com1_send);
    mask = 0x6100;
    /* value used to mask:
    *    bits 0-7 are related to modems,
    *    bits 8-15 are for port status,
    *      check to see that the following bits are set:
    *         8 (data ready)
    *        13 (Transmission-hold  register empty)
    *        14 (Transmission-shift register empty)
    /* check the status */
    com1_status = _bios_serialcom(_COM_STATUS, 0, 0);
    printf("COM1 status: 0x%4.4X\n", com1_status);
    /* wait until a character is ready */
    do {
        /* check the status */
        com1_status = _bios_serialcom(_COM_STATUS, 0, 0);
        /* mask off the low order byte of com1_status */
        com1_status = com1_status & 0xFF00;
    } while( (mask & com1_status) == 0);
    /* get a character */
    com1_rec =  _bios_serialcom(_COM_RECEIVE, 0, 0);
    printf("Read status: 0x%4.4X\n", com1_rec);
    /* print the character we just received */
    result = com1_rec & 0x00FF;
    printf("Character: 0x%2.2X  =  %c\n", result, (char)result);
These compiled and ran fine with my Borland 5.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question