Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to program 5 1 single chip microcomputer to make Ucharcode g code [] = "G1x0.2Y0.2Z6.3F200.37E55.3"; X, y and z values are suggested to be floating-point numbers?
How to program 5 1 single chip microcomputer to make Ucharcode g code [] = "G1x0.2Y0.2Z6.3F200.37E55.3"; X, y and z values are suggested to be floating-point numbers?
/* The landlord can try this. First, a string is an array of characters ending in' \ 0'. We can extract the data in it by digital subscript operation, and then find the following data by judging' x'' y'' z'. Because there is a space after the X data, we can intercept the character data through the X and the space, and then convert the characters into numbers and then into floating-point numbers.

*/

# Contains? & ltreg 5 1 . h & gt;

Charles? Code? gcode[]="G 1? X5.3? Y0.2? Z6.3? F200.37? e 55.3”;

Charles? x _ Array[3]; //Save the characters after x.

Floating? x _ Float = 0; //X floating-point number

Invalid? Major (invalid)

{

Charles? Me? =? 0; //gcode[i]

Charles? j? =? 0; //X_Array[j]

* * * * * * * * * * * * * Take the character * * * * * * * * * * * * * * *

while(gcode[i]? ! =? '\0')

{

? Switch (gcode[i])

? {

? Charles? k? =? 0;

Case? x ':

for(; gcode[++i]? ! ='?' ; )

{

X_Array[k]? =? gcode[I];

? k++;

}

Break;

//case? y ':

//{…………}

//case? z ':

//{…………}

Default value:

Break;

}

i++;

}

/* * * * * * * * * * Character variable floating point number * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

And (j? & lt? 3)

{

Switch (j)

{

Case? 0:

X_Float? =? X_Array[j]? -? '0'; //bit

Break; ?

Case? 1:

Break; //decimal point

Case? 2:

X_Float? +=? (X_Array[j]? -? '0')/ 10; //One decimal place

Break; ?

}

j++;

}

while( 1);

}