Floating point number display method and apparatus applied to 8-bit single chip microcomputer

A display method and a display device technology, which are applied in the direction of electrical digital data processing, digital data processing components, instruments, etc., can solve the problems of reducing code operation efficiency and affecting the performance of single-chip microcomputers, etc., so as to increase the selection cost and optimize product performance. Effect

Inactive Publication Date: 2015-12-23
SHENZHEN ZHENBANG TECH
3 Cites 1 Cited by

AI-Extracted Technical Summary

Problems solved by technology

[0005] The object of the present invention is to provide a method and device for displaying floating-point numbers applied to 8-bit single-chip microcomputers, aiming at solving t...
View more

Method used

In sum, the embodiment of the present invention is by simplifying processing and enlarging processing to calculation formula, floating-point operation is simplified to integer operation, thereby need not carry out forced conversion variable type and floating-point number operation, obtains the same operation precision The display value results can improve the operating efficiency of the code and make the product performance better without increasing the selection cost of the single-chip microcomputer and ensuring the operation accuracy.
In the present embodiment, by multiplying calculation formula by the amplification process of 10n, floating-point calculation is simplified to integer calculation, thereby need not carry out mandatory type conversion between integer variable and floating-point variable, obtain same operatio...
View more

Abstract

The present invention is applicable to the field of single chip microcomputers, provides a floating point number display method applied to an 8-bit single chip microcomputer and aims to solve the problem, in the 8-bit single chip, that floating point number calculation microcomputer reduces the running efficiency of code and further influences performance of the single chip microcomputer. The method comprises: acquiring a calculation formula of a to-be-displayed floating point number; according to requirements of display precision of the to-be-displayed floating point number, performing processing of multiplying 10n on the calculation formula, wherein n is a natural number; and performing integer calculation on the calculation formula subjected to processing of multiplying 10n to obtain each bit display value of the to-be-displayed floating point number. By means of the floating point number display method applied to the 8-bit single chip microcomputer provided by the present invention, floating point calculation is simplified into integer calculation, and the display value of the floating point number with the same precision is obtained without the need for forcibly converting a variable type and floating point number calculation, so that running efficiency of code is improved, and product performance is optimized.

Application Domain

Digital data processing details

Technology Topic

Microcomputer8-bit +3

Image

  • Floating point number display method and apparatus applied to 8-bit single chip microcomputer
  • Floating point number display method and apparatus applied to 8-bit single chip microcomputer
  • Floating point number display method and apparatus applied to 8-bit single chip microcomputer

Examples

  • Experimental program(6)

Example Embodiment

[0024] Example one:
[0025] figure 1 It shows the flow of the floating-point number display method applied to 8-bit single-chip microcomputer according to the first embodiment of the present invention, which specifically includes S101 to S104, which are detailed as follows:
[0026] S101. Obtain a calculation formula of the floating-point number to be displayed.
[0027] In 8-bit microcontrollers, various data display problems are often encountered, such as voltage display, temperature display, etc., and these data exist in the form of floating-point numbers. Therefore, it is necessary to obtain the calculation formula for calculating the floating-point number to be displayed according to actual needs.
[0028] S102. Multiply the calculation formula by 10 according to the requirements of the display accuracy of the floating-point number to be displayed. n Processing, n is a natural number.
[0029] In this embodiment, the obtained calculation formula of the floating-point number to be displayed is multiplied by 10. n Processing, where the value of n is determined by the display accuracy of the floating-point number to be displayed. Specifically, if the display accuracy of the floating-point number to be displayed is required to be accurate to N digits after the decimal point, the value of n can be taken as N. For example, the display accuracy of the floating-point number to be displayed is required to be accurate to two decimal places, then the value of n is 2, and the calculation formula is multiplied by 10. 2 The processing, that is, the calculation formula is enlarged 100 times.
[0030] S103, multiply by 10 n The processed calculation formula performs integer calculation to obtain each display value of the floating-point number to be displayed.
[0031] In this embodiment, integer calculation means that there is no need to force conversion of variable types and no need to perform floating-point operations; the need not to force conversion of variable types includes that there is no need to perform mutual conversion between integer variables and floating-point variables.
[0032] In this embodiment, by multiplying the calculation formula by 10 n The magnification process reduces floating-point operations to integer operations, eliminating the need for forced type conversion between integer variables and floating-point variables, and obtains the display value result with the same arithmetic accuracy, which improves the efficiency of the code.

Example Embodiment

