乙個是串列埠
1(pa9,pa10)
,乙個是串列埠
2(pa2,pa3)
我們的藍橋杯嵌入式開發板並不能直接使用串列埠
1rxbuf
是用來儲存串列埠的接收資料的,
rxover
為接收串列埠結束標誌位,
rxcunt
為串列埠接收計數值
#ifndef __usart_h
#define __usart_h
#include "stm32f10x.h"
void usart2_init(u32 bound);
void usart2_sendstring(u8 *str);
#endif
#include "usart.h"
void usart2_init(u32 bound)
/** * @說明 usart2字串傳送函式
* @引數 str: 指向字串的指標
* @返回值 none
*/void usart2_sendstring(u8 *str)
while(str[index] != 0); //檢查字串結束標誌
}
#include "stm32f10x.h"
#include "lcd.h"
#include "usart.h"
u32 timingdelay = 0;
u8 rxbuf[20];
u8 rxover=0;
u8 rxcunt=0;
u8 i;
void delay_ms(u32 ntime);
//main body
int main(void)
usart_itconfig(usart2,usart_it_rxne,enable);
rxover=0;
} //usart2_sendstring("sam\r\n"); }}
//延時函式
void delay_ms(u32 ntime)
//stm32f10x_it.c
extern u8 rxbuf[20];
extern u8 rxover;
extern u8 rxcunt;
void usart2_irqhandler(void)
else}}
stm32韌體庫v3.5\stm32f10x_stdperiph_lib_v3.5.0\project\stm32f10x_stdperiph_examples\usart\interrupt
usart_inittypedef usart_initstructure;
usart_initstructure.usart_baudrate = 9600;
usart_initstructure.usart_wordlength = usart_wordlength_8b;
usart_initstructure.usart_stopbits = usart_stopbits_1;
usart_initstructure.usart_parity = usart_parity_no;
usart_initstructure.usart_hardwareflowcontrol = usart_hardwareflowcontrol_none;
usart_initstructure.usart_mode = usart_mode_rx | usart_mode_tx;
usart_init(usarty, &usart_initstructure);
usart_itconfig(usarty, usart_it_rxne, enable);
usart_cmd(usarty, enable);
gpio_inittypedef gpio_initstructure;
gpio_initstructure.gpio_pin = usarty_rxpin;
gpio_initstructure.gpio_mode = gpio_mode_in_floating;
gpio_init(usarty_gpio, &gpio_initstructure);
gpio_initstructure.gpio_pin = usarty_txpin;
gpio_initstructure.gpio_speed = gpio_speed_50mhz;
gpio_initstructure.gpio_mode = gpio_mode_af_pp;
gpio_init(usarty_gpio, &gpio_initstructure);
nvic_inittypedef nvic_initstructure;
nvic_initstructure.nvic_irqchannel = usarty_irqn;
nvic_initstructure.nvic_irqchannelsubpriority = 0;
nvic_initstructure.nvic_irqchannelcmd = enable;
nvic_init(&nvic_initstructure);
藍橋杯嵌入式 USART(按 n傳送)
一 基本資料 快速編寫 6 stm32韌體庫 v3.5版 stm32f10x stdperiph lib stm32f10x stdperiph lib v3.5.0 project stm32f10x stdperiph examples usart interrupt usart.c inclu...
藍橋杯嵌入式 LCD
include stm32f10x.h include lcd.h include stdio.h u8 string 20 u8 temp 30 float ao 3.81 u32 timingdelay 0 void delay ms u32 ntime main body int main v...
藍橋杯嵌入式 RTC
bkp裡是關於備份暫存器的庫函式,pwr裡是關於電源管理的庫函式 ifndef rtc h define rtc h include stm32f10x.h void rtc init u8 hh,u8 mm,u8 ss endif include rtc.h void rtc init u8 hh...