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:

#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 );
	}
}


void init_8051(void)
{
	SCON  = 0x50;	/* SCON: mode 1, 8-bit UART, enable rcvr */
	TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload        */
	TH1   = 0xfd; /* TH1:  reload value for 9600 baud @ 11.0592MHz   */
	TR1   = 1;    /* TR1:  timer 1 run                          */
	TI    = 1;    /* TI:   set TI to send first char of UART    */
}

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

Parents
  • Will your students have development boards with flash-based MCU's that support in-circuit debugging?  Hopefully so, as this will provide the best learning experience. I don't know all of the chip manufacturers that support this, but Silicon Labs does via their USB Debug Adapter and so does Nuvoton with their Nu-Link.   If memory serves, the Nuvoton debugger runs right in the Keil IDE, but I'm not sure if the Silicon Labs does.

Reply
  • Will your students have development boards with flash-based MCU's that support in-circuit debugging?  Hopefully so, as this will provide the best learning experience. I don't know all of the chip manufacturers that support this, but Silicon Labs does via their USB Debug Adapter and so does Nuvoton with their Nu-Link.   If memory serves, the Nuvoton debugger runs right in the Keil IDE, but I'm not sure if the Silicon Labs does.

Children
No data