发 帖  
原厂入驻New
发烧友10周年庆典,全网超值优惠来袭!千元现金券,下单抽奖赶紧参与》》
[问答] 怎么将二进制数据转换为十进制或ASCII?
520 adc 传感器 LCD
分享
亲爱的,我在端口上有二进制数据。我用ADC转换温度数据并将其显示在端口上。我的问题是下面的最佳方法是什么?1)。将二进制文件转换为其他格式,以便在七段或LCD屏幕上显示它。在温度范围内校准传感器输出。

以上来自于百度翻译


      以下为原文

    Dear All,

I have Binary data on the port. I have used ADC to convert the temperature data and displayed it on the port. My question is what is the best way to do the following.

1). Converting the binary to some other format to display it either on the seven segment or LCD screen.
2). Calibrating the sensor output in the range of temprature.
0
2019-5-21 13:02:27   评论 分享淘帖 邀请回答

相关问题

13个回答
在C中,可以使用Simulf()或ITOA-()将一个数字转换成一个字符串。

以上来自于百度翻译


      以下为原文

    In C, you can use sprintf() or itoa() for converting a number into a string.
 
Not sure about calibration...
2019-5-21 13:16:33 评论

举报

也许你可以指定你使用的传感器,最好的方法是读取传感器数据表转换系数或校准。

以上来自于百度翻译


      以下为原文

   


Maybe you can specify which sensor you are using, The best way is to read that sensor datasheet for conversion factor or calibration.
2019-5-21 13:26:02 评论

举报

嗨,你用哪一张照片?问候

以上来自于百度翻译


      以下为原文

    Hi,
Which PIC to you use ??
Regards
2019-5-21 13:35:21 评论

举报

内存中的数字是一个数字。二进制、十进制、十六进制或八进制是人类的概念。所以你可以直接到7段显示器。对于LCD,您需要将其转换为ASCII。如SeaTrf()和IRIS所示。对于较小的图片,最好是转换代码。有几种方法来校准传感器。首先是线性的。常用的方法包括线的比率和斜率公式。你是在寻找互联网结果还是浮点?哪一张照片?

以上来自于百度翻译


      以下为原文

    The number in memory is a number. Binary , deciamal, hex or octal is a human concept.
So you can go right to a 7 segment display.
For an LCD you would need to convert it to ascii. As noted sprintf() and iris are choices. For smaller pics it may be better to code the conversion.
There are several ways to calibrate a sensor.
First is it linear.
The common ways include ratios and the slope formula for a line.
Are you looking for an internet result or a float?
And which pic?
2019-5-21 13:54:20 评论

举报

在快速浏览了一些原始海报开始的主题之后,看起来OP可能正在使用安装在Linux操作系统上的MPLABX,并使用用于PIC18F系列控制器的XC8编译器。人读形式。在大多数情况下,这包括范围限制、缩放和偏移。当使用模数转换器时,由具有有限数量的分辨率位的ADC施加范围限制。对于大多数PIC18F部件,这将是8位、10位或12位。有几个具有16位ADC的PIC18F部件。OP状态:“我在端口上有二进制数据。我用ADC转换温度数据并显示在端口上。“这表明传感器提供一个模拟输出电压来表示温度。温度传感器通常为较冷的温度提供低电压,为较热的温度提供高电压。这意味着零的ADC读数将是系统可以感测到的最冷的温度,并且所有ONES的ADC读数将代表系统最热的温度。当ADC读数接近零时,OP需要使用参考温度计来校准系统,称之为T0,称之为T1。为了将ADC读数转换为与参考温度计相同的标度,将ADC读数乘以(T1-T0)/(ADC最大计数),然后将T0添加到结果。注意,8位ADC的最大计数是255,10位ADC的最大计数是1023,12位ADC的最大计数是4095,并且这个计算应该使用浮点算法。用32位带符号的算术可以做到这一点,但是可能有点麻烦。使用C标准数学和字符串库函数将结果转换为ASCII字符串。函数sprintf()可以用于执行这些格式化,但是它将绑定到许多代码中,因此您将冒用尽应用程序的代码空间的风险。如果您的PIC有大量的闪存,超过16K字节,那么使用sprintf()应该可以。根据经验,您可以理解用于使代码更小更有效的方法。

