#include "stm32f10x.h" // Device header
#include "stdio.h"
#include "delay.h"
#include "spioled.h"
/*************串口初始化***********************/
void led()//led PE5初始化
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStruct);
}
void CUSART_init()//串口初始化函数
{
GPIO_InitTypeDef GPIO_InitStruct;//GPIO结构体
USART_InitTypeDef USART_InitStruct;//USART结构体
NVIC_InitTypeDef NVIC_InitStruct;//中断结构体
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;//
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_9;//设置RX,TX端口串口使能
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN_FLOATING;//设置端口浮空输入
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_10;//设置RX,TX端口串口使能
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
USART_InitStruct.USART_BaudRate=9600;//波特率
USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;//硬件流设置
USART_InitStruct.USART_Mode=USART_Mode_Tx | USART_Mode_Rx;//设置串口模式
USART_InitStruct.USART_Parity=USART_Parity_No;//不使用奇偶校验
USART_InitStruct.USART_StopBits=USART_StopBits_1;//设置停止位 1
USART_InitStruct.USART_WordLength=USART_WordLength_8b;//传输或接受传输数据位
USART_Init(USART1,&USART_InitStruct);
USART_Cmd(USART1,ENABLE);//使能串口
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //开启串口接受中断
NVIC_InitStruct.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStr
STM32摇杆控制舵机,OLED显示数据
于 2022-05-14 19:10:34 首次发布