But so far I can't get the data in array of chars (char[]).
Here is the program I've got from my department.
Expand|Select|Wrap|Line Numbers
- #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
- {
- Serial_initial();
- P1 = 0x80;
- while(1) // Infinite loop
- {
- Data = Get_Serial(); // ******** I'm thinking that the data gets in from this line
- //My main loop which I need to apply a string like data.
- }
- }
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.