Advertisement
RuiViana

main.c

Jul 25th, 2021
1,455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.67 KB | None | 0 0
  1. /*
  2.   main.c - An embedded CNC Controller with rs274/ngc (g-code) support
  3.   Part of Grbl
  4.  
  5.   Copyright (c) 2011-2015 Sungeun K. Jeon
  6.   Copyright (c) 2009-2011 Simen Svale Skogsrud
  7.  
  8.   Grbl is free software: you can redistribute it and/or modify
  9.   it under the terms of the GNU General Public License as published by
  10.   the Free Software Foundation, either version 3 of the License, or
  11.   (at your option) any later version.
  12.  
  13.   Grbl is distributed in the hope that it will be useful,
  14.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.   GNU General Public License for more details.
  17.  
  18.   You should have received a copy of the GNU General Public License
  19.   along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
  20. */
  21.  
  22. #include "grbl.h"
  23.  
  24.  
  25. // Declare system global variable structure
  26. system_t sys;
  27.  
  28.  
  29. int main(void)
  30. {
  31.   // Initialize system upon power-up.
  32.   serial_init();   // Setup serial baud rate and interrupts
  33.   settings_init(); // Load Grbl settings from EEPROM
  34.   stepper_init();  // Configure stepper pins and interrupt timers
  35.   system_init();   // Configure pinout pins and pin-change interrupt
  36.  
  37.   memset(&sys, 0, sizeof(system_t));  // Clear all system variables
  38.   sys.abort = true;   // Set abort to complete initialization
  39.   sei(); // Enable interrupts
  40.  
  41.   // Check for power-up and set system alarm if homing is enabled to force homing cycle
  42.   // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
  43.   // startup scripts, but allows access to settings and internal commands. Only a homing
  44.   // cycle '$H' or kill alarm locks '$X' will disable the alarm.
  45.   // NOTE: The startup script will run after successful completion of the homing cycle, but
  46.   // not after disabling the alarm locks. Prevents motion startup blocks from crashing into
  47.   // things uncontrollably. Very bad.
  48.   #ifdef HOMING_INIT_LOCK
  49.     if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
  50.   #endif
  51.  
  52.   // Force Grbl into an ALARM state upon a power-cycle or hard reset.
  53.   #ifdef FORCE_INITIALIZATION_ALARM
  54.     sys.state = STATE_ALARM;
  55.   #endif
  56.  
  57.   // Grbl initialization loop upon power-up or a system abort. For the latter, all processes
  58.   // will return to this loop to be cleanly re-initialized.
  59.   for(;;) {
  60.  
  61.     // TODO: Separate configure task that require interrupts to be disabled, especially upon
  62.     // a system abort and ensuring any active interrupts are cleanly reset.
  63.  
  64.     // Reset Grbl primary systems.
  65.     serial_reset_read_buffer(); // Clear serial read buffer
  66.     gc_init(); // Set g-code parser to default state
  67.     spindle_init();
  68.     coolant_init();
  69.     limits_init();
  70.     probe_init();
  71.     plan_reset(); // Clear block buffer and planner variables
  72.     st_reset(); // Clear stepper subsystem variables.
  73.  
  74.     // Sync cleared gcode and planner positions to current system position.
  75.     plan_sync_position();
  76.     gc_sync_position();
  77.  
  78.     // Reset system variables.
  79.     sys.abort = false;
  80.     sys_rt_exec_state = 0;
  81.     sys_rt_exec_alarm = 0;
  82.     sys.suspend = false;
  83.     sys.soft_limit = false;
  84.              
  85.     // Start Grbl main loop. Processes program inputs and executes them.
  86.     protocol_main_loop();
  87.    
  88.  
  89.  
  90.      pinMode(A4, OUTPUT); //Habilita o pino A4 como saida
  91.  
  92.     for(int i = 0; i < 1; i++)
  93.     {
  94.        digitalWrite(A4, HIGH); // Atribui nível lógico alto ao pino do A4, saida 5V
  95.        delay(500);             // Espera 500 milissegundos (meio segundo)
  96.        digitalWrite(A4, LOW);  // Atribui nível lógico baixo ao pino do A4, sem tensao
  97.     }
  98.  
  99.  }
  100.  
  101.   return 0;   /* Never reached */
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement