当前位置:   article > 正文

【STM32】【C】【嵌入式】分享一下我的项目经验--基于stm32桌面主从机械臂设计(三弹)_#define__motor_h

#define__motor_h

本文为原创文章,转载需要注明转载出处

 前言:嵌入式开发是相比其他IT行业是比较难的行业,它不仅需要你去掌握软件的经验,还要去学习一些硬件的知识,

它是软件和硬件的一个粘合剂,起到一个至关重要的地位

下面我们接着讲第三弹 

 

【STM32】【C】【嵌入式】分享一下我的项目经验--基于stm32桌面主从机械臂设计(一弹)

【STM32】【C】【嵌入式】分享一下我的项目经验--基于stm32桌面主从机械臂设计(二弹)

【STM32】【C】【嵌入式】分享一下我的项目经验--基于stm32桌面主从机械臂设计(三弹)

 

下面是从机械臂的代码

 

下面是/*motor.h*/

  1. #ifndef __MOTOR_H__
  2. #define __MOTOR_H__
  3. #include "sys.h"
  4. #define FALSE 0
  5. #define TRUE 1
  6. #define MS1_left PAout(0)
  7. #define MS2_left PAout(1)
  8. #define MS3_left PAout(2)
  9. #define DIR_left PAout(3)
  10. #define STEP_left PAout(4)
  11. #define ENABLE1_left PAout(5)
  12. #define MS1_right PBout(0)
  13. #define MS2_right PAout(7)
  14. #define MS3_right PAout(6)
  15. #define DIR_right PBout(1)
  16. #define STEP_right PBout(10)
  17. #define ENABLE2_right PBout(11)
  18. #define MS1 PBout(3)
  19. #define MS2 PBout(5) //PA15ÓÐÎÊÌâ PB4ÓÐÎÊÌâ
  20. #define MS3 PAout(8)
  21. #define DIR PBout(15)
  22. #define STEP PBout(14)
  23. #define ENABLE0 PBout(13)
  24. #define Full_step {MS1_left = 0;MS2_left = 0;MS3_left = 0;MS1_right = 0;MS2_right = 0;MS3_right = 0;}
  25. #define Half_step {MS1_left = 1;MS2_left = 0;MS3_left = 0;MS1_right = 1;MS2_right = 0;MS3_right = 0;}
  26. #define Quarter_step {MS1_left = 0;MS2_left = 1;MS3_left = 0;MS1_right = 0;MS2_right = 1;MS3_right = 0;}
  27. #define Eighth_step {MS1_left = 1;MS2_left = 1;MS3_left = 0;MS1_right = 1;MS2_right = 1;MS3_right = 0;}
  28. #define Sixteenth_step {MS1_left = 1;MS2_left = 1;MS3_left = 1;MS1_right = 1;MS2_right = 1;MS3_right = 1;}
  29. #define Full_step0 {MS1 = 0;MS2 = 0; MS3 = 0;}
  30. #define Half_step0 {MS1 = 1;MS2 = 0; MS3 = 0;}
  31. #define Quarter_step0 {MS1 = 0;MS2 = 1; MS3 = 0;}
  32. #define Eighth_step0 {MS1 = 1;MS2 = 1; MS3 = 0;}
  33. #define Sixteenth_step0 {MS1 = 1;MS2 = 1; MS3 = 1;}
  34. #define Full_360 5000
  35. #define Half_180 2500
  36. #define Quarter_90 1250
  37. #define Eighth_45 625
  38. #define Nine_9 125
  39. #define Eighteen_18 250
  40. #define Twenty_seven_27 375
  41. #define Thirty_six_36 500
  42. #define One_1 14
  43. #define Four_5 70
  44. void MOTOR_Step_Control(int dir,u16 period,u32 steps);
  45. void MOTOR_Init(void);
  46. void MOTOR_Step_Init(void);
  47. void MOTOR_Step_Enable(void);
  48. void MOTOR_Step_Micr(u16);
  49. void MOTOR_Step2_Enable(void);
  50. void MOTOR_Step2_Micr(u16);
  51. void MOTOR_Step2_Control(int dir,u16 period,u32 steps);
  52. void MOTOR_Step3_Enable(void);
  53. void MOTOR_Step3_Micr(u16);
  54. void MOTOR_Step3_Control(int dir,u16 period,u32 steps);
  55. void TIM3_PWM_Init(u16 arr,u16 psc);
  56. #endif

 

