C Code help

Thread Starter

Xeeshan Qureshi

Joined Jan 13, 2009
14
Hi!
Days ago, I posted a query about bioscom() function in c++[turbo c], in reference with serial port programming. Though I was unable to get through with that problem but instead found outportb(), inportb() functions in c for the same purpose.
Following are the serial port settings which I copy pasted into my code and it worked. Now I want to understand these settings (i.e. the code)...
Please help me.

#define PORT1 0x3F8
outportb(PORT1 + 1 , 0);
outportb(PORT1 + 3 , 0x80);
outportb(PORT1 + 0 , 0x0c);
outportb(PORT1 + 1 , 0x00);
outportb(PORT1 + 3 , 0x03);
outportb(PORT1 + 2 , 0xC7);
outportb(PORT1 + 4 , 0x0B);
 

Mark44

Joined Nov 26, 2007
628
Hi!
Days ago, I posted a query about bioscom() function in c++[turbo c], in reference with serial port programming. Though I was unable to get through with that problem but instead found outportb(), inportb() functions in c for the same purpose.
Following are the serial port settings which I copy pasted into my code and it worked. Now I want to understand these settings (i.e. the code)...
Please help me.

#define PORT1 0x3F8
outportb(PORT1 + 1 , 0);
outportb(PORT1 + 3 , 0x80);
outportb(PORT1 + 0 , 0x0c);
outportb(PORT1 + 1 , 0x00);
outportb(PORT1 + 3 , 0x03);
outportb(PORT1 + 2 , 0xC7);
outportb(PORT1 + 4 , 0x0B);
This code writes bytes of data to five serial ports: 0x3F8, 0x3F9, 0x3FA, 0x3FB, and 0x3FC.

I found the same code as above on the internet, with comments, so that might help you understand the purpose of each line of code above. Here's a link to where this code appears: http://www.tek-tips.com/viewthread.cfm?qid=624898.
Rich (BB code):
/* This program is used to pull data from the serial port */

#include <dos.h>
#include <stdio.h>
#include <conio.h>

#define PORT1 0x3F8  /* Defines Serial Port Base Address (COM1 */

void main(void){
    unsigned char c = 0;
    unsigned char chrctr = 0;
    /*int exit = 1; */

    outportb(PORT1 + 1, 0); /* Turn off interrupts */

    /* PORT1 Communication Settings */

    outportb(PORT1 + 3, 0x80); /* Set DLAB ON */
    outportb(PORT1 + 0, 0x0C); /* Set the baud rate to 9600 */

    outportb(PORT1 + 1, 0x00); /* Set Baud - Divisor latch HIGH */
    outportb(PORT1 + 3, 0x03); /* 8 bits, no parity, 1 stop */
    outportb(PORT1 + 2, 0xC7); /* FIFO Control Register */
    outportb(PORT1 + 4, 0x0B); /* Turn on DTR, RTS, and OUT2) */
 
Top