以上来自于百度翻译


      以下为原文

    After taking a quick look at some of the topics the Original Poster started it seems that the OP may be using MPLABX installed on a Linux OS and using the XC8 compiler for the PIC18F family of controllers.
 
The question the OP asked is about the conversion of numeric values to be displayed in some human readable form.
 
In most cases this involves range limits, scaling and offsets.
 
When using an Analog to Digital Converter there are range limitations imposed by the ADC having a finite number of bits of resolution. For most PIC18F parts this will be 8-bits, 10-bits or 12-bits. There are a few PIC18F parts with 16-bit ADCs.
 
The OP states: "I have Binary data on the port. I have used ADC to convert the temperature data and displayed it on the port."
 
This suggests that the sensor provides an analog output voltage that represent the temperature. It is usual for temperature sensors to provide a low voltage for colder temperatures and a higher voltage for warmer temperatures.
 
This means that an ADC reading of ZERO will be the coldest temperature the system can sense and an ADC reading of all ONES will represent the warmest temperature the system can sense.
 
What the OP will need to do is to calibrate the system by using a reference thermometer to measure the actual temperature when the ADC readings are close to ZERO, call this T0, and close to all ONES call this T1. To convert the ADC readings to the same scale as the reference thermometer multiply the ADC reading by (T1-T0)/(ADC maximum count) then add T0 to the result. Note that the maximum count for an 8-bit ADC is 255, for a 10-bit ADC it is 1023, for a 12-bit it is 4095, also this calculation should use floating point arithmetic. It is possible to do this with 32-bit signed arithmetic but is can get a bit tricky.
 
Use C standard math and string library functions to convert the result to an ASCII string. The function sprintf() can be used to do these kinds of formatting but it will bind in a lot of code so you run the risk of running out of code space for your application. If your PIC has a large amount of flash, more that 16K bytes, you should be fine using sprintf().
 
With experience you can understand the methods used to make the code that does this smaller and more efficient.
2019-5-21 14:13:01 评论

举报

嗨,二进制数据是数字计算机中整数数据的本机表示。十六进制或八进制是用于打印或显示的表示,易于安排。在小型8位计算机上,将二进制整数转换为十进制数字非常麻烦。sprintf和itoa都具有以下功能:可以使用上面建议的。它们都使用几千个指令周期从16位整数值中挑选出5个十进制数字。去年,关于这个转换的更有效的算法,有一个很长的线索:http://www..hip.com/for./FindPost/857650。对PIC16设备和具有8位硬件乘法器的PIC18设备的补充说明,这对此很有用。在这个线程中,在“3_Phase_Vol.”程序内部:http://www.micro..com/for./FindPost/964778is:uBin_Dec.c withIn here,PIC16和PIC18设备的汇编代码为inl在C函数中使用。它与字母数字LCD显示器上的显示结合使用。

以上来自于百度翻译


      以下为原文

    Hi,
Binary data is the native representation of integer data in a digital computer.
Hexadecimal or octal are representation for print or display that is easy to arrange.
Converting binary integer to decimal digits is surprisingly cumbersome on a small 8 bit computer.
 
Both sprintf and itoa functions, as suggested above, may be used.
They will both use a few thousand instruction cycles to pick out 5 decimal digits from a 16 bit integer value.
 
Last year, there was a long thread about more efficient algorithms for this conversion:
http://www.microchip.com/forums/FindPost/857650
There are alternative implementations for PIC16 devices,
and for PIC18 devices which have a 8-bit hardware multiplier that is useful for this.
 
In this thread, inside the 'Three_Phase_Voltage' program:
http://www.microchip.com/forums/FindPost/964778 
is: uBin_Dec.c   with
In there, assembly code for PIC16 and PIC18 devices, is inlined in C functions.
It is used in connection with display on a alphanumeric LCD display.
 
Regards,
   Mysil
2019-5-21 14:30:27 评论

举报

我使用PIC18F45 K22。我使用Microchip热敏电阻器MCP97。参见下面的链接。http://WW1. Microchip…com /…N/DeviceDoc /21942E.PDF

以上来自于百度翻译


      以下为原文

    I am using PIC18F45K22. 
 