下面是/*motor.c*/

  1. #include "motor.h"
  2. #include "stm32f10x.h"
  3. #include "delay.h"
  4. #include "sys.h"
  5. void MOTOR_Init(void){
  6. GPIO_InitTypeDef GPIO_InitStructure;
  7. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE); // PA,PD
  8. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  9. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //????
  10. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO ???? 50MHz
  11. //MS1->L MS2->L MS3->L Full step //2 Phase
  12. //MS3
  13. GPIO_Init(GPIOA, &GPIO_InitStructure); //??? GPIOA.2
  14. GPIO_ResetBits(GPIOA,GPIO_Pin_0); //PA.1 ???
  15. //MS2
  16. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  17. GPIO_Init(GPIOA, &GPIO_InitStructure);
  18. GPIO_ResetBits(GPIOA,GPIO_Pin_1);
  19. //MS1
  20. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  21. GPIO_Init(GPIOA, &GPIO_InitStructure);
  22. GPIO_ResetBits(GPIOA,GPIO_Pin_2);
  23. //DIR
  24. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  25. GPIO_Init(GPIOA, &GPIO_InitStructure);
  26. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  27. //STEP
  28. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  29. GPIO_Init(GPIOA, &GPIO_InitStructure);
  30. GPIO_ResetBits(GPIOA,GPIO_Pin_4);
  31. //MS1->L MS2->L MS3->L Full step //2 Phase
  32. //ENABLE
  33. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  34. GPIO_Init(GPIOB, &GPIO_InitStructure); //??? GPIOA.2
  35. GPIO_ResetBits(GPIOB,GPIO_Pin_11); //PA.1 ???
  36. //STEP
  37. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  38. GPIO_Init(GPIOB, &GPIO_InitStructure);
  39. GPIO_ResetBits(GPIOB,GPIO_Pin_10);
  40. //DIR
  41. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  42. GPIO_Init(GPIOB, &GPIO_InitStructure);
  43. GPIO_ResetBits(GPIOB,GPIO_Pin_1);
  44. //MS1
  45. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  46. GPIO_Init(GPIOB, &GPIO_InitStructure);
  47. GPIO_ResetBits(GPIOB,GPIO_Pin_0);
  48. //MS2
  49. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  50. GPIO_Init(GPIOA, &GPIO_InitStructure);
  51. GPIO_ResetBits(GPIOA,GPIO_Pin_7);
  52. //MS3
  53. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  54. GPIO_Init(GPIOA, &GPIO_InitStructure);
  55. GPIO_ResetBits(GPIOA,GPIO_Pin_6);
  56. //MS1
  57. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  58. GPIO_Init(GPIOB, &GPIO_InitStructure);
  59. GPIO_ResetBits(GPIOB,GPIO_Pin_3);
  60. //MS2
  61. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  62. GPIO_Init(GPIOB, &GPIO_InitStructure);
  63. GPIO_ResetBits(GPIOB,GPIO_Pin_5);
  64. //MS3
  65. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  66. GPIO_Init(GPIOA, &GPIO_InitStructure);
  67. GPIO_ResetBits(GPIOA,GPIO_Pin_8);
  68. //DIR
  69. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  70. GPIO_Init(GPIOB, &GPIO_InitStructure);
  71. GPIO_ResetBits(GPIOB,GPIO_Pin_15);
  72. //STEP
  73. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
  74. GPIO_Init(GPIOB, &GPIO_InitStructure);
  75. GPIO_ResetBits(GPIOB,GPIO_Pin_14);
  76. //ENABLE
  77. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  78. GPIO_Init(GPIOB, &GPIO_InitStructure);
  79. GPIO_ResetBits(GPIOB,GPIO_Pin_13);
  80. }
  81. void MOTOR_Step_Control(int dir,u16 period,u32 steps){
  82. u32 i;
  83. if(dir == 1){
  84. for(i = 0;i < steps;i++){
  85. DIR_left = 1;
  86. STEP_left = 0;
  87. //delay_ms(800);
  88. delay_ms(1);
  89. STEP_left = 1;
  90. //delay_ms(800);
  91. delay_us(period);
  92. }
  93. }
  94. if(dir == 0){
  95. for(i = 0;i < steps;i++){
  96. DIR_left = 0;
  97. STEP_left = 0;
  98. //delay_ms(800);
  99. delay_ms(1);
  100. STEP_left = 1;
  101. //delay_ms(800);
  102. delay_us(period);
  103. }
  104. }
  105. /*
  106. for(i = 0;i < steps * 2;i++){
  107. DIR = !dir;
  108. STEP = 1;
  109. delay_us(4);
  110. STEP = 0;
  111. delay_us(period);
  112. }
  113. */
  114. //i = 0;
  115. }
  116. void MOTOR_Step_Init(void){
  117. #if 0
  118. RCC->APB2ENR |= 1 << 3; //ʹÄÜʱÖÓ
  119. GPIOA->CRL &= 0xFF000000;
  120. GPIOA->CRL |= 0x00333333;
  121. #endif
  122. #if 0
  123. //RCC->APB2ENR |= 1 << 3;
  124. GPIOB->CRL &= 0x00000FFF;
  125. GPIOB->CRH &= 0xFFFFFFF0;
  126. GPIOB->CRL |= 0x33333000;
  127. GPIOB->CRH |= 0x00000003;
  128. //MS1 = 0;
  129. //MS2 = 0;
  130. //MS3 = 0;
  131. #endif
  132. }
  133. void MOTOR_Step_Enable(void){
  134. ENABLE1_left = 0;
  135. ENABLE2_right = 0;
  136. }
  137. void MOTOR_Step_Micr(u16 x){
  138. switch(x){
  139. case 1:Full_step; break;
  140. case 2:Half_step; break;
  141. case 4:Quarter_step; break;
  142. case 8: Eighth_step; break;
  143. case 16: Sixteenth_step; break;
  144. defalut: break;
  145. }
  146. }
  147. void MOTOR_Step2_Control(int dir,u16 period,u32 steps){
  148. u32 i;
  149. if(dir == 1){
  150. for(i = 0;i < steps;i++){
  151. DIR_right = 1;
  152. STEP_right = 0;
  153. //delay_ms(800);
  154. delay_ms(1);
  155. STEP_right = 1;
  156. //delay_ms(800);
  157. delay_us(period);
  158. }
  159. }
  160. if(dir == 0){
  161. for(i = 0;i < steps;i++){
  162. DIR_right = 0;
  163. STEP_right = 0;
  164. //delay_ms(800);
  165. delay_ms(1);
  166. STEP_right = 1;
  167. //delay_ms(800);
  168. delay_us(period);
  169. }
  170. }
  171. }
  172. void MOTOR_Step2_Enable(void){
  173. ENABLE0 = 0;
  174. }
  175. void MOTOR_Step2_Micr(u16 x){
  176. switch(x){
  177. case 1:Full_step0; break;
  178. case 2:Half_step0; break;
  179. case 4:Quarter_step0; break;
  180. case 8: Eighth_step0; break;
  181. case 16: Sixteenth_step0; break;
  182. defalut: break;
  183. }
  184. }
  185. void MOTOR_Step3_Control(int dir,u16 period,u32 steps){
  186. u32 i;
  187. if(dir == 1){
  188. for(i = 0;i < steps;i++){
  189. DIR = 1;
  190. STEP = 0;
  191. //delay_ms(800);
  192. delay_ms(1);
  193. STEP = 1;
  194. //delay_ms(800);
  195. delay_us(period);
  196. }
  197. }
  198. if(dir == 0){
  199. for(i = 0;i < steps;i++){
  200. DIR = 0;
  201. STEP = 0;
  202. //delay_ms(800);
  203. delay_ms(1);
  204. STEP = 1;
  205. //delay_ms(800);
  206. delay_us(period);
  207. }
  208. }
  209. }
  210. void MOTOR_Step3_Enable(void){
  211. ENABLE0 = 0;
  212. }
  213. void MOTOR_Step3_Micr(u16 x){
  214. switch(x){
  215. case 1:Full_step0; break;
  216. case 2:Half_step0; break;
  217. case 4:Quarter_step0; break;
  218. case 8: Eighth_step0; break;
  219. case 16: Sixteenth_step0; break;
  220. defalut: break;
  221. }
  222. }

 

