二进制转化成ascll_怎么将二进制数据转换为十进制或ASCII?

以上来自于百度翻译

以下为原文

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

评论

提交评论

以上来自于百度翻译

以下为原文

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

评论

提交评论

以上来自于百度翻译

以下为原文

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

评论

提交评论

以上来自于百度翻译

以下为原文

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

评论

提交评论

以上来自于百度翻译

以下为原文

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 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

评论

提交评论

以上来自于百度翻译

以下为原文

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

评论

提交评论

以上来自于百度翻译

以下为原文

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

评论

提交评论

以上来自于百度翻译

以下为原文

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

评论

提交评论

以上来自于百度翻译

以下为原文

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

评论

提交评论

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值