[0033] Embodiment two:
[0034] figure 2 It shows the flow of the floating-point number display method applied to 8-bit single-chip microcomputer according to the second embodiment of the present invention, which specifically includes S201 to S204, which are detailed as follows:
[0035] S201: Obtain a calculation formula of the floating-point number to be displayed.
[0036] S202: Simplify the calculation formula, so that the known number in the simplified calculation formula is a relatively prime number.
[0037] In this embodiment, when the value of the known number in the calculation formula is large, the calculation formula can be simplified to remove the common divisor of the known number, so that the known number in the simplified calculation formula is a relatively prime number. . When the calculation amount of the calculation formula is large, the simplified processing of the calculation formula can effectively reduce the amount of data calculation in the subsequent steps and improve the calculation efficiency.
[0038] For example, if the calculation formula is A=a*5*11/255, the common divisor 5 of 5 and 255 can be removed, and the simplified calculation formula is A=a*11/51.
[0039] S203. Multiply the calculation formula by 10 according to the requirements of the display accuracy of the floating-point number to be displayed. n Processing, n is a natural number.
[0040] Similar to the first embodiment, in this embodiment, the value of n is determined by the display accuracy of the floating-point number to be displayed. Specifically, if the display accuracy of the floating-point number to be displayed is required to be accurate to N digits after the decimal point, the value of n can be taken as N. For example, if the display accuracy of the floating-point number to be displayed is accurate to 3 digits after the decimal point, then the value of n is 3, and the calculation formula is multiplied by 10. 3 The processing is about to enlarge 1000 times according to the formula.
[0041] S204, multiply by 10 n The processed calculation formula performs integer calculation to obtain each display value of the floating-point number to be displayed.
[0042] In this embodiment, by simplifying the calculation formula, the amount of calculation in subsequent calculation steps is reduced, and the operating efficiency of the code is effectively improved.

Example Embodiment

[0043] Embodiment three:
[0044] image 3 It shows the flow of the floating-point number display method applied to 8-bit single-chip microcomputer according to the third embodiment of the present invention, which specifically includes S301 to S305, which are detailed as follows:
[0045] S301: Obtain a calculation formula of the floating-point number to be displayed.
[0046] S302. Simplify the calculation formula so that the known number in the simplified calculation formula is a relatively prime number.
[0047] S303. Multiply the calculation formula by 10 according to the requirements of the display accuracy of the floating-point number to be displayed. n Processing, n is a natural number.
[0048] In this embodiment, the value of n can be referred to the foregoing Embodiment 1 or Embodiment 2, which will not be repeated here.
[0049] S304, multiply by 10 n The processed calculation formula directly performs integer calculation to obtain the integer value result.
[0050] Because the input variable type of the calculation formula may be an integer, the output variable may be required to be a floating-point type. Generally, it is necessary to force the input variable type to a floating-point type before performing calculations. In this embodiment, directly multiply by 10 n The processed calculation formula performs integer calculation without forcing the variable type to obtain the integer value result.
[0051] S305: Perform integer calculation on the result of the integer value to obtain each display value of the floating-point number to be displayed.
[0052] Because the input variable of the calculation formula may be of integer type, and the output variable may be required to be of floating point type, it is usually necessary to force the input variable type to be of floating point type, and then perform calculations. The calculated result of the calculated formula is floating point When extracting each bit of the floating-point result value, you need to force the floating-point result value to an integer again, and then calculate the value of each bit. In this embodiment, since the result of the integer value obtained in step S301 is an integer, it is no longer necessary to force conversion of the variable type when calculating each display value, and directly calculate each digit of the floating-point number to be displayed through integer calculation Display value.
[0053] In order to clearly explain the technical scheme of the present invention, a specific application scenario of the present invention is given below: 8-bit microcontroller voltage sampling and display, the sampling voltage is 12.65V, and the voltage value displayed by the digital tube after sampling is required to be accurate to the decimal point. One.
[0054] Figure 4 The sampling circuit of the voltage in the 8-bit single-chip microcomputer in the application scenario provided in the third embodiment of the present invention is shown.
[0055] The calculation formula for calculating the voltage value obtained according to the sampling circuit module 41 is: Vdd=ad*5*11/255, where Vdd is the variable name of the voltage, and ad is the analog to digital conversion (Analog to Digital, AD) sampling value.
[0056] Normally, you need to go through steps a1 to a3 to get the voltage display value:
[0057] a1. Forcibly convert the integer variable ad in the calculation formula to a floating point type.
[0058] The AD sampling value ad is an integer. In order to ensure accuracy, the variable type of Vdd needs to be a floating-point type, so the variable type of ad needs to be forcibly converted to a floating-point type. The calculation formula is transformed into:
[0059] Vdd=(float)ad*5*11/255
[0060] Among them, float is a floating-point variable type.
[0061] a2. Perform floating-point calculation on the calculation formula to obtain the floating-point voltage value Vdd to be displayed.
[0062] a3. Forcibly convert the floating-point voltage value Vdd to an integer, and calculate the display value of each digit.
[0063] Use the integer variable Vdd_s, the integer variable Vdd_g and the integer variable Vdd_x to represent the tens digit, the single digit and one digit after the decimal point of the voltage value to be displayed. Since Vdd is a floating point type, it is necessary to convert Vdd to an integer type before calculating the display value of each digit. which is:
[0064] Vdd_s=((int)Vdd)/10
[0065] Vdd_g=((int)Vdd)%10
[0066] Vdd_x=((int)(Vdd*10))%10
[0067] Among them, int is an integer variable type.
[0068] It can be seen that under normal circumstances, two forced conversion of variable types and floating-point operations are required to obtain the voltage value that needs to be displayed.
[0069] Using the method provided by the present invention, the voltage display value needs to be obtained through steps b1 to b4:
[0070] b1. Simplify the calculation formula of Vdd.
[0071] Remove the common divisor 5 of the known number in the formula Vdd=ad*5*11/255, and the simplified formula is:
[0072] Vdd=ad*11/51
[0073] Among them, ad and Vdd are both set to integer.
[0074] b2. Multiply the simplified Vdd calculation formula by 10 n The enlargement processing.
[0075] According to the accuracy requirement of the displayed voltage value to one decimal place, the Vdd is magnified by 10 times, and the calculation formula after magnification is:
[0076] Vdd=ad*11*10/51
[0077] b3. Perform integer calculation on the calculation formula after amplification.
[0078] Both ad and Vdd are integer types, so there is no need to perform forced conversion of variable types and floating-point operations, and Vdd can be obtained directly through integer calculations.
[0079] b4. Perform an integer calculation on Vdd to get each display value.
[0080] Use the integer variable Vdd_s, the integer variable Vdd_g and the integer variable Vdd_x to represent the tens digit, the single digit and one digit after the decimal point of the voltage value to be displayed. Since Vdd is an integer, there is no need to force Vdd to convert the variable type, and the display value of each digit can be obtained by direct integer calculation. which is:
[0081] Vdd_s=Vdd/100
[0082] Vdd_g=(Vdd%100)/10
[0083] Vdd_x=Vdd%100
[0084] It can be seen that the method provided by the present invention does not need to undergo two forced conversions of variable types, nor does it need to perform floating-point number operations. Direct integer calculation can obtain the voltage value to be displayed with the same accuracy.
[0085] In this embodiment, by simplifying the calculation formula, the calculation amount in the subsequent calculation steps is effectively reduced, and at the same time, the calculation formula is multiplied by 10. n The magnification process reduces floating-point operations to integer operations, eliminating the need for forced type conversion between integer variables and floating-point variables, and obtains the display value result with the same arithmetic accuracy, which improves the efficiency of the code.