下面是/*blue.h*/

  1. #ifndef __BLUE_H__
  2. #define __BLUE_H __
  3. #include "sys.h"
  4. #include "stdarg.h"
  5. #include "stdio.h"
  6. #include "string.h"
  7. #include "usart.h"
  8. #include <stdio.h>
  9. #include <string.h>
  10. void BLUE_Init(void);
  11. //void RCC_Configuration(void);
  12. //void GPIO_Configuration(void);
  13. //void USART_Configuration(void);
  14. //void UART_PutChar(USART_TypeDef* USARTx, uint8_t Data);
  15. //void UART_PutStr (USART_TypeDef* USARTx, uint8_t *str);
  16. //int Putchar(int c);
  17. void USART1_IRQHandler(void);
  18. extern void data_IRQHandller1(void);
  19. #endif

 

下面是/*blue.c*/

  1. #include "blue.h"
  2. //#include "usart.h"
  3. #include "delay.h"
  4. void BLUE_Init(void){
  5. GPIO_InitTypeDef GPIO_InitStrue;
  6. USART_InitTypeDef USART_InitStrue;
  7. NVIC_InitTypeDef NVIC_InitStrue;
  8. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//?
  9. RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
  10. GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
  11. GPIO_InitStrue.GPIO_Pin=GPIO_Pin_9;
  12. GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
  13. GPIO_Init(GPIOA,&GPIO_InitStrue);//?
  14. GPIO_InitStrue.GPIO_Mode= GPIO_Mode_IN_FLOATING; //GPIO_Mode_IPU;
  15. GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10;
  16. GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
  17. GPIO_Init(GPIOA,&GPIO_InitStrue);
  18. USART_InitStrue.USART_BaudRate=9600;
  19. USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
  20. USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
  21. USART_InitStrue.USART_Parity=USART_Parity_No;
  22. USART_InitStrue.USART_StopBits=USART_StopBits_1;
  23. USART_InitStrue.USART_WordLength=USART_WordLength_8b;
  24. USART_Init(USART1,&USART_InitStrue);//?
  25. USART_Cmd(USART1,ENABLE);
  26. #if 1
  27. USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
  28. NVIC_InitStrue.NVIC_IRQChannel=USART1_IRQn;
  29. NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;
  30. NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=3;
  31. NVIC_InitStrue.NVIC_IRQChannelSubPriority=3;
  32. NVIC_Init(&NVIC_InitStrue);
  33. #endif
  34. }
  35. #if 0
  36. void data_IRQHandller1(void){
  37. u8 a = 0;
  38. u8 Res;
  39. int len;
  40. BUF4[1] = '\0';
  41. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET){
  42. Res= USART_ReceiveData(USART1);
  43. printf("%c",Res);
  44. BUF2[u++] = (Res & (uint16_t)0x01FF);
  45. //USART1->DR = (Res & (uint16_t)0x01FF);
  46. USART1->DR = (uint16_t)BUF2[u-1] ;
  47. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  48. if(BUF2[0] == 0x61 && BUF2[1] == 0x3d){
  49. printf("ok");
  50. }
  51. //USART1->DR = (0x2a & (uint16_t)0x01FF);
  52. //while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  53. }
  54. }
  55. #endif
  56. #if 0
  57. void USART1_IRQHandler(void)
  58. { u8 a = 0;
  59. u8 Res;
  60. //BUF4[1] = '\0';
  61. //printf("%s\r\n","Im fun");
  62. data_IRQHandller1();
  63. //printf("%s\r\n","Im fun");
  64. #if 0
  65. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET)
  66. {
  67. Res= USART_ReceiveData(USART1);
  68. //printf("%c",(Res & (uint16_t)0x01FF));
  69. //USART1->DR = (Res & (uint16_t)0x01FF);
  70. BUF2[a] = (Res & (uint16_t)0x01FF);
  71. //strcat(str,BUF2);
  72. USART_SendData(USART1,BUF2[a]);
  73. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  74. a++;
  75. //BUF4[0] = 0;
  76. BUF2[a] = '\0';
  77. USART_SendData(USART1,BUF2[5]);
  78. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  79. //printf("str=%s,strlen(str)=%d",str,strlen(str));
  80. #endif
  81. //USART_SendData(USART1,Res);
  82. //while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  83. //printf("jieshoudaole");
  84. #if 0
  85. if((USART_RX_STA & 0x8000)== 0){
  86. if(USART_RX_STA&0x4000){
  87. if(Res!=0x0a)
  88. USART_RX_STA=0;
  89. else {
  90. USART_RX_STA|=0x8000;
  91. //printf("jieshoudaole");
  92. //USART_SendData(USART1,Res);
  93. }
  94. //USART_SendData(USART1,Res);
  95. }
  96. else{
  97. if(Res==0x0d)
  98. USART_RX_STA|=0x4000;
  99. else
  100. {
  101. USART_RX_BUF[USART_RX_STA&0X3FFF]=Res;
  102. if((USART_RX_BUF[USART_RX_STA&0X3FFF] == 0x6f)){
  103. BUF2[0] = 0x6f;
  104. #if 0
  105. while(BUF[a] != 0){
  106. USART_SendData(USART1,BUF[a]);
  107. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  108. a++;
  109. }
  110. #endif
  111. }
  112. if((USART_RX_BUF[(USART_RX_STA)&0X3FFF] == 0x6b )){
  113. BUF2[1] = 0x6b;
  114. }
  115. if(USART_RX_BUF[(USART_RX_STA)&0X3FFF] != 0){
  116. BUF4[0] = (char)USART_RX_BUF[(USART_RX_STA)&0X3FFF];
  117. strcat(str,BUF4);
  118. USART_SendData(USART1,BUF4[0]);
  119. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  120. printf("\r\n");
  121. BUF4[0] = 0;
  122. printf("str=%s,strlen(str)=%d\r\n",str,strlen(str));
  123. }
  124. if(BUF2[0] == 0x6f && BUF2[1] == 0x6b){
  125. while(BUF[a] != 0){
  126. USART_SendData(USART1,BUF[a]);
  127. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  128. a++;
  129. BUF2[0] = 0;
  130. BUF2[1] = 0;
  131. }
  132. if(strlen(str) >= 5){
  133. printf("oknihao");
  134. printf(str);
  135. sscanf(str,"%s:%d,%s:%d %s:%d,%s:%d %s:%d,%s:%d",s1,a,s2,n,s3,a2,s4,n2,s5,a3,s6,n3);
  136. printf(s1);
  137. }
  138. //USART_RX_STA++;
  139. }
  140. //USART_SendData(USART1,USART_RX_BUF[USART_RX_STA&0X3FFF] ); //send ok
  141. USART_RX_STA++;
  142. a++;
  143. if(USART_RX_STA>(USART_REC_LEN-1))
  144. USART_RX_STA=0;
  145. }
  146. //USART_SendData(USART1,Res); //send ok
  147. }
  148. }
  149. //USART_SendData(USART1,Res);
  150. }
  151. #endif
  152. }
  153. #endif
  154. int Putchar(int c)
  155. {
  156. if (c == '\n'){putchar('\r');}
  157. USART_SendData(USART1,c);
  158. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
  159. return c;
  160. }
  161. void UART_PutChar(USART_TypeDef* USARTx, uint8_t Data)
  162. {
  163. USART_SendData(USARTx, Data);
  164. while(USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET){}
  165. }
  166. void UART_PutStr (USART_TypeDef* USARTx, uint8_t *str)
  167. { //str--;
  168. while (0 != *str)
  169. {
  170. UART_PutChar(USARTx, *str++);
  171. //str++;
  172. }
  173. }

 

