Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

89C51 Math problem using Keil

Status
Not open for further replies.

Uridan

Newbie level 4
Joined
Jun 11, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,343
keil bcd to 16 int

Hi

I am using keil to program my 89C51 using C language, and I am trying to work the following equation.

humidity = (0.6785 * (ADC_value)) - 27.1

note that ADC_value is giving correct values.

But when I build my program it will give me 8 warrnings and when I debug my program the humidity will remain empty, thus the equation is not being implimented within the program.

So I decided to eliminate the Point, at first by using the following equation.

humidity = ((6785 * (ADC_value))/10000) - 27

This time no warrnings were given but when debugging the program a pair of .. will always appear regardless the ADC value. thus again, the equation is not workling properly.

Again, I decided to manipulate the equation for testing and used the following:

humidity = ((6785 * 2)/10000) - 27, but again the value was not right. so I turning the -27 to + 27 and guess what, the equation worked.

I have no idea what I am doing wrong. Also the keil can work log10(x), sin(x) etc but the program will give some warrnings and will not exectute that part of the program.

I am using the <math.h> library.

Am I missing something important here ?

void sendhumidity_data()
{
char humidity;

//humidity = (((6785)*(150))/10000)-27;
humidity = ((6785*2)/10000) + 20;
bin=(humidity/10); //select first digit of value converted
bin1= bin + 0x30;
dec = (humidity % 10); //most significant digit
dec1 = dec + 0x30;
SBUF = bin1;
while(TI == 0); //Wait until the serial data is sent.
TI = 0;
SBUF = dec1;
while(TI == 0); //Wait until the serial data is sent.
TI = 0;
}

Note: bin and dec are both unsigned char.

The humidity value should be between 99 - 0 and since I am using hyperterminal I am spliting the hex result in two to display the right ASCII characters from 0 to 9 serially.

Any help would be great please

Regards
Uridan
 

unsigned long int problem in keil

Use data-type of humidity as integer or long and then typecast it to char after the calculation.
 

math functions for 89c51

CMOS, do you mean like this:

void sendhumidity_data()
{
char humidity;
long int humidity1; //I tried int , long and long int.

humidity1 = (((6785)*(150))/10000)-27;
//humidity1 = ((6785*2)/10000) + 20;
humidity = humidity1;

bin=(humidity/10); //select first digit of value converted
bin1= bin + 0x30;
dec = (humidity % 10); //most significant digit
dec1 = dec + 0x30;
SBUF = bin1;
while(TI == 0); //Wait until the serial data is sent.
TI = 0;
SBUF = dec1;
while(TI == 0); //Wait until the serial data is sent.
TI = 0;
}


I tried this but it gave same results as before.

Regards
 

humidity math problems

Ok try these
Don't convert humidity to HEX. Try sending percentage humidity directly.
User RealTerm terminal program to debug. It has HEX mode so you can directly see the HEX equivalent of the character received.
Let me know what result you get.

OR

Since KEIL has very good in-built string functions, try printing values after each calculation using printf function. Make sure serial interrupt is disabled otherwise printf wont work.
 

math problem bin empty 5 hours bin full 2 hours

This is wrong on so many levels…
First, depending on the range of your conversions, you’ll probably need to write something like this:
Code:
char humidity = (char)(((6785L * (ADC_value) + 5000)/10000) - 27);
(The “L” after 6785 prevents truncations by instructing the compiler to do calculations on long integers. The adding of 5000 = 10000/2 is for proper rounding.)
This assumes that your ADC_value is always in the interval [40, 415], or else you’ll have an under-/over-flow on char, so you’ll have to limit that.
Furthermore, your “BCD string conversion” assumes humidity in the range [0, 99], or else it will not work and this further reduce the interval of allowed ADC_value to [40, 185] (do the math!).

And I'm not even thinking of touching the subject of serial communication...

Beside all the flaws, I don’t think they are the reason of you not seeing the variable in debug, but rather the optimizations you might have enabled. Remember to always disable all optimizations when you debug!

Arthur
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top