欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: STM8F103串口發(fā)送及接收程序 [打印本頁]

作者: 1092648746    時(shí)間: 2019-3-6 18:45
標(biāo)題: STM8F103串口發(fā)送及接收程序
最近在用STM8做東西,看到論壇上關(guān)于STM8的例程少之又少,故發(fā)一個(gè)串口例程
串口1波特率9600,不斷發(fā)送數(shù)據(jù),同時(shí)可響應(yīng)接收數(shù)據(jù),注釋較少。
開發(fā)環(huán)境為IAR,可直接燒錄生成的hex文件。




單片機(jī)源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm8s.h"

  3. /* Private defines -----------------------------------------------------------*/
  4. /* Private function prototypes -----------------------------------------------*/
  5. /* Private functions ---------------------------------------------------------*/
  6. #define LED_GPIO_PORT  (GPIOB)
  7. #define LED_GPIO_PINS  (GPIO_PIN_5)
  8. void Delay(uint16_t nCount)
  9. {
  10.   /* Decrement nCount value */
  11.   while (nCount != 0)
  12.   {   
  13.     nCount--;
  14.   }
  15. }
  16. void Init_UART1(void)
  17. {
  18.         UART1_DeInit();
  19.         UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
  20.         
  21.         UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
  22.         enableInterrupts();
  23.         UART1_Cmd(ENABLE);
  24. }
  25. void Send(uint16_t dat)
  26. {
  27.   while(( UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET));
  28.        
  29.         UART1_SendData9(dat);
  30.        
  31. }

  32. void main(void)
  33. {

  34.   uint8_t i=0;
  35.   uint16_t j=0;
  36.                 CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
  37.                 Init_UART1();
  38.                
  39. /* Infinite loop */
  40.   while (1)
  41.   {
  42.     for(j=0;j<60000;j++);
  43.                 Send(i);
  44.     //UART1_SendData8(0x01);
  45.                 i++;
  46.   }
  47.   
  48. }

  49. #ifdef USE_FULL_ASSERT

  50. /**
  51.   * @brief  Reports the name of the source file and the source line number
  52.   *   where the assert_param error has occurred.
  53.   * @param file: pointer to the source file name
  54.   * @param line: assert_param error line source number
  55.   * @retval : None
  56.   */
  57. void assert_failed(u8* file, u32 line)
  58. {
  59.   /* User can add his own implementation to report the file name and line number,
  60.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  61.   /* Infinite loop */
  62.   while (1)
  63.   {
  64.   }
  65. }
  66. #endif
復(fù)制代碼

所有資料51hei提供下載:
UARTX-RX.7z (3.96 MB, 下載次數(shù): 60)


作者: 劍劍劍劍來!    時(shí)間: 2021-3-18 17:31
您好,我是一名機(jī)械電子工程專業(yè)的學(xué)習(xí)者,由于選擇了總線傳感器的組網(wǎng)與程序設(shè)計(jì)這一項(xiàng)目,與所學(xué)專業(yè)知識(shí)有偏差,現(xiàn)如今十分迷茫。但在看到了您對傳感器驅(qū)動(dòng)一帖子的評(píng)論后,逐漸找了一點(diǎn)靈感,想與您請教交流。




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1