Using library functions, the result of debugging is on the red program,
int main (void)
{
U8 A;
U8 T;
U8 Len;
U16 Times=0;
Delay_init (); Time-lapse function initialization
Nvic_configuration (); Set Nvic Interrupt grouping 2:2-bit preemption priority, 2-bit response priority
Uart_init (9600); Serial port initialized to 9600
Led_init (); LED Port Initialization
Key_init (); Initializing the hardware interface to the key connection
while (1)
{
if (usart_rx_sta&0x8000)
{
len=usart_rx_sta&0x3fff;//get the length of the data received
printf ("\ r \ n You sent the message: \r\n\r\n");
for (t=0;t<len;t++)
{
Usart_senddata (USART1, usart_rx_buf[t]);//Send data to serial 1
A=usart_rx_buf[t];
while (Usart_getflagstatus (USART1,USART_FLAG_TC)!=set);//wait for Send to end
}
printf ("\r\n\r\n");//Insert line break
usart_rx_sta=0;
}else
{
times++;
if (times%5000==0)
{
printf ("\r\nstm32 Export Control led\r\n");
}
if (times%200==0) printf ("Please enter data, end with enter \ n");
if (a== ' 0 ') led0=0;//flashes LED0, prompting the system to be running.
if (a== ' 1 ') led0=1;//flashes LED1, prompting the system to be running.
if (a== ' 2 ') led1=0;//flashes LED0, prompting the system to be running.
if (a== ' 3 ') led1=1;//flashes LED1, prompting the system to be running.
Delay_ms (10);
}
}
}
It is proved feasible in serial debugging.
Upper computer control LED