[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 &quot;stm32f10x.h&quot;
#include &quot;Led.
#include &quot;Usart.h&quot;
int main(){
init_Led();
usart_Init();
while(1);
} |