野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 16118|回复: 0

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

[复制链接]
发表于 2019-11-28 15:48:21 | 显示全部楼层 |阅读模式
[mw_shl_code=c,true]#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);
}[/mw_shl_code]

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-23 15:21 , Processed in 0.032411 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表