Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Serial port programming using c in Win XP OS platform

arunadarunad Posts: 2Member
I am using ANSI style c code for creating a serial data front end with GUI for my embedded unit.
The code is developed from the standard ASCI C code for serial port programming.
/***********CODE**********************/
#include
#include
#include

#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("
Sample Comm's Program. Press ESC to quit
");

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 */

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 */
}
In all standard text books(Eg:The window serial port programming By YING BAI) it is clearly mentioned that the code will not run in Win NT/2000/XP OS platforms.But I could run the c code in the Win XP OS, and it is working!!!But the problem is that after some time it pauses, until a mouse movement or key board hit is detected).I turned off the screen saver and power saving mode for display.The same code works perfectly with MSDOS /Win 95/98 OS platforms (that is standard)with out any problem.Can you give the explanation and remedy(if available)for this problem? With warm regards Arun.A.D

Sign In or Register to comment.