upload template

This commit is contained in:
筱傑
2019-01-18 17:14:55 +08:00
committed by GitHub
parent 42560f064c
commit c6dc4c99a6
98 changed files with 58254 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
#include <stdio.h>
#include "stm32f10x.h"
#include "SerialPort.h"
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
USART_SendData(USART1, (uint8_t) ch);
/* ѭ<><D1AD><EFBFBD>ȴ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>*/
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return ch;
}
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void SerialPortInit(int BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //ʹ<><CAB9>USART1<54><31>GPIOAʱ<41><CAB1>
USART_DeInit(USART1); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>1
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>PA9
//USART1_RX PA.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>PA10
/* USARTx configured as follow:
- BaudRate = 9600 baud <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
- Word Length = 8 Bits <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
- One Stop Bit ֹͣλ
- No parity У<>ʽ
- Hardware flow control disabled (RTS and CTS signals) Ӳ<><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
- Receive and transmit enabled ʹ<>ܷ<EFBFBD><DCB7>ͺͽ<CDBA><CDBD><EFBFBD>
*/
USART_InitStructure.USART_BaudRate = BaudRate;
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_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
NVIC_Configuration();
// <20>򿪴<EFBFBD><F2BFAAB4>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD>
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE); //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>
}

View File

@@ -0,0 +1,7 @@
#ifndef _SERIALPORT_H_
#define _SERIALPORT_H_
void SerialPortInit(int BaudRate);
#endif //_SERIALPORT_H_