I am using Microchip thermister MCP9700.
see the following link.
http://ww1.microchip.com/...n/DeviceDoc/21942e.pdf
2019-5-21 14:36:02 评论

举报

10mV每°Cif你的ADC范围为0..5V并且有10位,每一步意味着4mV左右,因此0.4°CEasy组成一个公式。

以上来自于百度翻译


      以下为原文

    10mV per °C
if your ADC ranges 0..5V and has 10bits, each step will mean 4mV circa hence 0.4°C
 
Easy to make up a formula
2019-5-21 14:44:00 评论

举报

小心,MCP9700有0.5伏的偏移。这意味着当传感器在0°C时,MCP9700的输出是500mV。

以上来自于百度翻译


      以下为原文

    Be cautious, the MCP9700 has a 0.5 volt offset.

This means when the sensor is at 0°C the MCP9700 output is 500mV.
2019-5-21 14:51:45 评论

举报

现在它工作在OpenADC中有一个错误,C18和XC8都有不同的原型。在我的程序中,在“输出”变量中得到ADC的输出。如果我想根据传感器的温度公式来绘制它,它是否正确?VOUT=TC·TA+V0°Chere TC是10,V0°C是500mV.TA=(VOUT-500mV)/10简而言之,我应该再用一个变量TA(FLOAT)来存储温度值?

以上来自于百度翻译


      以下为原文

    Now it working there was a mistake in OpenADC, Both C18 and XC8 has a different prototype.
 

 
Also, I have further question regarding converting. In my program I get output of ADC in "out" variable. If I want to map it according to the temperature formula of a sensor than is it right?
 
VOUT = TC • TA + V0°C 
here TC is 10 and V0°C is 500mV.
TA = (VOUT-500mV)/10
 
In short, I should take one more variable TA (FLOAT) to store the temperature values?
 
2019-5-21 15:01:01 评论

举报

我有VOUT=TC·TA+V0°CTC=10和V0=500mv,传感器可以测量从-40到125℃,所以我得到V-40=100和V125=1750,所以范围是1650,每步变化给我1.611mV。

以上来自于百度翻译


      以下为原文

    I have 
VOUT = TC • TA + V0°C
TC=10 and V0=500mv and the sensor can measure from -40 to 125 C so I got V-40=100 and V125=1750 so the range is 1650 which gives me 1.611 mV per step change.. 
2019-5-21 15:10:55 评论

举报

在其他线程中回答。至于步骤,这看起来很奇怪…

以上来自于百度翻译


      以下为原文

    Answered in other thread.
As for the steps, this looks strange...
2019-5-21 15:30:06 评论

举报

浮点计算和整数除法都是在8位计算机上缓慢而繁琐的操作。由于温度传感器的灵敏度为每°C 10mV,所以用整数毫伏计算可能很方便,并且可以避免浮点计算和长除法。对毫伏的直流测量可以这样进行。你需要知道微控制器中ADC的参考电压。如果VREF为3300毫伏,ADC的分辨率为10位,那么从ADC测量到毫伏的缩放可以这样进行:可以通过修改整数常数来进行校准调整。

以上来自于百度翻译


      以下为原文

    Both floating point calculations, and integer division are slow and cumbersome operations on a 8 bit computer.
 
With the sensivity of the temprature sensor 10mV per °C,
calculating in integer millivolt may be convinient, and may avoid both floating point calculations and long division.

Scaling from ADC measurement to millivolt may be done like this.
You need to know the reference voltage of the ADC in the microcontroller.
If VREF is 3300 millivolt and resolution of ADC is 10 bits,
scaling from ADC measurement to millivolt may be done like this:
   unsigned int millivolt, ADC_result;
    signed int   temprature01;

    millivolt = ADC_result * 3300ul >> 10;
    temprature01 = millivolt - 500; /* This is temprature in units of 0.1 °C. */
Calibration adjustments may be done by modifying the integer constants.
 
Regards,
   Mysil
 
2019-5-21 15:35:52 评论

举报

只有小组成员才能发言,加入小组>>

47个成员聚集在这个小组

加入小组

创建小组步骤

关闭

站长推荐 上一条 /10 下一条

快速回复 返回顶部 返回列表