The invention discloses a method for improving the precision of an MCU for controlling a
crystal oscillator, and relates to the technical field of microcontrollers. Setting a DAC output precision improvement multiple N, and calculating a register configuration range after improvement; calculating a theoretical register configuration value of a
voltage needing to be output after the output precision of the DAC is improved;
rounding off the calculated theoretical register configuration value to obtain an actual configuration value; creating an N-
bit array for storing an actual DAC register value, dividing an actual configuration value by a lifting multiple N,
rounding down, and assigning all elements in the array to obtain a
rounding down result; calculating a result k obtained by taking a remainder from the lifting multiple N by an actual configuration value, adding 1 to the first k number in the array and then randomly disorganizing; creating
timer interruption, and writing an array value into a DAC register every 1 / N seconds; and after all the data are written in, the DAC module outputs a
voltage effective value with the control precision improved by N times within one second. According to the invention, high-precision
voltage output of the voltage-controlled pin of the
crystal oscillator is realized under the condition that hardware configuration is not changed.