Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Replacing 'Bios.h' in VC++

Status
Not open for further replies.

Electrix

Member
I have written the foll code for transmitting data to the PC from a microcontroller..I ran the program in Turbo C 3.0, works fine. Now i want to run the same code in VC++. VC does not seem to recogonize 'bios.h'..what is the alternative to this ?
Code:
#include <stdio.h>
#include <conio.h>
#include <[color=red]bios.h[/color]>

#define SETTINGS (_COM_9600 | _COM_CHR8 | _COM_NOPARITY | _COM_STOP1)
/*BAUD RATE=9600, 8 BITS, NO PARITY, 1 STOP BIT */

void main(void)
{
unsigned  in,out,status;
int port;
clrscr();
printf("Select Port(Enter '0' for COM1 and '1' for COM2):");
scanf("%d",&port);
printf("Press ESC to exit");
textcolor(YELLOW);
cprintf("\nData Received:");
_bios_serialcom(_COM_INIT,port,SETTINGS);
	for(;;)
	{
		status=_bios_serialcom(_COM_STATUS,port,0);
		if(status&256)	/*if data ready */
		{
			if(((out=_bios_serialcom(_COM_RECEIVE,port,0))&127)!=0)
			putch(out);
		}
		if(kbhit()) /*if a keystroke is currently available*/
		{
			in=getch(); /*get a character without echoing onto the screen*/
			if(in==27)/*ESC*/
				break;
		_bios_serialcom(_COM_SEND,port,in);
		}
	}
}
 
its probably because it cannot locate the header file and relevant libary

check within VC++ its search paths
 
VC++ doesn't want you to use bios.h.

Your Turbo C code is 16 bit DOS code. You can't do that under Windows NT/2000/XP, your program will just crash, and possibly take a part of the system down with it.

You either need to keep using Turbo C under DOS (or Win 95/98/ME) or learn the Win32 way of doing whatever you're doing in that code.

The proper Win32 way is to use the CreateFile API to open the COM port and write to it like you would write in a file. Check the Win32 PLatform SDK documentation.

An alternative would be to find a 3rd party DLL that allows access to the serial port directly with _outp and _inp-style functions. I have seen of few of these posted recently on Electro-Tech for the parallel port. They might offer the same for the serial port. Check the past threads.
 
Joel Rainville said:
VC++ doesn't want you to use bios.h.

Your Turbo C code is 16 bit DOS code. You can't do that under Windows NT/2000/XP, your program will just crash, and possibly take a part of the system down with it.

You either need to keep using Turbo C under DOS (or Win 95/98/ME) or learn the Win32 way of doing whatever you're doing in that code.

The proper Win32 way is to use the CreateFile API to open the COM port and write to it like you would write in a file. Check the Win32 PLatform SDK documentation.

An alternative would be to find a 3rd party DLL that allows access to the serial port directly with _outp and _inp-style functions. I have seen of few of these posted recently on Electro-Tech for the parallel port. They might offer the same for the serial port. Check the past threads.

Hi Joel
I'm actually going through some 'strange' problems recently. If you remember a few days back I had successfully transmitted and received some data to & from the PIC. But that was under Tubo C 3.0 running under Win XP with Service Pack 2, the same thing worked for Turbo C under MSDOS. Now I'm using Win98 SE, and the program isn't working at all. I'm sure my port is COM 0, so when I punch in '0', after that all I get is a continous stream of invisible lines..in the sense the cursor justs keep running from top to bottom, line to line all accross the screen. I tried using fflush(stdin) wherever suitable..but that didnt work. It's just frustrating me..cause I need to demonstrate the project on a 98SE laptop.
Please suggest some measures.. :cry:

BTW: I know C, no C++ , a little bit of VB thats all..

One more thing in HyperTerminal it works fine (XP & 98SE), but the bad part is I need to make a GUI so HT does not work out for me.
 
Electrix said:
I'm sure my port is COM 0, so when I punch in '0', after that all I get is a continous stream of invisible lines..in the sense the cursor justs keep running from top to bottom, line to line all accross the screen. [...] cause I need to demonstrate the project on a 98SE laptop.

COM 0? I have never seen a serial port refered to as COM 0 on Windows. While the OS can call the serial port any damn way it wants, Windows usually starts at COM1. But if your program is waiting for an I/O address, you need to feed it the actual serial port address, not the numbering scheme used by windows. The usual memory address for a PC with only 1 serial port is 0x3F8, although you need to check your laptop configuration to make sure.

Your Turbo C code compiled as a 16 bit DOS executable should work fine on Win98SE, it just looks like you don't know how to properly use the program you compiled.

Electrix said:
BTW: I know C, no C++ , a little bit of VB thats all..

You can write plain C with Visual C++. The article about Win32 Serial Communications uses plain C too, no C++ at all.
 
Electrix said:
I had successfully transmitted and received some data to & from the PIC. But that was under Tubo C 3.0 running under Win XP with Service Pack 2,

Are you saying the code posted at the top of this thread worked on Windows XP? Or was it a different program?
 
Joel Rainville said:
Electrix said:
I had successfully transmitted and received some data to & from the PIC. But that was under Tubo C 3.0 running under Win XP with Service Pack 2,

Are you saying the code posted at the top of this thread worked on Windows XP? Or was it a different program?

It worked on a computer that has windows XP as the operating system
 
serial port control using VC++

man if you have got the solution by now its fine.... else i have the solution for you
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top