Thread: serial interface problem

  1. #1
    Registered User phoneix's Avatar
    Join Date
    Mar 2012

    serial interface problem

    hello everyone
    i am trying to interface my serial port with my project circuit but the program does not work at all.
    the program works fine in turbo c version 2 and the responses from my circuit are sent to my pc via the serial port.
    but when i use the same program in turbo c version 4.5 it does not work at all.
    following is my c code...please help
    #include <stdio.h>
    #include <conio.h>
    #define PORT1 0x3F8
    void main(void)
    char c,ch;
     outportb(PORT1 + 1 , 0);   /* Turn off interrupts - Port1 */
     outportb(PORT1 + 3 , 0x80);  /* SET DLAB ON */
     outportb(PORT1 + 0 , 0x02);  /* Set Baud rate - Divisor Latch Low Byte */
     outportb(PORT1 + 1 , 0x00);  /* Set Baud rate - Divisor Latch High Byte */
     outportb(PORT1 + 3 , 0x03);  /* 8 Bits, No Parity, 1 Stop Bit */
     outportb(PORT1 + 2 , 0xC7);  /* FIFO Control Register */
     outportb(PORT1 + 4 , 0x0B);  /* Turn on DTR, RTS, and OUT2 */
     do { c = inportb(PORT1 + 5);          /* Check to see if char has been  received.                     */
     if (c & 1)
            ch = inportb(PORT1); /* If so, then get Char          */
            printf("%x ",ch);
            if (kbhit())
          ch = getch();         /* If key pressed, get Char */
            } /* Send Char to Serial Port */
         } while (ch !=27); /* Quit when ESC (ASC 27) is pressed */

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Are you running both of these on top of windows (say XP or newer?)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User phoneix's Avatar
    Join Date
    Mar 2012
    yeah i am using windows xp sp3
    the program works with turbo v2 but not with turbo v4.5
    someone told me the port addresses are different in turbo v4.5 but i don't know what....

  4. #4
    Registered User
    Join Date
    May 2010
    Is the program you provided to run on your project board or the PC? If it is for you PC I suggest you consider the more modern Windows Serial API to control your serial port. Trying to use direct port access while using a modern Windows operating system is problematic. Here is a link to a document that describes how to use this API: Windows Serial Ports.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with c++, mplayer interface.
    By IM back! in forum C++ Programming
    Replies: 10
    Last Post: 02-21-2010, 02:20 PM
  2. serial port programming in vc++ and graphical interface
    By debkalyan in forum C++ Programming
    Replies: 2
    Last Post: 08-31-2006, 12:55 PM
  3. Replies: 1
    Last Post: 03-03-2006, 12:22 PM
  4. C++ Share Interface Problem
    By Morphios in forum C++ Programming
    Replies: 0
    Last Post: 04-28-2003, 07:30 PM
  5. Return Interface: problem
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2002, 05:03 PM

Tags for this Thread