找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 9820|回复: 10
收起左侧

stm32-gbrl-g代码解释程序

  [复制链接]
ID:294084 发表于 2018-3-19 16:03 | 显示全部楼层 |阅读模式
stm32-gbrl-g代码解释程序

单片机源程序如下:
  1. /***************************************************************/
  2. //2013.8.27  Copyright@ rhyme呆瓜云
  3. /***************************************************************/
  4. #include "stm32f10x.h"
  5. #include "stdio.h"
  6. #include "gpio.h"
  7. #include "usart.h"
  8. #include "delay.h"
  9. #include "tim.h"
  10. #include "eeprom.h"
  11. #include "pwm.h"

  12. #include "config.h"
  13. #include "planner.h"
  14. #include "nuts_bolts.h"
  15. #include "stepper.h"
  16. #include "spindle_control.h"
  17. #include "coolant_control.h"
  18. #include "motion_control.h"
  19. #include "gcode.h"
  20. #include "protocol.h"
  21. #include "limits.h"
  22. #include "report.h"
  23. #include "settings.h"
  24. #include "serial.h"

  25. /***************************************************************/
  26. u8 USART_RX[60]={""};
  27. u8 USART_mark=0;
  28. u8 Press_mark=0;
  29. int USART_control=0;
  30. int USART_data=0;
  31. u16 USART_RX_STA;       //接收状态标记       

  32. uint16_t ee;//EEPROM变量
  33. u8 mo=1;
  34. /***************************************************************/


  35. int main(void)
  36. {
  37.         RCC_Configuration();
  38.         delay_Configuration(72);
  39.         USART1_Configuration(9600);
  40.         PB9_OUT
  41.         Set_B9
  42.        
  43. //        PB8_OUT
  44. //        Set_B8
  45. //        delay_ms(200);
  46. //        Clr_B8
  47. //        delay_ms(200);
  48. //        Set_B8
  49. //        delay_ms(300);
  50. //        Clr_B8
  51.        
  52. //        PA7_OUT
  53. //        Clr_A7
  54. //       
  55. //        PA6_OUT
  56. //        Clr_A6
  57.        
  58.        
  59.        
  60.         Motors_Set_GPIO();//电机IO口定义
  61.        
  62. //        FLASH_Unlock();
  63. //        EE_Init();
  64.         settings_reset(true);//GRBL重置所有参数
  65.         //读取EEPROM 设定FEED和SEEK
  66. //        if(!EE_ReadVariable(32,&ee))
  67. //        {
  68. //                settings.default_feed_rate = ee;
  69. //                settings.default_seek_rate = ee;
  70. //        }
  71.         TIM_Configuration(TIM2,1001,1,1);
  72.         st_init(); //步进电机初始化,用这两个中断,通过 “布雷森汉姆直线算法”同时控制三个步进输出。
  73.        
  74.         memset(&sys, 0, sizeof(sys));  //清数组
  75.        
  76.         sys.abort = true;   // 设置abort 标志着初始化完成
  77.   sys.state = STATE_INIT;  // 设置一个警示标志来指示未知的初始位置
  78.        
  79. //        TIM3_PWM_Configuration(20,3600,1,1,0,0);
  80. //        PA6_OUT
  81. //        Set_A6
  82. //        PA7_OUT
  83. //        Clr_A7
  84.         while(1)
  85.         {
  86.                
  87.                   if (sys.abort) {
  88.       // Reset system.
  89.       serial_reset_read_buffer(); // Clear serial read buffer
  90.       plan_init(); // Clear block buffer and planner variables
  91.       gc_init(); // Set g-code parser to default state
  92.       protocol_init(); // Clear incoming line data and execute startup lines
  93.       spindle_init();
  94.       coolant_init();
  95.       limits_init();
  96.       st_reset(); // Clear stepper subsystem variables.

  97.       // Sync cleared gcode and planner positions to current system position, which is only
  98.       // cleared upon startup, not a reset/abort.
  99.       sys_sync_current_position();

  100.       // Reset system variables.
  101.       sys.abort = false;
  102.       sys.execute = 0;
  103.       if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) { sys.auto_start = true; }
  104.       
  105.       // Check for power-up and set system alarm if homing is enabled to force homing cycle
  106.       // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
  107.       // startup scripts, but allows access to settings and internal commands. Only a homing
  108.       // cycle '$H' or kill alarm locks '$X' will disable the alarm.
  109.       // NOTE: The startup script will run after successful completion of the homing cycle, but
  110.       // not after disabling the alarm locks. Prevents motion startup blocks from crashing into
  111.       // things uncontrollably. Very bad.
  112.       #ifdef HOMING_INIT_LOCK
  113.         if (sys.state == STATE_INIT && bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
  114.       #endif
  115.       
  116.       // Check for and report alarm state after a reset, error, or an initial power up.
  117.       if (sys.state == STATE_ALARM) {
  118.         report_feedback_message(MESSAGE_ALARM_LOCK);
  119.       } else {
  120.         // All systems go. Set system to ready and execute startup script.
  121.         sys.state = STATE_IDLE;
  122.         protocol_execute_startup();
  123.       }
  124.     }       
  125.                        

  126.                
  127.     protocol_execute_runtime();
  128.     protocol_process(); // ... process the serial protocol
  129.     if(mo==0) {MotorsEnable(0x00);mo=10;}
  130.                
  131. //                delay_ms(500);
  132. //                Set_B12
  133. //                delay_ms(500);
  134. //                Clr_B12
  135. //                printf(" This is the STM32 Demo !!! \r\n");
  136.         }
  137.        
  138. }
  139. /***************************************************************/

复制代码

所有资料51hei提供下载:
STM32-GRBL-master.rar (412.7 KB, 下载次数: 172)
回复

使用道具 举报

ID:331960 发表于 2018-5-17 11:04 | 显示全部楼层
谢谢分享
回复

使用道具 举报

ID:228452 发表于 2018-5-26 05:01 | 显示全部楼层
Nice work
Thanks
回复

使用道具 举报

ID:325739 发表于 2018-12-8 10:50 | 显示全部楼层
多谢楼主分享
回复

使用道具 举报

ID:445569 发表于 2018-12-19 08:39 | 显示全部楼层
多谢楼主分享
回复

使用道具 举报

ID:298628 发表于 2018-12-24 10:44 | 显示全部楼层
谢谢分享
回复

使用道具 举报

ID:395134 发表于 2019-4-17 20:31 | 显示全部楼层
楼主,你13行到25行的代码都指的啥呀
回复

使用道具 举报

ID:689683 发表于 2020-2-3 17:40 | 显示全部楼层
感谢分享
回复

使用道具 举报

ID:68875 发表于 2020-2-6 22:27 | 显示全部楼层
very good, thank you
回复

使用道具 举报

ID:234782 发表于 2022-7-10 10:36 | 显示全部楼层
谢谢分享,啥时候能发个文档
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表