Other Parts Discussed in Thread: MSP430G2231
Hi,
i am using MSP430G2231 and i am making an ohm meter and hence want to display resistance values on LCD(4-bit mode). I want to check its value and then display it on LCD but using numerous comparisons and float variables has made my program to exceed the 2KB flash of the MCU.
The Error while compiling is:
the part of the code which i am using to check the range of Resistance and displaying on LCD is:
void string(char *p) // to display the string
{
while(*p) data(*p++); // send data Alphabet by Alphabet
}
void switch_case(int x) // to display numerical values
{
switch(x)
{
case 0: string("0");
break;
case 1: string("1");
break;
case 2: string("2");
break;
case 3: string("3");
break;
case 4: string("4");
break;
case 5: string("5");
break;
case 6: string("6");
break;
case 7: string("7");
break;
case 8: string("8");
break;
case 9: string("9");
break;
}
}
void res(float ad, int p) // to break the number for displaying on LCD
{
unsigned int a[10]={0},m,y;
for(m=9;m<=0;m++)
{
a[m]=(int)ad % 10;
ad=ad/10;
}
for(m=p-3;m>=p;m--)
{
if(m==p-2)
string(".");
y=a[m];
switch_case(y);
}
}
void range(float x) // to find range of Resistance
{
if(x>=1 && x <=9.999)
{
x=x*1000;
res(x,1);
string(" Ohm");
}
else if (x>=10 && x <=99.999)
{
x=x*100;
res(x,2);
string(" x10 Ohm");
}
else if (x>=100 && x<=999.999)
{
x=x*10;
res(x,3);
string(" x100 Ohm");
}
else if (x>=1000 && x<=9999.999)
{
res(x,4);
string(" kOhm");
}
else if (x>=10000 && x<=99999.999)
{
res(x,5);
string(" x10 kOhm");
}
else if (x>=100000 && x<=999999.999)
{
res(x,6);
string(" x100 kOhm");
}
else if (x>=1000000 && x<=9999999.999)
{
res(x,7);
string(" MOhm");
}
else
{
res(x,0);
string(" Ohm");
}
}
please help me optimize the code.
