久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5560|回復: 2
打印 上一主題 下一主題
收起左側

stm32f103 USART異步通信串口例程

[復制鏈接]
跳轉到指定樓層
樓主
ID:308105 發(fā)表于 2018-4-14 17:38 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
需要的童鞋自行下載吧 usart通訊。。。

單片機源程序如下:
  1. #include "stm32f10x.h"
  2. #include "GLCD.h"
  3. #include "USART.h"
  4. #include <stdio.h>
  5. /* Private typedef -----------------------------------------------------------*/
  6. /* Private define ------------------------------------------------------------*/
  7. /* Private macro -------------------------------------------------------------*/
  8. /* Private variables ---------------------------------------------------------*/
  9. const char menu[] =
  10.    "\n\r"
  11.    "+******************** 火牛開發(fā)板  **********************+\n\r"
  12.    "|              火牛STM32開發(fā)板試驗程序                  |\n\r"
  13.    "|                USART異步通信試驗                     |\n\r"
  14.    "|                技術支持群:121939788                  |\n\r"
  15.    "+-------------------------------------------------------+\n\r";
  16. /* Private function prototypes -----------------------------------------------*/
  17. /* Private functions ---------------------------------------------------------*/
  18. #ifdef __GNUC__
  19. /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  20.    set to 'Yes') calls __io_putchar() */
  21. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  22. #else
  23. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  24. #endif /* __GNUC__ */

  25. void GPIO_Configuration(void)
  26. {
  27.         GPIO_InitTypeDef GPIO_InitStructure;
  28.         
  29.         /* Configure IO connected to LD1, LD2, LD3 and LD4 leds *********************/        
  30.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
  31.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  32.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  33.           GPIO_Init(GPIOD, &GPIO_InitStructure);

  34.            /* Configure USART1 Tx (PA.09) as alternate function push-pull */
  35.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  36.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  37.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  38.           GPIO_Init(GPIOA, &GPIO_InitStructure);
  39.    
  40.           /* Configure USART1 Rx (PA.10) as input floating */
  41.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  42.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  43.           GPIO_Init(GPIOA, &GPIO_InitStructure);

  44.         /* Configure USART2 Tx (PA.02) as alternate function push-pull */
  45.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  46.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  47.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  48.           GPIO_Init(GPIOA, &GPIO_InitStructure);
  49.    
  50.           /* Configure USART2 Rx (PA.03) as input floating */
  51.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  52.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  53.           GPIO_Init(GPIOA, &GPIO_InitStructure);
  54. }

  55. //系統(tǒng)中斷管理
  56. void NVIC_Configuration(void)
  57. {
  58.           /* Configure the NVIC Preemption Priority Bits */  
  59.           NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

  60.         #ifdef  VECT_TAB_RAM  
  61.           /* Set the Vector Table base location at 0x20000000 */
  62.           NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  63.         #else  /* VECT_TAB_FLASH  */
  64.           /* Set the Vector Table base location at 0x08000000 */
  65.           NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
  66.         #endif
  67. }

  68. //配置系統(tǒng)時鐘,使能各外設時鐘
  69. void RCC_Configuration(void)
  70. {
  71.         SystemInit();        
  72.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA
  73.                            |RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
  74.                            |RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE
  75.                                                    |RCC_APB2Periph_ADC1  | RCC_APB2Periph_AFIO
  76.                            |RCC_APB2Periph_SPI1, ENABLE );
  77.   // RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL ,ENABLE );
  78.      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4 | RCC_APB1Periph_USART2
  79.                            |RCC_APB1Periph_USART3|RCC_APB1Periph_TIM2                                   
  80.                            , ENABLE );
  81.          RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  82. }

  83. void InitDis(void)
  84. {
  85.    /* LCD Module init */
  86.    GLCD_init();
  87.    GLCD_clear(White);
  88.    GLCD_setTextColor(Blue);
  89.    GLCD_displayStringLn(Line1, "     FireBull");
  90.    GLCD_displayStringLn(Line2, "   USART example");
  91.    GLCD_setTextColor(Red);
  92. }

  93. //配置所有外設
  94. void Init_All_Periph(void)
  95. {
  96.         RCC_Configuration();        
  97.         InitDis();
  98.         GPIO_Configuration();
  99.         NVIC_Configuration();
  100.         USART1_Configuration();
  101.         USART2_Configuration();
  102.         USART1Write((u8*)"    FireBull  USART_example ",sizeof("    FireBull  USART_example "));
  103.         USART2Write((u8*)"    FireBull  USART_example ",sizeof("    FireBull  USART_example "));
  104. }

  105. void Delay(vu32 nCount)
  106. {
  107.   for(; nCount != 0; nCount--);
  108. }

  109. //發(fā)送開機信息
  110. void SendMessage(void)
  111. {
  112.    printf(menu);
  113.    USART1Write((u8*)"Hello World! USART1_Test\n\r",sizeof("Hello World! USART1_Test\n\r")) ;
  114.    USART2Write((u8*)"Hello World! USART2_Test\n\r",sizeof("Hello World! USART2_Test\n\r")) ;
  115. }

  116. int main(void)
  117. {  
  118.         Init_All_Periph();
  119.         SendMessage();
  120.          while(1)
  121.           {
  122.                 /* Turn on LD1 */
  123.             GPIO_SetBits(GPIOD, GPIO_Pin_8);
  124.             /* Insert delay */
  125.             Delay(0xAFFFF);
  126.                 Delay(0xAFFFF);
  127.                 Delay(0xAFFFF);

  128.             /* Turn on LD2  */
  129.             GPIO_SetBits(GPIOD, GPIO_Pin_9);
  130.             /* Turn off LD1 */
  131.             GPIO_ResetBits(GPIOD, GPIO_Pin_8);
  132.             /* Insert delay */
  133.             Delay(0xAFFFF);
  134.                 Delay(0xAFFFF);
  135.                 Delay(0xAFFFF);

  136.                 /* turn on LD3*/
  137.                 GPIO_SetBits(GPIOD, GPIO_Pin_10);
  138.                 /* Turn off LD2 */
  139.             GPIO_ResetBits(GPIOD, GPIO_Pin_9);
  140.                 /* Insert delay */
  141.             Delay(0xAFFFF);
  142.                 Delay(0xAFFFF);
  143.                 Delay(0xAFFFF);

  144.             /* Turn on LD4 */
  145.             GPIO_SetBits(GPIOD, GPIO_Pin_11);
  146.             /* Turn off LD2 and LD3 */
  147.             GPIO_ResetBits(GPIOD, GPIO_Pin_10);
  148.             /* Insert delay */
  149.             Delay(0xAFFFF);
  150.                 Delay(0xAFFFF);
  151.                 Delay(0xAFFFF);
  152.             /* Turn off LD4 */
  153.             GPIO_ResetBits(GPIOD, GPIO_Pin_11);        
  154.           }
  155. }
  156. /*******************************************************************************
  157. * Function Name  : PUTCHAR_PROTOTYPE
  158. * Description    : Retargets the C library printf function to the USART.
  159. * Input          : None
  160. * Output         : None
  161. * Return         : None
  162. *******************************************************************************/
  163. PUTCHAR_PROTOTYPE
  164. {
  165.   /* Place your implementation of fputc here */
  166.   /* e.g. write a character to the USART */
  167.   USART_SendData(USART1, (u8) ch);

  168.   /* Loop until the end of transmission */
  169.   while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  170.   {}

  171.   return ch;
  172. ……………………

  173. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
Usart1-3.rar (285.27 KB, 下載次數: 62)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:162562 發(fā)表于 2018-8-28 16:14 | 只看該作者
非常感謝,正需要資料!!
回復

使用道具 舉報

板凳
ID:388109 發(fā)表于 2018-10-17 20:51 | 只看該作者
好的,感謝
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日韩不卡一区二区 | 久久久免费精品 | 久久免费视频1 | 日韩最新网址 | 国产高清精品在线 | 精品一二三 | 国产一区二区精华 | 婷婷综合久久 | 99在线免费观看视频 | 免费在线观看av | 中文精品视频 | 黄色一级片aaa | 秋霞电影一区二区 | 国产高清视频在线观看播放 | 久久久久久免费毛片精品 | 在线观看国产精品视频 | 欧美在线小视频 | 国产精品久久 | 欧美精品一区三区 | 国产成人综合在线 | 小h片免费观看久久久久 | 日韩在线精品 | 91精品国产综合久久久久久首页 | 又爽又黄axxx片免费观看 | 狠狠综合久久av一区二区小说 | 国产高清一区二区三区 | 中文字幕亚洲视频 | 国产精品国产精品国产专区不卡 | 久久久www成人免费精品 | 中文亚洲视频 | 久久久久久中文字幕 | 国产精品视频播放 | 久久久久久久国产精品影院 | 国产精品日韩在线观看 | 九色在线观看 | 亚洲三级在线观看 | a在线视频观看 | 日本久草视频 | 欧美日韩高清一区二区三区 | 免费观看视频www | 亚洲一区二区三区在线免费观看 |