Discussion in "8051 Discussion Forum" started by    say2paul    Jul 5, 2008.
Sat Jul 05 2008, 12:09 am
#1
I know my post might look weird as I am noob, but believe me I only got time to learn uC's at night as I am really very busy in daytime with Symbian C++.

Please look at the following code and let me know the mistake, here I am trying to print back a character to the hyper terminal in window OS. I wrote the code in such a way so that it can detect the character entered by user in hyper terminal and then send the same back to the hyper terminal.

I know I must be doing something wrong that is why I am unable to type anything on the Hyper Terminal

#include<P89V51Rx2.h>

#include<intrins.h>

#include<string.h>


void delay()

   {
    int i;
 for(i=0;i<9000;i++);
 }
 
void serial_send(unsigned char dat){
        while(!TI);
        TI = 0;
        SBUF = dat;
}
unsigned char serial_read(){
        while(!RI);
        RI = 0;
        return SBUF;
}           
                   
 void main()
   {
unsigned char i,data1;         
    TMOD=0x20;
    SCON=0x50;
    TH1=0xfd;
    TL1=0xfd;
    TR1=1;
  while(1)
	{
		char a = serial_read();
		delay();
		serial_send(a);
	}	
}		




Mon Jul 07 2008, 08:31 pm
#2
I am not sure how you're able to compile it

coz you are using C now.. not c++ so

this thing is not possible within the program..
char a = serial_read();


As per ANSI C you have to define the character at the top of program.
Mon Jul 07 2008, 08:32 pm
#3
I am moving your post in 8051 discussion section
Tue Jul 08 2008, 08:17 am
#4

void serial_send(unsigned char dat){
while(!TI);
TI = 0;
SBUF = dat;
}



Change to ...

void serial_send(unsigned char dat){
SBUF = dat;
while(!TI);
TI = 0;

}
Tue Jul 08 2008, 08:31 pm
#5
Sashi what paul wrote is fine just the problem is he declared the variable within the function which is not valid in C

he is used to of c++ a lot i guess
Tue Jul 08 2008, 09:08 pm
#6
Its fact... and its difficult to follow C Standards...

But I will get use to it

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am