Home > other >  Proteus - a serial port to the LED
Proteus - a serial port to the LED

Time:12-02

Is originally want to enter data via a serial port, and then according to the digital tube, but the code written, LED has no reaction, and serial no return I send data, it is some screenshots , PA0 PA1 and has not been used, the code is as follows:
The main. C:
# include "stm32f10x. H"
# include "smart. H"
# define uchar unsigned char
# define uint unsigned int

Int main ()
{
Usart_Init ();
Usled_Clock_Init ();
Usled_Gpio_Init ();
While (1)
{
uchar i;
Uint a, b;
I=RecvChar ();
SendChar (I);
Discuss (I);

}
}
# include "stm32f10x. H"
# include "smart. H"
#include
Unsigned char seg []={xa4 xc0 0, 0 xf9, 0, 0 xb0, 0 x99, 0 x92, 0 x82, 0 xf8, 0 x80, 0 x90};

Void Usled_Clock_Init (void)
{
/* e +? Oe1? UN */
RCC_DeInit ();
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOC, ENABLE);
}
Void Usled_Gpio_Init (void)
{
GPIO_InitTypeDef GPIO_InitStructure;

GPIO_DeInit (GPIOA);

GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

GPIO_InitStructure. GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

GPIO_DeInit (GPIOC);

GPIO_InitStructure. GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init (GPIOC, & amp; GPIO_InitStructure);
GPIO_Write (GPIOC, seg [3]);
}
//void NVI_Init (void)
//{
//NVIC_InitTypeDef NVIC_InitStructure;
//NVIC_PriorityGroupConfig (NVIC_PriorityGroup_0);
//NVIC_InitStructure. NVIC_IRQChannel=USART1_IRQn;
//NVIC_InitStructure. NVIC_IRQChannelSubPriority=0;
//NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
//NVIC_Init (& amp; NVIC_InitStructure);
//}

Void Usart_Init (void)
{
USART_InitTypeDef USART_InitStructure;
USART_DeInit (USART1);
/* The following example illustrates how to configure The USART1 */

USART_InitStructure. USART_BaudRate=9600;
USART_InitStructure. USART_WordLength=USART_WordLength_8b;
USART_InitStructure. USART_StopBits=USART_StopBits_1;
USART_InitStructure. USART_Parity=USART_Parity_No;
USART_InitStructure. USART_HardwareFlowControl=
USART_HardwareFlowControl_None;
USART_InitStructure. USART_Mode=USART_Mode_Tx | USART_Mode_Rx;
USART_Init (USART1, & amp; USART_InitStructure);

USART_Cmd (USART1, ENABLE);

}
Unsigned char RecvChar (void)
{
Unsigned char RxData;
While (USART_GetFlagStatus (USART1, USART_FLAG_RXNE)==RESET)
RxData=https://bbs.csdn.net/topics/USART_ReceiveData (USART1);
Return RxData;
}

Int fputc (int ch, FILE * f)
{
USART_SendData (USART1, ch);
While (USART_GetFlagStatus (USART1, USART_FLAG_TC)==RESET);
Return (ch);
}
Void delay (unsigned int I)
{
Unsigned char j;
While (I -)
For (j=0; J & lt; 100; j++);
}

Void SendChar (unsigned char ch)
{
USART_SendData (USART1, ch);
While (USART_GetFlagStatus (USART1, USART_FLAG_TC)==RESET);
}

Void discuss (unsigned char dat)
{
The switch (dat)
{
Case 'a' :
GPIO_Write (GPIOC, seg [1]);
break;
Case '2' :
GPIO_Write (GPIOC, seg [2]);
break;
Case '3' :
GPIO_Write (GPIOC, seg [3]);
break;
Case '4' :
GPIO_Write (GPIOC, seg [4]);
break;
Case '5' :
GPIO_Write (GPIOC, seg [5]);
break;
Case '6' :
GPIO_Write (GPIOC, seg [6]);
break;
Case '7' :
GPIO_Write (GPIOC, seg [7]);
break;
Case '8' :
GPIO_Write (GPIOC, seg [8]);
break;
Case '9' :
GPIO_Write (GPIOC, seg [9]);
break;
Default:
Printf (" Error ");
break;
}
}
The main. H:
# # ifndef __USART_H_
# define __USART_H_
#include

Void Usled_Clock_Init (void);
Void Usled_Gpio_Init (void);
Void Usart_Init (void);
Unsigned char RecvChar (void);
Int fputc (int ch, FILE * f);
Void delay (unsigned int I);
Void NVI_Init (void);
Void discuss (unsigned char dat);
Void SendChar (unsigned char ch);

# endif

CodePudding user response:

I'd like to have been first to display a number 3, and then through the serial port input digital, the digital display on LED

CodePudding user response:

Single-step tracking a try

CodePudding user response:

No change the

CodePudding user response:

Give up with Proteus development board
  • Related