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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

STM32 MODBUS協議源程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:593598 發表于 2019-8-2 15:26 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
STM32 MODBUS協議

單片機源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @文件   
  4.   * @作者
  5.   * @版本
  6.   * @日期
  7.   * @概要
  8.   ******************************************************************************
  9.   * @注意事項
  10.   *
  11.   *
  12.   *
  13.   ******************************************************************************
  14.   */  

  15. /* 頭文件                --------------------------------------------------------------*/
  16. #include <stdio.h>
  17. #include "stm32f10x.h"
  18. #include "mb.h"

  19. /* 私有數據類型 --------------------------------------------------------------*/
  20. /* 私有定義         --------------------------------------------------------------*/
  21. /* 私有宏定義         --------------------------------------------------------------*/
  22. #ifdef __GNUC__
  23. /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  24.    set to 'Yes') calls __io_putchar() */
  25. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  26. #else
  27. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  28. #endif /* __GNUC__ */
  29. /* 私有變量         --------------------------------------------------------------*/
  30. /* 私有函數聲明 --------------------------------------------------------------*/
  31. void LED_Config(void)
  32. {
  33.         GPIO_InitTypeDef GPIO_InitStructure;
  34.        
  35.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  36.         GPIO_InitStructure.GPIO_Pin          = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
  37.         GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_Out_PP;
  38.         GPIO_InitStructure.GPIO_Speed         = GPIO_Speed_50MHz;

  39.         GPIO_Init(GPIOC,&GPIO_InitStructure);
  40. }


  41. /**
  42.   * @brief  Configure the nested vectored interrupt controller.
  43.   * @param  None
  44.   * @retval : None
  45.   */
  46. void NVIC_Configuration(void)
  47. {
  48.   NVIC_InitTypeDef NVIC_InitStructure;

  49.   /* Enable the TIM2 gloabal Interrupt */
  50.   NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  51.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  52.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  53.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  54.   NVIC_Init(&NVIC_InitStructure);

  55.   /* Enable the TIM2 gloabal Interrupt */
  56.   NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  57.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  58.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  59.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  60.   NVIC_Init(&NVIC_InitStructure);
  61. }

  62. /**
  63.   * @功能
  64.   * @參數
  65.   * @返回值
  66.   */
  67. int main(void)
  68. {
  69.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  70.         NVIC_Configuration();
  71.         LED_Config();
  72.        
  73.         /*模式         從機地址 端口 波特率 校驗位*/
  74.         eMBInit( MB_RTU, 0x01, 0, 9600, MB_PAR_NONE );
  75.        
  76.         /* Enable the Modbus Protocol Stack. */
  77.         eMBEnable(  );
  78.        
  79.         for( ;; )
  80.         {
  81.          ( void )eMBPoll(  );
  82.          /* Here we simply count the number of poll cycles. */
  83.          //usRegInputBuf[0]++;
  84.         }
  85. }

  86. /**
  87.   * @brief  Retargets the C library printf function to the USART.
  88.   * @param  None
  89.   * @retval None
  90.   */
  91. PUTCHAR_PROTOTYPE
  92. {
  93.   /* Place your implementation of fputc here */

  94.   /* Loop until the end of transmission */
  95.   while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  96.   {}
  97.   /* e.g. write a character to the USART */
  98.   USART_SendData(USART1, (uint8_t) ch);       

  99.   return ch;
  100. }

  101. #ifdef  USE_FULL_ASSERT

  102. /**
  103.   * @brief  Reports the name of the source file and the source line number
  104.   *         where the assert_param error has occurred.
  105.   * @param  file: pointer to the source file name
  106.   * @param  line: assert_param error line source number
  107.   * @retval None
  108.   */
  109. void assert_failed(uint8_t* file, uint32_t line)
  110. {
  111.   /* User can add his own implementation to report the file name and line number,
  112.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  113.   /* Infinite loop */
  114.   while (1)
  115.   {
  116.   }
  117. }
  118. #endif
  119. /**
  120.   * @}
  121.   */


  122. /*******************************文件結尾**************************************/
復制代碼

所有資料51hei提供下載:
STM32_MODBUS.7z (196.05 KB, 下載次數: 129)


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

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久午夜国产精品www忘忧草 | 国内av在线 | 国产精品亚洲一区二区三区在线观看 | 久久精品91久久久久久再现 | 超碰伊人 | 日韩电影中文字幕在线观看 | 91精品久久久久久久久中文字幕 | 国产一区二区三区四区在线观看 | 第一区在线观看免费国语入口 | 国产精品国产三级国产播12软件 | 成人午夜免费在线视频 | 天天综合天天 | 久久99久久99| 亚洲情综合五月天 | 国产区视频在线观看 | 日韩一区二区三区视频在线播放 | 欧美一区2区三区4区公司二百 | 91免费观看 | 国产亚洲精品精品国产亚洲综合 | 日日摸夜夜添夜夜添特色大片 | 狠狠操狠狠操 | 亚洲 欧美 另类 综合 偷拍 | 国产精品久久久久久 | 久久精品国产免费一区二区三区 | 午夜视频在线免费观看 | 日韩电影免费在线观看中文字幕 | 暖暖日本在线视频 | 华人黄网站大全 | 一级片免费网站 | 日韩精品在线免费观看视频 | 一区二区三区四区国产精品 | 久久伊人操 | 一区二区三区国产好 | 综合二区 | 99精品99 | 国产99久久精品一区二区300 | 亚洲高清在线观看 | 日日夜夜天天 | 日本不卡一区二区三区在线观看 | 欧美一级欧美三级在线观看 | 九九九久久国产免费 |