打印

不知道为什么我写的串口发送接收程序一加上Led初始化程序就不起作用了

[复制链接]
410|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
大碴子味|  楼主 | 2020-4-9 15:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[C] 纯文本查看 复制代码#include "Led.h"uint8_t ZT= 1;
void init_Led(){
GPIO_InitTypeDef Led_Init;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
Led_Init.GPIO_Pin = Blue;
Led_Init.GPIO_Mode = GPIO_Mode_Out_PP;
Led_Init.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&Led_Init);

Led_Init.GPIO_Pin = Red;
GPIO_Init(GPIOB,&Led_Init);

Led_Init.GPIO_Pin = Green;
GPIO_Init(GPIOB,&Led_Init);

Close_Led(Green);
Close_Led(Blue);
Close_Led(Red);
}void Open_Led(uint16_t GPIO_Led){
GPIO_ResetBits(GPIOB,GPIO_Led);
}void Close_Led(uint16_t GPIO_Led){
GPIO_SetBits(GPIOB,GPIO_Led);
}void rever(uint16_t GPIO_Led){
if(ZT==1){
  Close_Led(GPIO_Led);
  ZT = 0;
}else{
  Open_Led(GPIO_Led);
  ZT = 1;
}
}

#include "Usart.h"void usart_Init(){
GPIO_InitTypeDef usart_GPIO_Init;
USART_InitTypeDef usart_USART_Init;
NVIC_InitTypeDef usart_NVIC_Init;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);

usart_GPIO_Init.GPIO_Pin = GPIO_Pin_9;
usart_GPIO_Init.GPIO_Mode = GPIO_Mode_AF_PP;
usart_GPIO_Init.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&usart_GPIO_Init);

usart_GPIO_Init.GPIO_Pin = GPIO_Pin_10;
usart_GPIO_Init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&usart_GPIO_Init);

usart_NVIC_Init.NVIC_IRQChannel = USART1_IRQn;
usart_NVIC_Init.NVIC_IRQChannelPreemptionPriority = 0;
usart_NVIC_Init.NVIC_IRQChannelSubPriority = 0;
usart_NVIC_Init.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&usart_NVIC_Init);

usart_USART_Init.USART_BaudRate = 115200;
usart_USART_Init.USART_WordLength = USART_WordLength_8b;
usart_USART_Init.USART_StopBits = USART_StopBits_1;
usart_USART_Init.USART_Parity = USART_Parity_No;
usart_USART_Init.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;

USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);

USART_Init(USART1,&usart_USART_Init);

USART_Cmd(USART1,ENABLE);
}void send_Byte(uint8_t str){
  USART_SendData(USART1,str);
  while(!(USART_GetFlagStatus(USART1,USART_FLAG_TXE)));
}void send_String(char *str,uint32_t num){
uint32_t i;
for(i=0;i<num;i++){
  USART_SendData(USART1,str);
  while(!(USART_GetFlagStatus(USART1,USART_FLAG_TXE)));
}
}

#include "stm32f10x.h"
#include "Led.
#include "Usart.h"
int main(){
init_Led();
usart_Init();
while(1);
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

372

主题

372

帖子

0

粉丝