Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C Programming...urgently needed correction of code

Status
Not open for further replies.

yousafzai82

Member level 4
Joined
Jan 20, 2010
Messages
77
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Pakistan
Activity points
1,844
C Programming...

Hi everyone

Please read the C program and identify the errors. I need it urgently.
Thanks in advance...




Statement missing
Expression Syntax
Undefined MCR
Function should return a value

Added after 1 minutes:

You can click on the image to see it clearly...
 

Re: C Programming...

Hi,

statement missing ";" in line number 10 & 11. it should be

Code:
unsigned int MSR=COM2+0x06;
unsigned int MCR=COM2+0x04;

check the procedure/function delay(); I think you need to defined it as a prototype and need to code it to generate the delay

Code:
int delay(int delayTime);

check this and state your comments

good luck!
bassa
 

Re: C Programming...

1. #define COM2 0x2F8 ==> The comment says the base address is 0x3F8
2. Missing ";" at the end of the two lines defining MCR and MSR
3. Missing "(" after "if"
4. Missing "}" at the end of the file
--
Amr Ali
 

Thank you both..

Now the error is
outportb"(MCR,DTR)";

The error is statement missing..
Also let me know about the address of COM1..

Zahoor
 

yousafzai82 said:
Thank you both..

Now the error is
outportb"(MCR,DTR)";

The error is statement missing..
Also let me know about the address of COM1..

Zahoor

Hi,

In Turbo C, the function is
Code:
void outportb( int port, unsigned char byte )

You can check COM1 address when you boot your PC then go to the BIOS settings. It will be there and you can check available COM ports with addresses.

good luck!
bassa
 

Now with this function i am getting another error .i.e
Multiple declaration for outportb...

How can i fix that..

Thanks..
 

This is because you have two different prototypes for this function.
Search in your include files or your source code to see the different prototypes and stick to one of them only.
--
Amr Ali
 

I am very bad at programming. Can you tell me exactly what should i do?
 

Search for the definition or prototypes for the buggy function.
The function is defined more than once.
--
Amr Ali
 
yousafzai82 said:
I am very bad at programming. Can you tell me exactly what should i do?

Hi,

As "amraldo" said you can search it. If you can post your code here. Then it will be very easy to check it

copy and past your code using BBcode

ex
Code:
your code her

regards
bassa
 

The c codes are as folllows:
#include<dos.h>
#include<stdio.h>
#define COM1 0x3F8;
#define DTR 0x01;
#define RTS 0x02;

main()
{
unsigned char status;
unsigned int value, bit;
unsigned int MSR=COM2+0x06;
unsigned int MCR=COM2+0x04;
outportb(MCR,DTR);
delay(10);
outportb(MCR,DTR+RTS);
do{
status=inportb(MSR) & 0x20;
}while(status);
value=0;
for(i=0;i<12;i++){
value=value<<1;
delay(1);
outportb(MCR,RTS);
delay(1);

ourportb(MCR,DTR+RTS);
delay(1);
if (inportb(MSR) & 0x20)==0) bit=1;else bit=0;
value=value+bit;
}
ourportb(MCR,0x00);
printf("%d\n",value);
}
 

Please send the compiler output log too.
--
Amr Ali
 

I modified it as:
The c codes are as folllows:
#include<dos.h>
#include<stdio.h>
#define COM1 0x3F8;
#define DTR 0x01;
#define RTS 0x02;

main()
{
unsigned char status;
unsigned int value, bit;
unsigned int MSR=COM2+0x06;
unsigned int MCR=COM2+0x04;

outportb"(MCR,DTR)";
delay(10);
outportb"(MCR,DTR+RTS)";
do{
status=inportb(MSR) & 0x20;
}while(status);
value=0;
for(i=0;i<12;i++){
value=value<<1;
delay(1);
outportb"(MCR,RTS)";
delay(1);

ourportb(MCR,DTR+RTS);
delay(1);
if (inportb(MSR) & 0x20)==0) bit=1;else bit=0;
value=value+bit;
}
ourportb(MCR,0x00);
printf("%d\n",value);
}


In line 14,16,25 and 28 i am getting Error statement missing...
 

Remove the quotes pal.
--
Amr Ali
 

I didnt get you. I am not good at programming so my questions may be foolish. Sorry for that.
 

yousafzai82 said:
The c codes are as folllows:
#include<dos.h>
#include<stdio.h>
#define COM1 0x3F8;
#define DTR 0x01;
#define RTS 0x02;

main()
{
unsigned char status;
unsigned int value, bit;
unsigned int MSR=COM2+0x06;
unsigned int MCR=COM2+0x04;
outportb(MCR,DTR);
delay(10);
outportb(MCR,DTR+RTS);
do{
status=inportb(MSR) & 0x20;
}while(status);
value=0;
for(i=0;i<12;i++){
value=value<<1;
delay(1);
outportb(MCR,RTS);
delay(1);

ourportb(MCR,DTR+RTS);
delay(1);
if (inportb(MSR) & 0x20)==0) bit=1;else bit=0;
value=value+bit;
}
ourportb(MCR,0x00);
printf("%d\n",value);
}


Hi,

here corrected code

Code:
#include<dos.h>
#include<stdio.h>

#define COM1 0x3F8;

#define COM2 0x2F8;

#define DTR 0x01;
#define RTS 0x02;

main()
{
	unsigned char status;
	unsigned int value, bit;
	int MSR, MCR, i; // =COM2;//+0x06;

//unsigned int MCR=COM2;//+0x04;

	MSR = COM2+0x06;
	MCR = COM2+0x04;

//outportb(MCR,DTR);

	outportb(MCR,chr(0x01));

	delay(10);

//outportb(MCR,DTR+RTS);

	outportb(MCR,chr(0x01+0x02));
	do{
		status=inportb(MSR) & 0x20;
	}while(status);
	value=0;
	for(i=0;i<12;i++){
		value=value<<1;
		delay(1);

//outportb(MCR,RTS);

		outportb(MCR,chr(0x02));
		delay(1);

//ourportb(MCR,DTR+RTS);

		ourportb(MCR,chr(0x01+0x02));
		delay(1);
		if ((inportb(MSR) & 0x20)==0) bit=1;else bit=0;
		value=value+bit;
	}
	ourportb(MCR,0x00);
	printf("%d\n",value);
	return 0;
}

check this

good luck!
bassa
 

Thanks bassa for your time..

Now i am getting one error

outportb(MCR,chr(0x01));
Error function 'chr' should have a prototype..
 

yousafzai82 said:
Thanks bassa for your time..

Now i am getting one error

outportb(MCR,chr(0x01));
Error function 'chr' should have a prototype..

Hi,

remove chr function

ex outportb(MCR,chr(0x01)); when chr remove it will look like outportb(MCR, 0x01);

and test it (you need to send unsigned char values from outportb).

What is your C compiler? Turbo C version 3?

good luck!
bassa
 

yeah it is Turbo C version 3.
Which version do i need for that?
Another problem i am getting while running the program is that...
The system cannot open the COM2 port requested by the application...
How to resolve this issue?

Thanks alot bassa..

Zahoor Ahmad
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top