#include <reg51.h>
#include "_LCD_R8C.c"
#define INPUT_LENGTH 11
char input[INPUT_LENGTH]; /* The input from the serial port */
int input_pos = 0; /* Current position to write in the input buffer */
int main()
{
int i;
lcd_init();
lcd_clear();
SCON = 0x50;
TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */
TH1 = 0xFD; /* reload value for 2400 baud */
TR1 = 1;
TI = 1;
RI = 1;
while (1 == 1)
{
/* read the next character from the serial port */
input[input_pos++] = getCharacter ();
/* send it back to the original sender */
for (i = 0; i <= input_pos; i++)
{
lcd_print_b(input[i]);
}
}
}
char getCharacter(void)
{
char chr[INPUT_LENGTH]; /* variable to hold the new character */
while (RI != 1) {;}
chr[input_pos++] = SBUF;
RI = 0;
return (chr);
}
我尝试显示我从 rfreader 读取的 rs232 收到的号码。但是我在显示器上得到了错误的值,即 002100 而不是 0016221826。但是在超级终端上,我得到了准确的正确值,其中包含 $ 美元,即 $0016221826。