UART 8051 - Read data
Discussion in "8051 Discussion Forum" started by say2paul Jul 5, 2008.
Sat Jul 05 2008, 12:09 am
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
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
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..
As per ANSI C you have to define the character at the top of program.
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.
Tue Jul 08 2008, 08:17 am
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
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
he is used to of c++ a lot i guess
Tue Jul 08 2008, 09:08 pm
Its fact... and its difficult to follow C Standards...
But I will get use to it
But I will get use to it
Powered by e107 Forum System