How to use the scanf() function in a real 8051 mcu ?

Hi, I use the 8051 mcu and Keil C51 to teach my students for the C programming language. The 8051+KeilC51 will make the students understand the power of the C programming language. Students can gain immense confidence. In my teaching, I can use the printf() function for the example programs, but when I use the scanf() function, I encountered some difficulities. 

My example program is:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <reg51.h>
#include <stdio.h>
void init_8051(void);
void main(void)
{
char a;
int b;
long c;
int argsread;
init_8051();
while(1)
{
printf("\n enter a signed byte ,int, and long \n");
argsread = scanf("%bd %d %ld", &a, &b, &c);
printf("\n %d arguments read \n",argsread);
printf("\n %bd %d %ld \n", a, b, c );
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I download the .hex file (which generated by the example code above) to my 8051 mcu, then I send some numbers to the variables a, b, c, such as:

When I click the sendData button, the software got a lot of message as the picture shows above.  These message runs forever, they are not stop.

But, if I click the "Start debug Session" button:

The keil will enter the debug session, and I can run the example code above correctly:

Unfortunately, the  debug session is a simulation tool, it is not real running in the 8051 mcu.

Does anyone can help me, how can I use the scanf() in a real 8051 mcu, not just running it in a simulation session ?

Best regards.

The example project:

test1224.zip

0