⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manual.c

📁 CNC.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
    UARTConfigSet(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 |
                                       UART_CONFIG_STOP_ONE |
                                       UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);

    //
    // Set the default values for the speed, acceleration, and table position.
    //
    ulSpeed = 2400;
    ulAccel = 30000;
    ulX = 0;
    ulY = 6800;
    ulZ = 0;

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Print out the current status.
        //
        ManualSendString("Speed: ");
        ManualSendValue(ulSpeed);
        ManualSendString("  Acceleration: ");
        ManualSendValue(ulAccel);
        ManualSendString("  X: ");
        ManualSendValue(ulX);
        ManualSendString("  Y: ");
        ManualSendValue(ulY);
        ManualSendString("  Z: ");
        ManualSendValue(ulZ);
        ManualSendString("\r\n");
        ManualSendString("0) speed  1) accel  2) x  3) y  4) z  5) run  "
                         "6) tool on  7) tool off  ? ");

        //
        // Read a character from the UART.
        //
        cChar = UARTCharGet(UART0_BASE);

        //
        // Echo out the character read.
        //
        UARTCharPut(UART0_BASE, cChar);
        ManualSendString("\r\n");

        //
        // Determine what to do based on the character received.
        //
        switch(cChar)
        {
            //
            // The speed should be changed.
            //
            case '0':
            {
                //
                // Prompt for the new speed.
                //
                ManualSendString("Speed = ");

                //
                // Read the speed.
                //
                ulValue = ManualGetValue();

                //
                // Change the speed only if the read value was not zero.
                //
                if(ulValue != 0)
                {
                    ulSpeed = ulValue;
                }

                //
                // Done handling this command.
                //
                break;
            }

            //
            // The acceleration should be changed.
            //
            case '1':
            {
                //
                // Prompt for the new acceleration.
                //
                ManualSendString("Acceleration = ");

                //
                // Read the acceleration.
                //
                ulValue = ManualGetValue();

                //
                // Change the acceleration only if the read value was not zero.
                //
                if(ulValue != 0)
                {
                    ulAccel = ulValue;
                }
                //
                // Done handling this command.
                //
                break;
            }

            //
            // The X coordinate should be changed.
            //
            case '2':
            {
                //
                // Prompt for the new X coordinate.
                //
                ManualSendString("X = ");

                //
                // Read the X coordinate.
                //
                ulX = ManualGetValue();

                //
                // Done handling this command.
                //
                break;
            }

            //
            // The Y coordinate should be changed.
            //
            case '3':
            {
                //
                // Prompt for the new Y coordinate.
                //
                ManualSendString("Y = ");

                //
                // Read the Y coordinate.
                //
                ulY = ManualGetValue();

                //
                // Done handling this command.
                //
                break;
            }

            //
            // The Z coordinate should be changed.
            //
            case '4':
            {
                //
                // Prompt for the new Z coordinate.
                //
                ManualSendString("Z = ");

                //
                // Read the Z coordinate.
                //
                ulZ = ManualGetValue();

                //
                // Done handling this command.
                //
                break;
            }

            //
            // The tool should be moved.
            //
            case '5':
            {
                //
                // Indicate that the machine is running.
                //
                ManualSendString("Running...\r\n");

                //
                // Start a drawing operation.
                //
                DrawStart();

                //
                // There are three moves involved; jog to the X/Y position with
                // Z = 0, move to the requested Z depth, and then move back to
                // Z = 0.
                //
                for(ulValue = 0; ulValue < 3; ulValue++)
                {
                    //
                    // Determine which move is being performed.
                    //
                    if(ulValue == 0)
                    {
                        //
                        // Move the tool to the requested X/Y position.
                        //
                        TableMoveLine(ulX, ulY, 0, ulSpeed, ulAccel);
                    }
                    else if(ulValue == 1)
                    {
                        //
                        // Move the tool down to the requested Z position.
                        //
                        TableMoveLine(ulX, ulY, ulZ, 1200, 30000);
                    }
                    else
                    {
                        //
                        // Move the tool up to the Z = 0 position.
                        //
                        TableMoveLine(ulX, ulY, 0, 1200, 30000);
                    }

                    //
                    // Wait until the table stops moving.
                    //
                    while(TableIsMoving())
                    {
                        //
                        // See if there is a character ready to be read from
                        // the UART.
                        //
                        if(UARTCharsAvail(UART0_BASE))
                        {
                            //
                            // Read the character from the UART.
                            //
                            UARTCharGet(UART0_BASE);

                            //
                            // Stop the table.
                            //
                            TableStop();

                            //
                            // End the drawing.
                            //
                            DrawStop();
                        }
                    }

                    //
                    // Break out of the loop if the drawing was aborted.
                    //
                    if(!DrawIsDrawing())
                    {
                        break;
                    }

                    //
                    // See if this was the Z down move and the Z value was not
                    // zero.
                    //
                    if((ulValue == 1) && (ulZ != 0))
                    {
                        //
                        // Get the current time.
                        //
                        ulStart = VirtualTimeGet();

                        //
                        // Delay until two seconds have passed.
                        //
                        while((VirtualTimeGet() - ulStart) <
                              (g_ulSysClock * 2))
                        {
                        }
                    }
                }

                //
                // End the drawing.
                //
                DrawStop();

                //
                // Done handling this command.
                //
                break;
            }

            //
            // The tool should be turned on.
            //
            case '6':
            {
                //
                // Turn on the tool.
                //
                ToolOn();

                //
                // Done handling this command.
                //
                break;
            }

            //
            // The tool should be turned off.
            //
            case '7':
            {
                //
                // Turn off the tool.
                //
                ToolOff();

                //
                // Done handling this command.
                //
                break;
            }
        }
    }
}

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -