初中生
最后登录1970-1-1
在线时间 小时
注册时间2019-11-23
|
[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]
|
|