hi sir i need one help now iam doing project on 89c51 using C51 Evaluation Software i converted 0-5 analog volatge to 0-5 digital voltage . now i want convert digital data to pressure my output should be like this 0v 1.1E-1 3v 4.1E-4 0.1 1.2E-1 4v 5.1E-5 1v 2.1E-2 5v 6.1E-6 2v 3.1E-3 i want 500 values in between 0 to 5 volts how to calibrate the voltage interms of preesure what logic i want use to convert Voltage to pressure my C51 not taking floting oparations please help regards chandra sri
"my job is simply display the preesure for caresponing input voltage" If it's purely for display purposes. maybe strings would be best:
unsigned int voltage; // In units of 10mV char pressure_string[] = { "1.1E-1", // Index 0 corresponds to 0mv "1.2E-1", // Index 1 corresponds to 10mv "1.3E-1", // Index 2 corresponds to 20mv : : } printf( "Voltage %u mV = Pressuse %s", voltage*10, pressure_string[voltage] );
thank you sir i tried this program but iam getting one error #include<stdio.h> #include<reg51.h> #include <string.h> void main() { unsigned int voltage; char pressure_string[2] ={"1.1E-1","1.2E-1","1.3E-1"}; voltage=0x0A; /*10mv*/ SCON = 0x50; TMOD |= 0x20; TH1 = 221; TR1 = 1; TI = 1; printf( "Voltage %u mV = Pressuse %s", voltage*10, pressure_string[voltage] ); } iam getting this error compiling forum.c... MAIN\FORUM.C(8): error C243: 'array[]': string out of bounds main\forum.c - 1 Error(s), 0 Warning(s). sir how much memory well take for 500 values of the look up table regards chandu
sir char pressure_string[] ={"1.1E-1","1.2E-1","1.3E-1"};
"compiling forum.c... MAIN\FORUM.C(8): error C243: 'array[]': string out of bounds" Look-up the error in the Manual - it tells you exactly what is wrong! http://www.keil.com/support/man/docs/c51/c51_c243.htm
"how much memory well take for 500 values of the look up table" Keil C51 does not add any extra space for padding or alignment; therefore the size of an array is simply the size of one element multiplied by the number of elements in the array. The sizes of the data types used by C51 are listed in the Manual: http://www.keil.com/support/man/docs/c51/c51_ap_datastorage.htm You need to become familiar with the Manual - that doesn't mean you have to learn it by heart, but you need to be familiar with what's in it, and how to find stuff in it... You probably also need a good 'C' textbook...
sir i tried this expressions char pressure_string[] ={"1.1E-1","1.2E-1","1.3E-1"}; it is showing same error char pressure_string[3] ={"1.1E-1","1.2E-1","1.3E-1"}; it is also showing same error then which is correct. thank you
Oops - I made a mistake in the code I posted:
char pressure_string[] = { "1.1E-1", // Index 0 corresponds to 0mv "1.2E-1", // Index 1 corresponds to 10mv "1.3E-1", // Index 2 corresponds to 20mv : : }
Iam sorry sir i can not spot your mistake please give solution for that one thank you sir
It's a classic 'C' programmer's mistake! You need to learn to spot these things if you want to do 'C' programming! (it's the kind of thing you'd get in a 'C' test at a job interview!) Another hint: what's the difference between a char and a string in 'C'? Don't be afraid to look in your 'C' textbook... (they probably won't let you do that in an interview, though!)
Have you given up? Try
char * pressure_string[] =
hi sir thank you sir i tried this program { unsigned int voltage; unsigned char *pressure_string[] ={"11E-1","12E-2","13E-3"}; printf( "Voltage %u mV = Pressuse %s", voltage*10, pressure_string[voltage] ); } it is showing folling out put "voltage 10mv=pressure 13E- " it is not showing full value. regards nari
When you posted your data as
0.00v =1.1E-1 0.01v =1.2E-1 0.02v =1.3E-1 . . 1.00 =2.1E-2 . . 2.00 =3.1E-3 . . 3.00 =4.1E-4 4.00 =5.1E-4 5.00 =6.1E-5
char * pressure_string[] = { "1.1E-1", // Index 0 corresponds to 0mv "1.2E-1", // Index 1 corresponds to 10mv "1.3E-1", // Index 2 corresponds to 20mv : : }
{ unsigned int voltage; unsigned char *pressure_string[] ={ "11E-1", "12E-2", "13E-3" }; printf( "Voltage %u mV = Pressuse %s", voltage*10, pressure_string[voltage] ); }
printf( "Voltage %u mV = Pressuse %s\r\n", voltage*10, pressure_string[voltage] );
Hi sir I assign a value to 'voltage' now iam geting correct values. up to 24 string elements [array elements]it showing correct. Above the 24 elements it is compiling but it is showing linking error the error is: "Build target 'Target 1' linking... *** ERROR L107: ADDRESS SPACE OVERFLOW SPACE: DATA SEGMENT: _DATA_GROUP_ LENGTH: 0071H Program Size: data=123.1 xdata=0 code=1559 Target not created*/" above the 50 elements it is not compiling and showing this error . the error is: " compiling forum.c... MAIN\FORUM.C(19): error C241: 'main': auto segment too large main\forum.c - 1 Error(s), 0 Warning(s). " regards chandu
*** ERROR L107: ADDRESS SPACE OVERFLOW SPACE: DATA This means that there is not enough memory available in DATA memory space to hold all the variables you have declared. Which is not surprising, as the 8052 only has 128 bytes of DATA memory. Since your programm will most likely not change the contents of the string array at run-time, you could simply store the array in CODE space instead. If the program does need to change the contents, and your device has enough XDATA memory, store the array there instead. Refer to the Cx51 manual for more information on memory types and areas: http://www.keil.com/support/man/docs/c51/c51_extensions.htm
Chandra, Is it just that English is not your first language, or do you really not understand the word "OVERFLOW" ? See: http://www.keil.com/forum/docs/thread7364.asp As Christoph says, the data in the lookup table is constant - it will not change at run-time - so you should put it into CODE space. You might find that you exceed the code space limit of the evaluation version, though...