下面是/*main.c*/

  1. #include "stm32f10x.h"
  2. #include "motor.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "delay.h"
  6. #include <stdio.h>
  7. //#include "usart.h"
  8. #include "blue.h"
  9. #include <string.h>
  10. int USART1_RX_STA=0;
  11. #define USART1_MAX_RECV_LEN 7
  12. char BUF2[8] ;
  13. char BUF3[5] = {0x0d,0x59,0x65,0x73};
  14. #define USART_REC_LEN 200
  15. u8 USART_RX_BUF[USART_REC_LEN];
  16. char BUF[5] = {0x59,0x65,0x73};
  17. char BUF4[2];
  18. char *str = BUF2;
  19. u16 USART_RX_STA=0;
  20. int u =0;
  21. int a,a2,a3;
  22. int n,n2,n3;
  23. char *s1 = NULL,*s2 = NULL,*s3 = NULL;
  24. char *s4 = NULL,*s5 = NULL,*s6 = NULL;
  25. int IRQ_RX = 0;//·½Ïò±ê־λ
  26. int IRQ_RX_a = 0,IRQ_RX_b = 0,IRQ_RX_c = 0; //Èý¸ö·½Ïò±ê־λ
  27. char step_a = 0,step_b = 0,step_c = 0;
  28. char step_a1 = 0x30,step_a2 = 0x30,step_b1 = 0x30, step_b2 = 0x30,step_c1 = 0x30,step_c2 = 0x30;
  29. int fputc(int ch,FILE *p) //
  30. {
  31. USART_SendData(USART1,(u8)ch);
  32. while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
  33. return ch;
  34. }
  35. int chartoint10(char a){
  36. int w;
  37. switch(a){
  38. // 0-9
  39. case 0x30: w = 0;break;
  40. case 0x31: w = 1;break;
  41. case 0x32: w = 2;break;
  42. case 0x33: w = 3;break;
  43. case 0x34: w = 4;break;
  44. case 0x35: w = 5;break;
  45. case 0x36: w = 6;break;
  46. case 0x37: w = 7;break;
  47. case 0x38: w = 8;break;
  48. case 0x39: w = 9;break;
  49. }
  50. return w;
  51. }
  52. int chartoint_two(char a,char b){
  53. int w,v;//Ê®½øÖÆ
  54. int sum;
  55. switch(a){
  56. // 0-9
  57. case 0x30: w = 0;break;
  58. case 0x31: w = 1;break;
  59. case 0x32: w = 2;break;
  60. case 0x33: w = 3;break;
  61. case 0x34: w = 4;break;
  62. case 0x35: w = 5;break;
  63. case 0x36: w = 6;break;
  64. case 0x37: w = 7;break;
  65. case 0x38: w = 8;break;
  66. case 0x39: w = 9;break;
  67. }
  68. w = w * 10;
  69. switch(b){
  70. // 0-9
  71. case 0x30: v = 0;break;
  72. case 0x31: v = 1;break;
  73. case 0x32: v = 2;break;
  74. case 0x33: v = 3;break;
  75. case 0x34: v = 4;break;
  76. case 0x35: v = 5;break;
  77. case 0x36: v = 6;break;
  78. case 0x37: v = 7;break;
  79. case 0x38: v = 8;break;
  80. case 0x39: v = 9;break;
  81. }
  82. sum = w + v;
  83. printf("%d\r\n",sum);
  84. return sum ;
  85. }
  86. void USART1_IRQHandler(void)
  87. {
  88. u8 a = 0;
  89. u8 Res;
  90. int len;
  91. //BUF4[1] = '\0';
  92. //&& BUF2[7] ==0x0D && BUF2[8] == 0x0A
  93. #if 1
  94. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET){
  95. //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  96. Res= USART_ReceiveData(USART1);
  97. //printf("%c",Res);
  98. // if(USART1_RX_STA< USART1_MAX_RECV_LEN){
  99. BUF2[USART1_RX_STA++] = (Res & (uint16_t)0x01FF);
  100. USART1->DR = (uint16_t)BUF2[USART1_RX_STA-1];
  101. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  102. if( BUF2[0] == 0x59 && (BUF2[1] == 0x61 || BUF2[1] == 0x62 || BUF2[1] == 0x30 )&& (BUF2[2] >= 0x30 && BUF2[2] <= 0x39) \
  103. && (BUF2[3] >= 0x30 && BUF2[3] <= 0x39) && (BUF2[4] == 0x61 || BUF2[4] == 0x62 || BUF2[4] == 0x30) && (BUF2[5] >= 0x30 && BUF2[5] <= 0x39) \
  104. && (BUF2[6] >= 0x30 && BUF2[6] <= 0x39) && (BUF2[7] == 0x61 || BUF2[7] == 0x62 || BUF2[7] == 0x30)&& (BUF2[8] >= 0x30 && BUF2[8] <= 0x39) \
  105. && (BUF2[9] >= 0x30 && BUF2[9] <= 0x39) && BUF2[10] == 0x0d && BUF2[11] == 0x0a){
  106. //printf("ok\r\n");
  107. step_a1 = BUF2[2];
  108. step_a2 = BUF2[3];
  109. step_b1 = BUF2[5];
  110. step_b2 = BUF2[6];
  111. step_c1 = BUF2[8];
  112. step_c2 = BUF2[9];
  113. if(BUF2[1] == 0x61){
  114. IRQ_RX_a = 1;
  115. }
  116. else if( BUF2[1] == 0x62 ){
  117. IRQ_RX_a = 2;
  118. }
  119. else if(BUF2[1] == 0x30){
  120. IRQ_RX_a = 3;
  121. }
  122. if(BUF2[4] == 0x61){
  123. IRQ_RX_b = 1;
  124. }
  125. else if(BUF2[4] == 0x62){
  126. IRQ_RX_b = 2;
  127. }
  128. else if(BUF2[4] == 0x30){
  129. IRQ_RX_b = 3;
  130. }
  131. if(BUF2[7] == 0x61){
  132. IRQ_RX_c =1;
  133. }
  134. else if(BUF2[7] == 0x62){
  135. IRQ_RX_c = 2;
  136. }
  137. else if(BUF2[7] == 0x30){
  138. IRQ_RX_c = 3;
  139. }
  140. #if 0
  141. if(IRQ_RX_a == 0 && IRQ_RX_b == 0 && IRQ_RX_c == 0){
  142. USART1_RX_STA = 0;
  143. printf("test2\r\n");
  144. }
  145. #endif
  146. //printf("test1\r\n");
  147. //printf("......");
  148. //memset(BUF2,0,sizeof(BUF2));
  149. }
  150. // }
  151. // else{
  152. //USART1_RX_STA|=1<<15;
  153. // USART1_RX_STA = 0;
  154. // }
  155. }
  156. #endif
  157. //test6 OK
  158. #if 0
  159. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET){
  160. //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  161. Res= USART_ReceiveData(USART1);
  162. //printf("%c",Res);
  163. // if(USART1_RX_STA< USART1_MAX_RECV_LEN){
  164. BUF2[USART1_RX_STA++] = (Res & (uint16_t)0x01FF);
  165. USART1->DR = (uint16_t)BUF2[USART1_RX_STA-1];
  166. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  167. if( BUF2[0] == 0x59 && (BUF2[1] == 0x61 || BUF2[1] == 0x62 )&& (BUF2[2] >= 0x30 && BUF2[2] <= 0x39) \
  168. && (BUF2[3] == 0x61 || BUF2[3] == 0x62 ) && (BUF2[4] >= 0x30 && BUF2[4] <= 0x39) \
  169. && (BUF2[5] == 0x61 || BUF2[5] == 0x62 )&& (BUF2[6] >= 0x30 && BUF2[6] <= 0x39) \
  170. ){
  171. step_a = BUF2[2];
  172. step_b = BUF2[4];
  173. step_c = BUF2[6];
  174. if(BUF2[1] == 0x61){
  175. IRQ_RX_a = 1;
  176. }
  177. else if( BUF2[1] == 0x62 ){
  178. IRQ_RX_a = 2;
  179. }
  180. if(BUF2[3] == 0x61){
  181. IRQ_RX_b = 1;
  182. }
  183. else if(BUF2[3] == 0x62){
  184. IRQ_RX_b = 2;
  185. }
  186. if(BUF2[5] == 0x61){
  187. IRQ_RX_c =1;
  188. }
  189. else if(BUF2[5] == 0x62){
  190. IRQ_RX_c = 2;
  191. }
  192. //memset(BUF2,0,sizeof(BUF2));
  193. }
  194. // }
  195. // else{
  196. //USART1_RX_STA|=1<<15;
  197. // USART1_RX_STA = 0;
  198. // }
  199. }
  200. #endif
  201. #if 0
  202. //test4
  203. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET){
  204. USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  205. Res= USART_ReceiveData(USART1);
  206. //printf("%c",Res);
  207. if(USART1_RX_STA< USART1_MAX_RECV_LEN){
  208. BUF2[USART1_RX_STA++] = (Res & (uint16_t)0x01FF);
  209. USART1->DR = (uint16_t)BUF2[USART1_RX_STA-1];
  210. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  211. //USART1->DR = (Res & (uint16_t)0x01FF);
  212. // 0x2c , | 0x61 a | 0x62 b | 0x63 c | 0x31 1 | 0x39 9 | 0x3d = | 0x6d m } 0x6e n | 0x6f o |
  213. if(BUF2[0] == 0x61 && BUF2[1] == 0x3D && BUF2[USART1_RX_STA - 2] ==0x0D && BUF2[USART1_RX_STA - 1] == 0x0A){
  214. step_a = BUF2[6];
  215. step_b = BUF2[14];
  216. step_c = BUF2[22];
  217. if(BUF2[2] == 0x31){
  218. IRQ_RX_a = 1;
  219. }
  220. else if( BUF2[2] == 0x32 ){
  221. IRQ_RX_a = 2;
  222. }
  223. if(BUF2[10] == 0x31){
  224. IRQ_RX_b = 1;
  225. }
  226. else if(BUF2[10] == 0x32){
  227. IRQ_RX_b = 2;
  228. }
  229. if(BUF2[18] == 0x31){
  230. IRQ_RX_c =1;
  231. }
  232. else if(BUF2[18] == 0x32){
  233. IRQ_RX_c = 2;
  234. }
  235. //memset(BUF2,0,sizeof(BUF2));
  236. }
  237. }
  238. else{
  239. //USART1_RX_STA|=1<<15;
  240. USART1_RX_STA = 0;
  241. USART_ClearFlag(USART1, USART_FLAG_TC);
  242. }
  243. }
  244. #endif
  245. //test3
  246. #if 0
  247. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET){
  248. //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  249. Res= USART_ReceiveData(USART1);
  250. //printf("%c",Res);
  251. if(USART1_RX_STA< USART1_MAX_RECV_LEN){
  252. BUF2[USART1_RX_STA++] = (Res & (uint16_t)0x01FF);
  253. USART1->DR = (uint16_t)BUF2[USART1_RX_STA-1];
  254. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  255. //USART1->DR = (Res & (uint16_t)0x01FF);
  256. // 0x2c , | 0x61 a | 0x62 b | 0x63 c | 0x31 1 | 0x39 9 | 0x3d = | 0x6d m } 0x6e n | 0x6f o |
  257. if(BUF2[0] == 0x61 && BUF2[1] == 0x3D && (BUF2[2] == 0x31 || BUF2[2] == 0x32 ) \
  258. && BUF2[3] ==0x2C && BUF2[4] == 0x6D \
  259. && BUF2[5] == 0x3D && (BUF2[6] >= 0x30 && BUF2[6] <= 0x39) && BUF2[7] == 0x2C \
  260. && BUF2[8] == 0x62 && BUF2[9] == 0x3D && (BUF2[10] == 0x31 || BUF2[10] == 0x32) && BUF2[11] == 0x2C \
  261. && BUF2[12] == 0x6E && BUF2[13] == 0x3D && (BUF2[14] >= 0x30 && BUF2[14] <= 0x39) \
  262. && BUF2[15] == 0x2C && BUF2[16] == 0x63 && BUF2[17] == 0x3D && (BUF2[18] == 0x31 || BUF2[18] == 0x32) \
  263. && BUF2[19] == 0x2C && BUF2[20] == 0x6F && BUF2[21] == 0x3D && (BUF2[22] >= 0x30 && BUF2[22] <= 0x39) \
  264. && BUF2[23] ==0x0D && BUF2[24] == 0x0A){
  265. step_a = BUF2[6];
  266. step_b = BUF2[14];
  267. step_c = BUF2[22];
  268. if(BUF2[2] == 0x31){
  269. IRQ_RX_a = 1;
  270. }
  271. else if( BUF2[2] == 0x32 ){
  272. IRQ_RX_a = 2;
  273. }
  274. if(BUF2[10] == 0x31){
  275. IRQ_RX_b = 1;
  276. }
  277. else if(BUF2[10] == 0x32){
  278. IRQ_RX_b = 2;
  279. }
  280. if(BUF2[18] == 0x31){
  281. IRQ_RX_c =1;
  282. }
  283. else if(BUF2[18] == 0x32){
  284. IRQ_RX_c = 2;
  285. }
  286. //memset(BUF2,0,sizeof(BUF2));
  287. }
  288. }
  289. else{
  290. //USART1_RX_STA|=1<<15;
  291. USART1_RX_STA = 0;
  292. }
  293. }
  294. #endif
  295. //test2 word OK ------------------------------------
  296. //#define USART1_MAX_RECV_LEN 24
  297. //char BUF2[23];
  298. #if 0
  299. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET){
  300. //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  301. Res= USART_ReceiveData(USART1);
  302. //printf("%c",Res);
  303. if(USART1_RX_STA<USART1_MAX_RECV_LEN){
  304. BUF2[USART1_RX_STA++] = (Res & (uint16_t)0x01FF);
  305. USART1->DR = (uint16_t)BUF2[USART1_RX_STA-1];
  306. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  307. //USART1->DR = (Res & (uint16_t)0x01FF);
  308. if(BUF2[0] == 0x61 && BUF2[1] == 0x3d && (BUF2[2] == 0x31 || BUF2[2] == 0x32 \
  309. && (BUF2[3] >= 0x30 || BUF2[3] <= 0x39) && BUF2[4] == 0x2c && BUF2[5] == 0x6d \
  310. && BUF2[6] == 0x3d && (BUF2[7] >= 0x30 || BUF2[7] <= 0x39) && BUF2[8] == 0x2c \
  311. && BUF2[9] == 0x62 && BUF2[10] == 0x3d && (BUF2[11] >= 0x30 || BUF2[11] <= 0x39) && BUF2[12] == 0x2c \
  312. && BUF2[13] == 0x6e && BUF2[14] == 0x3d && (BUF2[15] >= 0x30 || BUF2[15] <= 0x39) \
  313. && BUF2[16] == 0x2c && BUF2[17] == 0x63 && BUF2[18] == 0x3d && (BUF2[19] >= 0x30 || BUF2[19] <= 0x39)\
  314. && BUF2[20] == 0x2c && BUF2[21] == 0x6f && BUF2[22] == 0x3d && (BUF2[23] >= 0x30 || BUF2[23] <= 0x39) )){
  315. //printf("ok");
  316. //MOTOR_Step3_Micr(1);
  317. //MOTOR_Step3_Control(BUF2[2],1600,BUF2[3] );
  318. //MOTOR_Step3_Control(1,1600,125 );
  319. //MOTOR_Step3_Enable();
  320. //USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
  321. if(BUF2[2] == 0x31){
  322. IRQ_RX = 1;
  323. }
  324. //memset(BUF2,0,u);
  325. //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  326. //MOTOR_Step3_Control(0,1600,125);
  327. //if(u > 4){
  328. //memset(BUF2,0,sizeof(BUF2));
  329. //u = 0;
  330. // }
  331. if( BUF2[2] == 0x32 ){
  332. //MOTOR_Step3_Micr(1);
  333. //USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
  334. IRQ_RX = 2;
  335. //MOTOR_Step3_Control(2,1600,125 );
  336. //MOTOR_Step3_Enable();
  337. }
  338. }
  339. //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  340. }
  341. else{
  342. //USART1_RX_STA|=1<<15;
  343. USART1_RX_STA = 0;
  344. }
  345. }
  346. #endif
  347. #if 0
  348. if((BUF2[2] == 0x31 || BUF2[2] == 0x32) && (BUF2[3] >= 0x30 && BUF2[3] <= 0x39)){
  349. //MOTOR_Step3_Micr(1);
  350. //MOTOR_Step3_Control(BUF2[2],1600,BUF2[3] );
  351. memset(BUF2,0,u);
  352. //MOTOR_Step3_Control(0,1600,chartoint10(BUF2[3]) * One_1);
  353. //MOTOR_Step3_Control(1,1600,625);
  354. //MOTOR_Step3_Enable();
  355. //BUF2[3] =0;
  356. //BUF2[2] = 0;
  357. //BUF2[0] = 0;
  358. //BUF2[1] = 0;
  359. //u = 0;
  360. USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  361. }
  362. #endif
  363. //test1 word OK ------------------------------------
  364. //#define USART1_MAX_RECV_LEN 4
  365. //char BUF2[5];
  366. #if 0
  367. if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET){
  368. Res= USART_ReceiveData(USART1);
  369. //printf("%c",Res);
  370. if(USART1_RX_STA<USART1_MAX_RECV_LEN){
  371. BUF2[USART1_RX_STA++] = (Res & (uint16_t)0x01FF);
  372. USART1->DR = (uint16_t)BUF2[USART1_RX_STA-1];
  373. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  374. if(BUF2[0] == 0x61 && BUF2[1] == 0x3d && (BUF2[2] == 0x31 || BUF2[2] == 0x32 )){
  375. if(BUF2[2] == 0x31){
  376. IRQ_RX = 1;
  377. }
  378. if( BUF2[2] == 0x32 ){
  379. IRQ_RX = 2;
  380. }
  381. }
  382. }
  383. else{
  384. USART1_RX_STA = 0;
  385. }
  386. }
  387. #endif
  388. //USART1->DR = (0x2a & (uint16_t)0x01FF);
  389. //while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}
  390. }
  391. int main(void){
  392. //int ret=0;
  393. // u16 led0pwmval=0;
  394. //u8 dir=1;
  395. int i = 0;
  396. u8 Res;
  397. u8 temp;
  398. MOTOR_Step_Init();
  399. MOTOR_Init();
  400. delay_init();
  401. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  402. BLUE_Init();
  403. //uart_init(115200);
  404. //DIR = TRUE;
  405. //½ÓÏß×óµç»ú
  406. //printf("\r\nhello");
  407. #if 0
  408. for(i = 0;i < 4;i++){
  409. USART_SendData(USART1,BUF3[i]);
  410. while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
  411. //BUF2[0] = 0;
  412. //BUF2[1] = 0;
  413. }
  414. #endif
  415. /*
  416. for(i = 0;i < 1 ;i++){
  417. MOTOR_Step_Micr(1);
  418. MOTOR_Step3_Micr(1);
  419. //delay_ms(1000);
  420. MOTOR_Step_Control(1,1600,625);
  421. MOTOR_Step3_Control(1,1600,1250);
  422. MOTOR_Step3_Control(0,1600,1250);
  423. MOTOR_Step3_Enable();
  424. delay_ms(1000);
  425. MOTOR_Step_Control(0,1600,625);
  426. MOTOR_Step_Control(1,1600,625);
  427. MOTOR_Step_Enable();
  428. }
  429. */
  430. while(1){
  431. //printf("**************************\n");
  432. //MOTOR_Step_Control(FALSE,3600,400);
  433. //MOTOR_Step_Control(0,1600,200);
  434. //delay_ms(1000);
  435. //delay_ms(1000);
  436. //test4
  437. #if 1
  438. if(IRQ_RX_a == 1){
  439. MOTOR_Step_Micr(1);
  440. //MOTOR_Step_Control(1,1600,150);
  441. MOTOR_Step_Control(0,1600,chartoint_two(step_a1,step_a2) * One_1);
  442. MOTOR_Step_Enable();
  443. IRQ_RX_a = 0;
  444. step_a1 = 0x30;
  445. step_a2 = 0x30;
  446. USART1_RX_STA = 0;
  447. }
  448. else if(IRQ_RX_a == 2){
  449. MOTOR_Step_Micr(1);
  450. //MOTOR_Step_Control(0,1600,150);
  451. MOTOR_Step_Control(1,1600,chartoint_two(step_a1,step_a2) * One_1 );
  452. MOTOR_Step_Enable();
  453. IRQ_RX_a= 0;
  454. step_a1 = 0x30;
  455. step_a2 = 0x30;
  456. USART1_RX_STA = 0;
  457. }
  458. else if(IRQ_RX_a == 3){
  459. USART1_RX_STA = 0;
  460. }
  461. if(IRQ_RX_b == 1){
  462. MOTOR_Step2_Micr(1);
  463. //MOTOR_Step2_Control(1,1600,150);
  464. MOTOR_Step2_Control(0,1600,chartoint_two(step_b1,step_b2) * One_1);
  465. MOTOR_Step2_Enable();
  466. IRQ_RX_b = 0;
  467. step_b1 = 0x30;
  468. step_b2 = 0x30;
  469. USART1_RX_STA = 0;
  470. }
  471. else if(IRQ_RX_b == 2){
  472. MOTOR_Step2_Micr(1);
  473. // MOTOR_Step2_Control(0,1600,150);
  474. MOTOR_Step2_Control(1,1600,chartoint_two(step_b1,step_b2) * One_1 );
  475. MOTOR_Step2_Enable();
  476. IRQ_RX_b= 0;
  477. step_b1 = 0x30;
  478. step_b2 = 0x30;
  479. USART1_RX_STA = 0;
  480. }
  481. else if(IRQ_RX_b == 3){
  482. USART1_RX_STA = 0;
  483. }
  484. if(IRQ_RX_c == 1){
  485. MOTOR_Step3_Micr(1);
  486. //MOTOR_Step3_Control(1,1600,150);
  487. MOTOR_Step3_Control(0,1600,chartoint_two(step_c1,step_c2) * One_1);
  488. MOTOR_Step3_Enable();
  489. IRQ_RX_c = 0;
  490. step_c1 =0x30;
  491. step_c2 =0x30;
  492. USART1_RX_STA = 0;
  493. }
  494. else if(IRQ_RX_c == 2){
  495. MOTOR_Step3_Micr(1);
  496. // MOTOR_Step3_Control(0,1600,150);
  497. MOTOR_Step3_Control(1,1600,chartoint_two(step_c1,step_c2) * One_1 );
  498. MOTOR_Step3_Enable();
  499. IRQ_RX_c= 0;
  500. step_c1 = 0x30;
  501. step_c2 = 0x30;
  502. USART1_RX_STA = 0;
  503. }
  504. else if(IRQ_RX_c == 3){
  505. USART1_RX_STA = 0;
  506. }
  507. #endif
  508. //test3 ok
  509. #if 0
  510. if(IRQ_RX_a == 1){
  511. MOTOR_Step_Micr(1);
  512. //MOTOR_Step_Control(1,1600,150);
  513. MOTOR_Step_Control(1,1600,chartoint10(step_a) * One_1);
  514. MOTOR_Step_Enable();
  515. IRQ_RX_a = 0;
  516. step_a = 0;
  517. USART1_RX_STA = 0;
  518. }
  519. else if(IRQ_RX_a == 2){
  520. MOTOR_Step_Micr(1);
  521. //MOTOR_Step_Control(0,1600,150);
  522. MOTOR_Step_Control(0,1600,chartoint10(step_a) * One_1 );
  523. MOTOR_Step_Enable();
  524. IRQ_RX_a= 0;
  525. step_a = 0;
  526. USART1_RX_STA = 0;
  527. }
  528. if(IRQ_RX_b == 1){
  529. MOTOR_Step2_Micr(1);
  530. //MOTOR_Step2_Control(1,1600,150);
  531. MOTOR_Step2_Control(1,1600,chartoint10(step_b) * One_1);
  532. MOTOR_Step2_Enable();
  533. IRQ_RX_b = 0;
  534. step_b = 0;
  535. USART1_RX_STA = 0;
  536. }
  537. else if(IRQ_RX_b == 2){
  538. MOTOR_Step2_Micr(1);
  539. // MOTOR_Step2_Control(0,1600,150);
  540. MOTOR_Step2_Control(0,1600,chartoint10(step_b) * One_1 );
  541. MOTOR_Step2_Enable();
  542. IRQ_RX_b= 0;
  543. step_b = 0;
  544. USART1_RX_STA = 0;
  545. }
  546. if(IRQ_RX_c == 1){
  547. MOTOR_Step3_Micr(1);
  548. //MOTOR_Step3_Control(1,1600,150);
  549. MOTOR_Step3_Control(1,1600,chartoint10(step_c) * One_1);
  550. MOTOR_Step3_Enable();
  551. IRQ_RX_c = 0;
  552. step_c = 0;
  553. USART1_RX_STA = 0;
  554. }
  555. else if(IRQ_RX_c == 2){
  556. MOTOR_Step3_Micr(1);
  557. // MOTOR_Step3_Control(0,1600,150);
  558. MOTOR_Step3_Control(0,1600,chartoint10(step_c) * One_1 );
  559. MOTOR_Step3_Enable();
  560. IRQ_RX_c= 0;
  561. step_c = 0;
  562. USART1_RX_STA = 0;
  563. }
  564. #endif
  565. //test1 and 2 word OK ------------------------------------------------
  566. #if 0
  567. if(IRQ_RX == 1){
  568. MOTOR_Step3_Micr(1);
  569. MOTOR_Step3_Control(1,1600,150);
  570. //MOTOR_Step3_Control(1,1600,chartoint10(BUF2[3]) * One_1);
  571. MOTOR_Step3_Enable();
  572. IRQ_RX = 0;
  573. }
  574. else if(IRQ_RX == 2){
  575. MOTOR_Step3_Micr(1);
  576. MOTOR_Step3_Control(0,1600,150);
  577. //MOTOR_Step3_Control(0,1600,chartoint10(BUF2[3]) * One_1 );
  578. MOTOR_Step3_Enable();
  579. IRQ_RX = 0;
  580. }
  581. #endif
  582. }
  583. while(1);
  584. }

完结~,谢谢

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/405308
推荐阅读
相关标签
  

闽ICP备14008679号