PUM

no PUM

Description & Claims & Application Information

We can also present the details of the Description, Claims and Application information to help users get a comprehensive understanding of the technical details of the patent, such as background art, summary of invention, brief description of drawings, description of embodiments, and other original content. On the other hand, users can also determine the specific scope of protection of the technology through the list of claims; as well as understand the changes in the life cycle of the technology with the presentation of the patent timeline. Login to view more.

Similar technology patents

Cutting fluid for machining center

InactiveCN108148669AGood product performanceIncrease productivity
Owner:宜兴市零零七机械科技有限公司

Preparation method of easy dyeing flame-retardant non-woven fabric

InactiveCN109208175Awell mixedGood product performance
Owner:王涛

Heat-insulating heat-preserving waterproof coating and method of producing the same

ActiveCN101130457BReasonable preparation processGood product performance
Owner:内蒙古建亨能源科技有限公司

Casting method for boron-phosphorus alloy cast iron

InactiveCN105886886AReasonable formula designGood product performance
Owner:李幼月

Classification and recommendation of technical efficacy words

  • Good product performance

Hard medicine capsule

InactiveCN100998572AGood product performanceStable in nature
Owner:刘杰

Impact resistance high wearing-proof conveyer belt

InactiveCN1724321AGood process performanceGood product performance
Owner:阳江市北山胶化有限公司

Modified polyurethane/unsaturated polyester resin dibasic alcohol preparation method

ActiveCN103665311AControllable curing processGood product performance
Owner:CHANGZHOU XIAOGUO INFORMATION SERVICES

Production technology for plastic-wood plate with mixed color

ActiveCN104004370ARaw material formula is reasonableGood product performance
Owner:ANHUI SENTAI WPC GRP CO LTD

Surface silicon oxidation polyimide-co-silane thin film and preparation method thereof

ActiveCN107757015AGood product performanceControllable process conditions
Owner:JILIN UNIV
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products