<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > Stm32串口發(fā)送字符串?dāng)?shù)據(jù)

          Stm32串口發(fā)送字符串?dāng)?shù)據(jù)

          作者: 時間:2016-11-09 來源:網(wǎng)絡(luò) 收藏
          ps:把字符串分成字節(jié)循環(huán)發(fā)送

          本文引用地址:http://www.ex-cimer.com/article/201611/318056.htm
          /**說明:*PA0:KEY1;PA1:KEY2;*PA2:LED1;PA3:LED2;*PA9:USART1_TX;PA10:USART1_RX*/#include "stm32f10x.h"  #include "stm32f10x_rcc.h"  #include "stm32f10x_gpio.h"  #include "stm32f10x_usart.h" #include "stm32f10x_crc.h"#include "system_stm32f10x.h" #include "stdio.h" #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)void RCC_Configuration(void);  void GPIO_Configuration(void); void USART_Configuration(void); void delay_ms(u16 time);void UART_PutChar(USART_TypeDef* USARTx, uint8_t Data);void UART_PutStr (USART_TypeDef* USARTx, uint8_t *str);int main(){SystemInit();RCC_Configuration();  GPIO_Configuration();   USART_Configuration(); while(1){printf("n發(fā)送的信息:");UART_PutStr(USART1, "hello world!"); delay_ms(1000);  } }void RCC_Configuration(void)    {     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);     }   void GPIO_Configuration(void)    {    GPIO_InitTypeDef GPIO_InitStructure;    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;             //管腳9  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       //復(fù)用推挽輸出  GPIO_Init(GPIOA, &GPIO_InitStructure);                //TX初始化  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;            //管腳10  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;         //上拉輸入  GPIO_Init(GPIOA, &GPIO_InitStructure);                //RX初始化  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;//LED GPIO_Pin_All    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  GPIO_Init(GPIOA, &GPIO_InitStructure);   }void USART_Configuration(void)//串口初始化函數(shù)  {  //串口參數(shù)初始化    USART_InitTypeDef USART_InitStructure;               //串口設(shè)置恢復(fù)默認(rèn)參數(shù)  //初始化參數(shù)設(shè)置  USART_InitStructure.USART_BaudRate = 9600;                  //波特率9600  USART_InitStructure.USART_WordLength = USART_WordLength_8b; //字長8位  USART_InitStructure.USART_StopBits = USART_StopBits_1;      //1位停止字節(jié)  USART_InitStructure.USART_Parity = USART_Parity_No;         //無奇偶校驗  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//無流控制  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//打開Rx接收和Tx發(fā)送功能  USART_Init(USART1,&USART_InitStructure);                   //初始化  USART_Cmd(USART1,ENABLE);                                  //啟動串口  }void delay_ms(u16 time)     {    u16 i=0;    while(time--)     {    i=12000;    while(i--);    }    } int putchar(int c)                                            //putchar函數(shù)  {  if (c == n){putchar(r);}                                 //將printf的n變成r  USART_SendData(USART1, c);                                   //發(fā)送字符  while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //等待發(fā)送結(jié)束  return c;                                                      //返回值  } void UART_PutChar(USART_TypeDef* USARTx, uint8_t Data){USART_SendData(USARTx, Data);while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}}void UART_PutStr (USART_TypeDef* USARTx, uint8_t *str)  {  while (0 != *str)  {  UART_PutChar(USARTx, *str);  str++;  }  } 


          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();