Thread: Serial pot communication through c program

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    99

    Serial pot communication through c program

    Dear experts ,

    please help me i want to connect tp serial port and want to read the data from that , itried like this:

    Code:
    #include <dos.h>
    #include <stdio.h>
    #include <conio.h>
    
    #define PORT1 0x3F8
    
      /* Defines Serial Ports Base Address */
      /* COM1 0x3F8                        */
      /* COM2 0x2F8			       */
      /* COM3 0x3E8			       */
      /* COM4 0x2E8			       */
    
    void main(void)
    {
     int c;
     int ch;
     outportb(PORT1 + 1 , 0);   /* Turn off interrupts - Port1 */
    
     /*         PORT 1 - Communication Settings         */
    
     outportb(PORT1 + 3 , 0x80);  /* SET DLAB ON */
     outportb(PORT1 + 0 , 0x03);  /* Set Baud rate - Divisor Latch Low Byte */
    			      /* Default 0x03 =  38,400 BPS */
    			      /*         0x01 = 115,200 BPS */
    			      /*         0x02 =  57,600 BPS */
    			      /*         0x06 =  19,200 BPS */
    			      /*         0x0C =   9,600 BPS */
    			      /*         0x18 =   4,800 BPS */
    			      /*         0x30 =   2,400 BPS */
     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 */
    
     printf("\nSample Comm's Program. Press ESC to quit \n");
     
     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("%c",ch);}    /* Print Char to Screen          */
                                           /*%d
          if (kbhit()){ch = getch();         /* If key pressed, get Char */
                       outportb(PORT1, ch);} /* Send Char to Serial Port */
    
        }while (ch !=27); /* Quit when ESC (ASC 27) is pressed */
    }
    but i am not getting the desired results means no results only please help me
    how to connect to COM1 serail port and how to check its output,

    please help me

    with regards,
    vidya.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    http://msdn.microsoft.com/en-us/library/ms810467.aspx

    In case you are using Turbo-C++ or some other ancient compiler - it's time to upgrade.

    gg

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    new thread here - this one is closed.
    http://cboard.cprogramming.com/showthread.php?t=110685
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 Serial Communication & DeviceIoControl()
    By button_basher in forum Networking/Device Communication
    Replies: 1
    Last Post: 12-01-2005, 09:37 PM
  2. C Serial Communication BCD
    By ZoomCities in forum C Programming
    Replies: 1
    Last Post: 10-13-2005, 07:00 PM
  3. Bioscom serial communication
    By PierreB in forum C Programming
    Replies: 1
    Last Post: 10-24-2004, 10:04 AM
  4. Replies: 1
    Last Post: 10-13-2004, 12:15 PM
  5. Need help or info about serial port communication
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 01-08-2002, 01:48 PM