I'm trying to receive data from PC via serial port.
But so far I can't get the data in array of chars (char[]).
Here is the program I've from my department.
If I send a data from PC as "10"
The program will only read '1'
which is not correct.
please give me some advice.
ps. sorry for my English, it's not my primary language.
But so far I can't get the data in array of chars (char[]).
Here is the program I've from my department.
Code:
#include <p89v51rd2.h> // Header file register for P89V51RD2FN
unsigned char Get_Serial(void)
{
bit Timeout=0;
unsigned char count=252, Data = 0;
while((Timeout == 0))
{
if(RI == 0)
count++; //waiting
else
{
Data = SBUF;
RI=0;
return(Data);
}
if(count <= 2)
{
Timeout = 1; //Timeout!!
}
}
return(Data);
}
void Send_Serial(unsigned char x)
{
TI = 0;
SBUF = x;
while(TI==0);
}
void Serial_initial()
{
TMOD = 0x21;
SCON = 0x50;
TH1 =0xFD;
TL1 =0xFD;
TF1 = 0;
TR1 = 1;
TI = 0;
}
void main(void) // Main loop
{
unsigned char Data=0; // ******** I'm thinking that the data gets in from this line
Serial_initial();
P1 = 0x80;
while(1) // Infinite loop
{
//My main loop which I need to apply a string like data.
}
}
If I send a data from PC as "10"
The program will only read '1'
which is not correct.
please give me some advice.
ps. sorry for my English, it's not my primary language.