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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

STM32仿三菱PLC開源代碼+電路圖

  [復制鏈接]
跳轉到指定樓層
樓主
三菱PLC源碼,提供給大家參考。


電路原理圖如下:


單片機源程序如下:
  1. /*
  2. UART 后臺處理程序
  3. */

  4. /*************Both Uart Used Variable Define *********************/
  5. unsigned char crc1,crc2;
  6. unsigned char crc3,crc4;

  7. /*************** Uart 0 Used Variable Define *********************/
  8. unsigned char uart0_rxbuf[127];                        //接受數據包緩沖
  9. unsigned char uart0_txbuf[127];                        //發送數據包緩沖
  10. unsigned char uart0_rxptr;                                //接受數據包當前指針
  11. unsigned char uart0_txptr;                                //發送數據包當前指針
  12. unsigned char uart0_txall;                          //發送數據包總長度
  13. unsigned char uart0_time;                                //接受數據包分割計時參數


  14. /*************** Uart 1 Used Variable Define *********************/
  15. unsigned char uart1_rxbuf[127];                        //接受數據包緩沖
  16. unsigned char uart1_txbuf[127];                        //發送數據包緩沖
  17. unsigned char uart1_rxptr;                                //接受數據包當前指針
  18. unsigned char uart1_txptr;                                //發送數據包當前指針
  19. unsigned char uart1_txall;                          //發送數據包總長度
  20. unsigned char uart1_time;                                //接受數據包分割計時參數


  21. /*************  Genernal Uart Function Predefine ***************/
  22. extern void uart_crc(unsigned char* , unsigned char);

  23. /***********  Two Uart Disposal Function Predefine **************/
  24. extern void uart0_dispose(void);
  25. extern void uart1_dispose(void);

  26. /************  Two Uart Setup Function Predefine ***************/
  27. extern void UART0_setup(void);
  28. extern void UART1_setup(void);


  29. /*******************************************************************************
  30. * Function Name  : UART1_Setup
  31. * Description    : Configures the uart1
  32. * Input          : None
  33. * Output         : None
  34. * Return         : None
  35. *******************************************************************************/
  36. void UART1_setup(void)
  37. {
  38.   USART_InitTypeDef USART_InitStructure;

  39.   USART_InitStructure.USART_BaudRate = 57600;
  40.   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  41.   USART_InitStructure.USART_StopBits = USART_StopBits_1;
  42.   USART_InitStructure.USART_Parity = USART_Parity_No ;
  43.   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  44.   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  45.   /* Configure the USART1*/
  46.   USART_Init(USART1, &USART_InitStructure);

  47.   /* Enable USART1 Receive and Transmit interrupts */
  48.   USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  49.   USART_ITConfig(USART1, USART_IT_TC, ENABLE);

  50.   /* Enable the USART1 */
  51.   USART_Cmd(USART1, ENABLE);

  52.   USART1->CR1 = 0x0000206C;
  53.   
  54. // 初始化 串口輸入輸出緩沖
  55.   uart0_time = 0;
  56.   uart0_txall = 0;
  57.   uart0_txptr = 0;
  58.   uart0_rxptr = 0;
  59.   USART1->CR1 |= 0x00002000;
  60. }


  61. /****************************************************************************  F!
  62. * 名稱:uart0_setup()
  63. * 功能:串口UART1 初始化以及變更格式程序
  64. * 入口參數:無
  65. * 出口參數:無
  66. ****************************************************************************/
  67. /*第二通訊口 通訊參數更新函數*/
  68. void UART0_setup(void)         
  69. {
  70. USART_InitTypeDef USART_InitStructure;

  71. switch(program[0x1C])
  72.         {

  73. //=============無校驗通訊設置區域========================
  74.         case(0x01):
  75.         /* 設置UART串口波特率  4800bps */
  76.         USART_InitStructure.USART_BaudRate = 4800;
  77.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  78.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  79.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  80.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  81.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  82.         break;

  83.         case(0x02):
  84.         /* 設置UART串口波特率  9600bps */
  85.         USART_InitStructure.USART_BaudRate = 9600;
  86.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  87.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  88.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  89.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  90.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  91.         break;

  92.         case(0x03):
  93.         /* 設置UART串口波特率 14400bps */
  94.         USART_InitStructure.USART_BaudRate = 14400;
  95.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  96.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  97.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  98.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  99.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  100.         break;

  101.         case(0x04):
  102.         /* 設置UART串口波特率  19200bps*/
  103.         USART_InitStructure.USART_BaudRate = 19200;
  104.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  105.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  106.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  107.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  108.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  109.         break;

  110.         case(0x05):
  111.         /* 設置UART串口波特率  38400bps */
  112.         USART_InitStructure.USART_BaudRate = 38400;
  113.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  114.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  115.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  116.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  117.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  118.         break;

  119.         case(0x06):
  120.         /* 設置UART串口波特率  57600bps */
  121.         USART_InitStructure.USART_BaudRate = 57600;
  122.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  123.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  124.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  125.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  126.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  127.         break;

  128. //=============奇校驗通訊設置區域========================
  129.         case(0x11):
  130.         /* 設置UART串口波特率 4800bps */
  131.         USART_InitStructure.USART_BaudRate = 4800;
  132.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  133.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  134.         USART_InitStructure.USART_Parity = USART_Parity_Odd;
  135.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  136.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  137.         break;

  138.         case(0x12):
  139.         /* 設置UART串口波特率 9600bps */
  140.         USART_InitStructure.USART_BaudRate = 9600;
  141.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  142.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  143.         USART_InitStructure.USART_Parity = USART_Parity_Odd;
  144.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  145.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  146.         break;

  147.         case(0x13):
  148.         /* 設置UART串口波特率 14400bps */
  149.         USART_InitStructure.USART_BaudRate = 14400;
  150.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  151.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  152.         USART_InitStructure.USART_Parity = USART_Parity_Odd;
  153.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  154.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  155.         break;

  156.         case(0x14):
  157.         /* 設置UART串口波特率  19200bps*/
  158.         USART_InitStructure.USART_BaudRate = 19200;
  159.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  160.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  161.         USART_InitStructure.USART_Parity = USART_Parity_Odd;
  162.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  163.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  164.         break;

  165.         case(0x15):
  166.         /* 設置UART串口波特率 38400bps */
  167.         USART_InitStructure.USART_BaudRate = 38400;
  168.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  169.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  170.         USART_InitStructure.USART_Parity = USART_Parity_Odd;
  171.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  172.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  173.          break;

  174.         case(0x16):
  175.         /* 設置UART串口波特率   57600bps */
  176.         USART_InitStructure.USART_BaudRate = 57600;
  177.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  178.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  179.         USART_InitStructure.USART_Parity = USART_Parity_Odd;
  180.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  181.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  182.          break;


  183. //=============偶校驗通訊設置區域========================
  184.         case(0x21):
  185.         /* 設置UART串口波特率4800bps */
  186.         USART_InitStructure.USART_BaudRate = 4800;
  187.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  188.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  189.         USART_InitStructure.USART_Parity = USART_Parity_Even;
  190.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  191.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  192.         break;

  193.         case(0x22):
  194.         /* 設置UART串口波特率  9600bps*/
  195.         USART_InitStructure.USART_BaudRate = 9600;
  196.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  197.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  198.         USART_InitStructure.USART_Parity = USART_Parity_Even;
  199.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  200.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  201.           break;

  202.         case(0x23):
  203.         /* 設置UART串口波特率 14400bps*/
  204.         USART_InitStructure.USART_BaudRate = 14400;
  205.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  206.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  207.         USART_InitStructure.USART_Parity = USART_Parity_Even;
  208.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  209.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  210.          break;

  211.         case(0x24):
  212.         /* 設置UART串口波特率  19200bps */
  213.         USART_InitStructure.USART_BaudRate = 19200;
  214.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  215.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  216.         USART_InitStructure.USART_Parity = USART_Parity_Even;
  217.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  218.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  219.         break;

  220.         case(0x25):
  221.         /* 設置UART串口波特率 38400bps */
  222.         USART_InitStructure.USART_BaudRate = 38400;
  223.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  224.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  225.         USART_InitStructure.USART_Parity = USART_Parity_Even;
  226.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  227.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  228.         break;

  229.         case(0x26):
  230.         /* 設置UART串口波特率 57600bps */
  231.         USART_InitStructure.USART_BaudRate = 57600;
  232.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  233.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  234.         USART_InitStructure.USART_Parity = USART_Parity_Even;
  235.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  236.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  237.         break;


  238. //==============出現異常后的處理  9600bps 8 N 1
  239.         default:
  240.         /* 設置UART串口波特率 38400bps */
  241.         USART_InitStructure.USART_BaudRate = 38400;
  242.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  243.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  244.         USART_InitStructure.USART_Parity = USART_Parity_No;
  245.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  246.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  247.         break;

  248.         }

  249.   /* Configure the USART2*/
  250.   USART_Init(USART2, &USART_InitStructure);

  251.   /* Enable USART1 Receive and Transmit interrupts */
  252.   USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  253.   USART_ITConfig(USART2, USART_IT_TC, ENABLE);

  254.   /* Enable the USART1 */
  255.   USART_Cmd(USART2, ENABLE);


  256. // 初始化 串口輸入輸出緩沖
  257.   uart1_time = 0;
  258.   uart1_txall = 0;
  259.   uart1_txptr = 0;
  260.   uart1_rxptr = 0;

  261. }

  262. //=================================================================================================================



  263. //=================================================================================================================
  264. //=================================================================================================================
  265. //=================================================================================================================
  266. /****************************************************************************  F
  267. * 名稱:uart1_dispose()
  268. * 功能:串口uart1數據處理。          專用編程接口
  269. * 入口參數:無
  270. * 出口參數:無
  271. ****************************************************************************/
  272. void uart1_dispose(void)
  273. {
  274. unsigned char bitres;
  275. unsigned short address;
  276. unsigned short length;
  277. unsigned short counter;

  278. unsigned char  ta;
  279. //
  280. unsigned short tc;


  281. if((uart1_rxptr > 4) && (uart1_time > 10))
  282. {

  283. if((uart1_rxbuf[0] == 0x00) || (uart1_rxbuf[0] ==  program[0x1b]) ) //通訊地址判斷機制——8位模式         #### 以后用數據表參數代替
  284.         {
  285.         crc3 = uart1_rxbuf[uart1_rxptr - 2];
  286.         crc4 = uart1_rxbuf[uart1_rxptr - 1];

  287.         uart_crc(uart1_rxbuf , (uart1_rxptr - 2));


  288.            if((crc3 == crc1)&&(crc4 == crc2))
  289.                 {

  290.         /*********@@@@@@@@@@@@@@@@解釋執行程序 begin @@@@@@@@@@@@@@@***********/
  291.         switch(uart1_rxbuf[1])
  292.                 {
  293.                 //+++++++++++++++++++++++++++++++++++++++++++++++
  294.                 case(0x01):
  295.                 address = uart1_rxbuf[2];
  296.                 address = address << 8;
  297.                 address |= uart1_rxbuf[3];
  298.                 bitres = address & 0x0f;
  299.                 address = address >> 4;
  300.                
  301.                 length = uart1_rxbuf[4];
  302.                 length = length << 8;
  303.                 length |= uart1_rxbuf[5];
  304.                
  305.                 if(length == 0) length = 1;

  306.                 ta = 0;
  307.                 uart1_txbuf[0] = uart1_rxbuf[0];
  308.                 uart1_txbuf[1] = uart1_rxbuf[1];
  309.                 //uart1_txbuf[2] =
  310.                 counter = 3;
  311.                 uart1_txbuf[counter] = 0;

  312.                 while(length)
  313.                         {
  314.                         if(memory[address] & (1<<bitres))
  315.                                 {
  316.                                 uart1_txbuf[counter] |= (1<<ta);
  317.                                 }
  318.                         else
  319.                                 {
  320.                                 uart1_txbuf[counter] &= ~(1<<ta);
  321.                                 }
  322.                         bitres++;
  323.                         if(bitres == 16)
  324.                                 {
  325.                                 bitres = 0;
  326.                                 address ++;
  327.                                 }
  328.                         ta++;
  329.                         length--;
  330.                         if((ta == 8)&(length != 0))
  331.                                 {
  332.                                 ta = 0;
  333.                                 counter ++;
  334.                                 uart1_txbuf[counter] = 0;
  335.                                 }
  336.                         
  337.                         }
  338.                 uart1_txbuf[2] = counter - 2;
  339.                 uart_crc(uart1_txbuf,(counter + 1));
  340.                 uart1_txbuf[counter+1] = crc1;
  341.                 uart1_txbuf[counter+2] = crc2;
  342.                 uart1_txall = counter+2;

  343.                 uart1_txptr = 0;
  344.                 COM1_OUT;
  345.                 USART2->DR = uart1_txbuf[0];

  346.                 break;
  347.                 //+++++++++++++++++++++++++++++++++++++++++++++++
  348.                 //+++++++++++++++++++++++++++++++++++++++++++++++
  349.                 case(0x05):
  350.                 address = uart1_rxbuf[2];
  351.                 address = address << 8;
  352.                 address |= uart1_rxbuf[3];
  353.                 bitres = address & 0x0f;
  354.                 address = address >> 4;
  355.                
  356.                 if((uart1_rxbuf[4] == 0xff) && (uart1_rxbuf[5] == 0x00))
  357.                 {
  358.                 memory[address] |= (1<< bitres);
  359.                 }
  360.                 else if((uart1_rxbuf[4] == 0x00) && (uart1_rxbuf[5] == 0x00))
  361.                 {
  362.                 memory[address] &= ~(1<< bitres);
  363.                 }

  364.                 uart1_txbuf[0] = uart1_rxbuf[0];
  365.                 uart1_txbuf[1] = uart1_rxbuf[1];
  366.                 uart1_txbuf[2] = uart1_rxbuf[2];
  367.                 uart1_txbuf[3] = uart1_rxbuf[3];
  368.                 uart1_txbuf[4] = uart1_rxbuf[4];
  369.                 uart1_txbuf[5] = uart1_rxbuf[5];
  370.                 uart1_txbuf[6] = uart1_rxbuf[6];
  371.                 uart1_txbuf[7] = uart1_rxbuf[7];
  372.                 uart1_txall = 7;

  373.                 //-----------------

  374.                 uart1_txptr = 0;
  375.                 COM1_OUT;
  376.                 USART2->DR = uart1_txbuf[0];
  377.                 break;



  378.                 //+++++++++++++++++++++++++++++++++++++++++++++++
  379.                 case(0x03):        
  380.                 address = uart1_rxbuf[2];
  381.                 address = address << 8;
  382.                 address |= uart1_rxbuf[3];

  383.                 length = uart1_rxbuf[4];
  384.                 length = length << 8;
  385.                 length |= uart1_rxbuf[5];
  386.                 if(length == 0) length = 1;

  387.                 counter = 2;
  388.                 uart1_txbuf[0] = uart1_rxbuf[0];
  389.                 uart1_txbuf[1] = uart1_rxbuf[1];
  390.                
  391.                   while(length)
  392.                           {
  393.                           counter ++;
  394.                           uart1_txbuf[counter] = memory[address] >> 8;
  395.                           counter ++;
  396.                           uart1_txbuf[counter] = memory[address] & 0x00ff;
  397.   
  398.                           length --;
  399.                           address ++;
  400.                           }
  401.                   
  402.                 uart1_txbuf[2]= counter -2;
  403.                 uart_crc(uart1_txbuf,(counter + 1));
  404.                 uart1_txbuf[counter+1] = crc1;
  405.                 uart1_txbuf[counter+2] = crc2;
  406.                 uart1_txall = counter+2;

  407.                 uart1_txptr = 0;
  408.                 COM1_OUT;
  409.                 USART2->DR = uart1_txbuf[0];
  410.                 break;
  411.                 //+++++++++++++++++++++++++++++++++++++++++++++++
  412.             /*
  413.                 //+++++++++++++++++++++++++++++++++++++++++++++++
  414.                 case(0x0F):
  415.                 address = uart1_rxbuf[2];
  416.                 address = address << 8;
  417.                 address |= uart1_rxbuf[3];
  418.                 bitres = address & 0x0f;
  419.                 address = address >> 4;
  420.                
  421.                 length = uart1_rxbuf[4];
  422.                 length = length << 8;
  423.                 length |= uart1_rxbuf[5];

  424.                 uart1_txbuf[0] = uart1_rxbuf[0];
  425.                 uart1_txbuf[1] = uart1_rxbuf[1];
  426.                 uart1_txbuf[2] = uart1_rxbuf[2];
  427.                 uart1_txbuf[3] = uart1_rxbuf[3];
  428.                 uart1_txbuf[4] = uart1_rxbuf[4];
  429.                 uart1_txbuf[5] = uart1_rxbuf[5];

  430.                 ta  = 0;
  431.                 counter = 7;

  432.                 //-----------------
  433.                         while(length)
  434.                                 {
  435.                                 if(uart1_rxbuf[counter] & (1<<ta))
  436.                                         {
  437.                                         memory[address] |= (1<<bitres);
  438.                                         }
  439.                                 else
  440.                                         {
  441.                                         memory[address] &= ~(1<<bitres);
  442.                                         }
  443.                                 bitres++;
  444.                                 if(bitres == 8)
  445.                                         {
  446.                                         bitres = 0;
  447.                                         address ++;
  448.                                         }
  449.                                 ta++;
  450.                                 length--;
  451.                                 if(ta == 8)
  452.                                         {
  453.                                         ta = 0;
  454.                                         counter ++;
  455.                                         }
  456.                         
  457.                                 }


  458.                 uart_crc(uart1_txbuf,6);
  459.                 uart1_txbuf[6] = crc1;
  460.                 uart1_txbuf[7] = crc2;
  461.                 uart1_txall = 7;

  462.                 //-----------------


  463.                 uart1_txptr = 0;
  464.                 COM1_OUT;
  465.                 USART2->DR = uart1_txbuf[0];
  466.                 break;
  467.             */
  468.                 //+++++++++++++++++++++++++++++++++++++++++++++++
  469.                 case(0x10):
  470.                 address = uart1_rxbuf[2];
  471.                 address = address << 8;
  472.                 address |= uart1_rxbuf[3];

  473.                 length = uart1_rxbuf[4];
  474.                 length = length << 8;
  475.                 length |= uart1_rxbuf[5];
  476.                 if(length == 0) length = 1;

  477.                 counter = 7;
  478.                 uart1_txbuf[0] = uart1_rxbuf[0];
  479.                 uart1_txbuf[1] = uart1_rxbuf[1];
  480.                 uart1_txbuf[2] = uart1_rxbuf[2];
  481.                 uart1_txbuf[3] = uart1_rxbuf[3];
  482.                 uart1_txbuf[4] = uart1_rxbuf[4];
  483.                 uart1_txbuf[5] = uart1_rxbuf[5];

  484.                 while(length)
  485.                         {
  486.                         tc = uart1_rxbuf[counter];
  487.                         tc = tc << 8;
  488.                         tc |= uart1_rxbuf[counter +1];
  489.                         memory[address] = tc;

  490.                         counter +=2;
  491.                         address ++;
  492.                         length --;
  493.                         }

  494.                 uart_crc(uart1_txbuf,6);
  495.                 uart1_txbuf[6] = crc1;
  496.                 uart1_txbuf[7] = crc2;
  497.                 uart1_txall = 7;


  498.                 uart1_txptr = 0;
  499.                 COM1_OUT;
  500.                 USART2->DR = uart1_txbuf[0];
  501.                 break;


  502.                 }                                 
  503.         /*********@@@@@@@@@@@@@@@@解釋執行程序 end @@@@@@@@@@@@@@@***********/
  504.             uart1_rxptr = 0;          //清空uart1的緩沖計數 以及 定時
  505.                 uart1_time = 0;
  506.                 }
  507.         else
  508.                 {
  509.                 uart1_rxptr = 0;          //清空uart1的緩沖計數 以及 定時
  510.                 uart1_time = 0;
  511.                 }
  512.         }
  513. else
  514.         {
  515.         uart1_rxptr = 0;                  //清空uart1的緩沖計數 以及 定時
  516.         uart1_time = 0;
  517.         }
  518. }



  519. if((uart1_rxptr <= 4) && (uart1_time > 15))
  520.     {
  521.         uart1_rxptr = 0;                  //清空uart1的緩沖計數 以及 定時
  522.         uart1_time = 0;
  523.     }



  524. }


  525. /****************************************************************************  F
  526. * 名稱:uart0_dispose()
  527. * 功能:串口uart0數據處理。
  528. * 入口參數:無
  529. * 出口參數:無
  530. ****************************************************************************/
  531. void uart0_dispose(void)
  532. {
  533. unsigned short address;

  534. unsigned char  ta;
  535. //
  536. unsigned short tt,tc;
  537. if((uart0_rxptr > 4) && (uart0_time > 9))
  538. {

  539. if((uart0_rxbuf[0] == 0x01)&&(uart0_rxbuf[1] == 0x55)&&(uart0_rxbuf[2] == 0xaa)&&(uart0_rxbuf[11] == 0x12)&&(uart0_rxbuf[12] == 0xef)&&(uart0_rxbuf[13] == 0xff))
  540.     {
  541.       /*********@@@@@@@@@@@@@@@@編程口解釋執行程序 begin @@@@@@@@@@@@@@@***********/
  542.       if(uart0_rxbuf[3] == 0x00)          //讀參數系統
  543.              {
  544.           address = uart0_rxbuf[5];
  545.           address = address << 8;
  546.           address |= uart0_rxbuf[6];
  547.                switch(uart0_rxbuf[4])
  548.             {
  549.                     //=====================================================================
  550.             case(0x00):   
  551.                     uart0_txbuf[7] = memory[address];
  552.                     uart0_txbuf[8] = memory[address] >> 8;
  553.                     uart0_txbuf[9] = memory[address + 1];
  554.                     uart0_txbuf[10] = memory[address + 1] >> 8;
  555.             break;
  556.                     //=====================================================================
  557.             case(0x11):
  558.                     uart0_txbuf[7] = program[address];

  559.                     uart0_txbuf[8] = program[address + 1];

  560.                     uart0_txbuf[9] = program[address + 2];

  561.                     uart0_txbuf[10] = program[address + 3];
  562.             break;

  563.             }
  564.           uart0_txbuf[0] = 0x02;
  565.           uart0_txbuf[1] = 0xAA;
  566.           uart0_txbuf[2] = 0x55;

  567.           uart0_txbuf[3] = 0x00;
  568.           uart0_txbuf[4] = uart0_rxbuf[4];
  569.           uart0_txbuf[5] = uart0_rxbuf[5];
  570.           uart0_txbuf[6] = uart0_rxbuf[6];

  571.           uart0_txbuf[11] = 0x34;
  572.           uart0_txbuf[12] = 0xcd;
  573.           uart0_txbuf[13] = 0xff;

  574.           uart0_txall = 13;
  575.           uart0_txptr = 0;
  576.           USART1->DR = uart0_txbuf[0];
  577.             }
  578.       else if(uart0_rxbuf[3] == 0x11)         //寫參數系統
  579.              {
  580.           address = uart0_rxbuf[5];
  581.           address = address << 8;
  582.           address |= uart0_rxbuf[6];
  583.           switch(uart0_rxbuf[4])
  584.             {
  585.                     //=====================================================================
  586.             case(0x00):
  587.               tc = uart0_rxbuf[8];
  588.               tc = tc << 8;
  589.               tc |= uart0_rxbuf[7];
  590.               memory[address] = tc;
  591.               tc = uart0_rxbuf[10];
  592.               tc = tc << 8;
  593.               tc |= uart0_rxbuf[9];
  594.               memory[address + 1] = tc;
  595.             break;
  596.                     //=====================================================================
  597.                     //=====================================================================
  598.             case(0x11):
  599.               if(address == 0)
  600.               {
  601.                   FLASH_Unlock();
  602.                   FLASH_ErasePage(0x0800C000);
  603.                   FLASH_ErasePage(0x0800C400);
  604.                   FLASH_ErasePage(0x0800C800);
  605.                   FLASH_ErasePage(0x0800CC00);
  606.                   
  607.                   FLASH_ErasePage(0x0800D000);
  608.                   FLASH_ErasePage(0x0800D400);
  609.                   FLASH_ErasePage(0x0800D800);
  610.                   FLASH_ErasePage(0x0800DC00);
  611.                   
  612.                   FLASH_ErasePage(0x0800E000);
  613.                   FLASH_ErasePage(0x0800E400);
  614.                   FLASH_ErasePage(0x0800E800);
  615.                   FLASH_ErasePage(0x0800EC00);
  616.                   
  617.                   FLASH_ErasePage(0x0800F000);
  618.                   FLASH_ErasePage(0x0800F400);
  619.                   FLASH_ErasePage(0x0800F800);
  620.                   FLASH_ErasePage(0x0800FC00);
  621.               }
  622.               
  623.               tc = uart0_rxbuf[8];
  624.               tc = tc << 8;
  625.               tc |= uart0_rxbuf[7];
  626.               FLASH_ProgramHalfWord( (0x0800C000 + address), tc);
  627.               
  628.               tc = uart0_rxbuf[10];
  629.               tc = tc << 8;
  630.               tc |= uart0_rxbuf[9];
  631.               FLASH_ProgramHalfWord( (0x0800C000 + address + 2), tc);
  632.               
  633.             break;
  634.             }     

  635.           uart0_txbuf[0] = 0x02;
  636.           uart0_txbuf[1] = 0xAA;
  637.           uart0_txbuf[2] = 0x55;

  638.           uart0_txbuf[3] = 0x11;
  639.           uart0_txbuf[4] = uart0_rxbuf[4];
  640.           uart0_txbuf[5] = uart0_rxbuf[5];
  641.           uart0_txbuf[6] = uart0_rxbuf[6];
  642.   
  643.           uart0_txbuf[7] = uart0_rxbuf[7];
  644.           uart0_txbuf[8] = uart0_rxbuf[8];
  645.           uart0_txbuf[9] = uart0_rxbuf[9];
  646.           uart0_txbuf[10] = uart0_rxbuf[10];

  647.           uart0_txbuf[11] = 0x34;
  648.           uart0_txbuf[12] = 0xCD;
  649.           uart0_txbuf[13] = 0xFF;

  650.           uart0_txall = 13;
  651.           uart0_txptr = 0;
  652.           USART1->DR = uart0_txbuf[0];
  653.              }
  654.       else if(uart0_rxbuf[3] == 0x30)         //特殊指令
  655.              {
  656. ……………………

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

工程是IAR編譯的51hei附件下載:
STM32仿三菱PLC開源代碼.7z (500.17 KB, 下載次數: 1167)
STM32F103RBT6_開源PLC原理圖.pdf (897.25 KB, 下載次數: 1048)


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

來自 2#
ID:71883 發表于 2019-10-12 14:37 | 只看該作者
請問樓主梯形圖用什么軟件編譯,編譯完成后代碼下載到單片機,和編譯軟件怎么通信。
回復

使用道具 舉報

來自 3#
ID:795427 發表于 2020-10-2 09:04 | 只看該作者
這是通過什么軟件編譯的,反正不是keil軟件。
回復

使用道具 舉報

來自 4#
ID:272119 發表于 2020-10-2 10:28 | 只看該作者
我目前也正好做這個,不過都是自己一點點啃代碼,串口數據轉坐標脈沖算法我至少花了一周,伺服電機的S型啟動和停止我至少用了3個算法方案,最后勉強用數組寫固定式緩沖才勉強撐住.
回復

使用道具 舉報

5#
ID:77110 發表于 2019-4-19 21:25 | 只看該作者
its = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_Odd;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_
回復

使用道具 舉報

6#
ID:74303 發表于 2019-5-26 20:37 | 只看該作者
下載學習
回復

使用道具 舉報

7#
ID:415096 發表于 2019-5-27 11:26 | 只看該作者
下載學習,可是沒有硬件也是理解不了的
回復

使用道具 舉報

8#
ID:82419 發表于 2019-5-27 20:23 來自手機 | 只看該作者
留個腳印!以后有需要來下載
回復

使用道具 舉報

9#
ID:557411 發表于 2019-6-8 11:46 | 只看該作者
完整資源開源,樓主好樣的,佩服!找了好久了,感謝樓主和我們這個交流學習平臺
回復

使用道具 舉報

10#
ID:113936 發表于 2019-6-10 18:48 | 只看該作者
能下載梯形圖嗎
回復

使用道具 舉報

11#
ID:46999 發表于 2019-8-16 17:13 | 只看該作者
不錯。先記下了。
回復

使用道具 舉報

12#
ID:240452 發表于 2019-8-17 12:44 | 只看該作者

留個腳印!
回復

使用道具 舉報

13#
ID:166646 發表于 2019-8-19 10:24 | 只看該作者
這個很NB,謝謝了
回復

使用道具 舉報

14#
ID:69421 發表于 2019-8-23 18:27 來自手機 | 只看該作者
誰有開發板試試能行不告知一聲
回復

使用道具 舉報

15#
ID:603960 發表于 2019-8-26 16:35 | 只看該作者
樓主牛逼 ,這個東西可以好好參考參考了
回復

使用道具 舉報

16#
ID:606788 發表于 2019-9-4 18:05 | 只看該作者
謝謝分享
回復

使用道具 舉報

17#
ID:606788 發表于 2019-9-5 08:39 | 只看該作者
謝謝分享
回復

使用道具 舉報

18#
ID:482794 發表于 2019-10-13 14:01 | 只看該作者
謝謝分享
回復

使用道具 舉報

19#
ID:629247 發表于 2019-10-24 21:47 | 只看該作者
怎么打開文件,找不到工程文件啊,各位大蝦指導下新人
回復

使用道具 舉報

20#
ID:52896 發表于 2019-11-12 06:06 | 只看該作者
感謝分享,下載學習
回復

使用道具 舉報

21#
ID:383657 發表于 2019-11-17 22:37 | 只看該作者
下載學習學習
回復

使用道具 舉報

22#
ID:492919 發表于 2019-11-23 14:47 | 只看該作者
不錯的東東.感謝樓主分享
回復

使用道具 舉報

23#
ID:195496 發表于 2019-11-30 20:34 | 只看該作者
謝謝分享,學習一下
回復

使用道具 舉報

24#
ID:128391 發表于 2019-12-1 16:51 | 只看該作者
感謝大大的分享,收下學習!
回復

使用道具 舉報

25#
ID:164036 發表于 2019-12-13 22:11 | 只看該作者
謝謝大佬分享,我找個開發板下進去試試看
回復

使用道具 舉報

26#
ID:658136 發表于 2019-12-29 23:46 | 只看該作者
謝謝分享,學習一下
回復

使用道具 舉報

27#
ID:292577 發表于 2019-12-31 15:34 | 只看該作者
完整資源開源,樓主好樣的,佩服!
回復

使用道具 舉報

28#
ID:693370 發表于 2020-3-6 18:32 | 只看該作者
下載學習
回復

使用道具 舉報

29#
ID:369697 發表于 2020-3-10 12:11 | 只看該作者
下載學習中,謝謝LZ分享
回復

使用道具 舉報

30#
ID:574873 發表于 2020-3-10 15:15 | 只看該作者
這個很NB,謝謝了,能不能在線仿真調試梯形圖?
回復

使用道具 舉報

31#
ID:697917 發表于 2020-3-11 10:46 | 只看該作者
謝謝,正在尋找仿PLC的內容
回復

使用道具 舉報

32#
ID:91165 發表于 2020-3-11 13:06 | 只看該作者
直接梯形圖串口傳程序嗎
回復

使用道具 舉報

33#
ID:719527 發表于 2020-3-31 14:57 | 只看該作者
仿PLC的資料有用過的嗎
回復

使用道具 舉報

34#
ID:719527 發表于 2020-3-31 14:58 | 只看該作者
謝謝。下載學習
回復

使用道具 舉報

35#
ID:719527 發表于 2020-3-31 15:00 | 只看該作者
有用嗎?有試過的嗎
回復

使用道具 舉報

36#
ID:719527 發表于 2020-4-1 13:35 | 只看該作者
下載來看看有沒用
回復

使用道具 舉報

37#
ID:716711 發表于 2020-4-9 09:26 | 只看該作者
感謝分享,我有硬件原理圖,這個程序先mark 一下,哪天想動手做一塊了,來學習研究。
回復

使用道具 舉報

38#
ID:430492 發表于 2020-4-9 11:51 | 只看該作者
非常棒啊!完整資源開源,樓主好樣的,佩服!
回復

使用道具 舉報

39#
ID:254011 發表于 2020-4-12 00:10 | 只看該作者
下載學習,謝謝樓主
回復

使用道具 舉報

40#
ID:313434 發表于 2020-4-16 10:32 | 只看該作者
謝謝分享
回復

使用道具 舉報

41#
ID:142383 發表于 2020-4-16 16:16 | 只看該作者
感謝樓主分享,下載學習學習。
回復

使用道具 舉報

42#
ID:105206 發表于 2020-5-1 08:49 | 只看該作者
下載學習,謝謝樓主
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久在看| 久久久久久久久久久久一区二区 | 久精品视频 | 四虎精品在线 | 久久精品国产一区二区电影 | 91久久久久久久久久久 | 91久久精品日日躁夜夜躁国产 | 欧美激情一区二区 | 一级毛片免费完整视频 | 欧美午夜视频 | 337p日韩| 97人人超碰| 69福利影院| 国产视频二区在线观看 | 国产一区二区久久久 | 亚洲高清久久 | 在线观看免费毛片 | 欧美激情一区二区三区 | 久久久久久国产精品 | 成人精品鲁一区一区二区 | 久久国产成人 | 色综合国产 | 伊人二区 | 亚洲一区二区三区视频免费观看 | 毛片黄片免费看 | 国产欧美三区 | 午夜精品一区二区三区在线视频 | 九九热在线视频 | 亚洲第一av | 一级片免费在线观看 | 午夜精品久久久久久久久久久久久 | 欧美1区 | 日韩黄色免费 | 国产高清在线 | 国产精品小视频在线观看 | 精品亚洲一区二区三区 | 亚洲毛片| 亚洲欧美视频一区 | 国产综合网址 | 欧美精品一区二区免费视频 | 97视频网站 |