Код: Выделить всё
void IntPrintLCD(int number)
{
unsigned char KeyDisp[16];
lcd_gotoxy(num,0);
sprintf(KeyDisp,"%d",number);
lcd_puts(KeyDisp);
num++;
}Код: Выделить всё
void IntPrintLCD(int number)
{
unsigned char KeyDisp[16];
lcd_gotoxy(num,0);
sprintf(KeyDisp,"%d",number);
lcd_puts(KeyDisp);
num++;
}Код: Выделить всё
#define NDIG 6
#define NFTOA (NDIG+4)
/*
* convert floating to ascii. ftoa returns an integer e such that
* f=g*10**e, with .1<=|g|<1 (e=0 when g==0) and puts an ascii
* representation of g in the buffer pointed to by bp. bp[0] will
* be '+' or '-', and bp[1] to bp[NFTOA-2]
* will be appropriate digits of g. bp[NFTOA-1] will be '\0'
*/
int ftoa(double f, char *bp){
int e, e1, e2;
char i;
double digit, g, p;
if(f>=0) *bp++=' ';
else{
f=-f;
*bp++='-';
}
/* find e such that f==0 or 1<=f*pow10(e)<10, and set f=f*pow10(e) */
if(f==0.) e=1;
else{
frexp(f, &e);
e=-(long)e*30103L/100000L;
/* split in 2 pieces to guard against overflow in extreme cases */
e1=e/2;
e2=e-e1;
p=f*pow(10,e2);
while((g=p*pow(10,e1))<1.) e1++;
while((g=p*pow(10,e1))>=10.) --e1;
e=e1+e2;
f=g+1e-7;
}
for(i=0;i!=NDIG;i++){
f=modf(f, &digit)*10.;
*bp++=(char)(digit+'0');
}
*bp='\0';
return 1-e;
}
//========================
//Преобразование числа ф строку
//x- число, State=0 - без Е, State=1 - с Е
char ConvertDouble(double x, char State,char *St)
{ int Exp;
char *StS;
char *p;
char i;
StS=St;
//x=10.0;
Exp=ftoa(x,St);
if(((Exp<1)||(Exp>(NDIG))||(x==0)))
{ for(i=NDIG+2;i>2;i--)
St[i]=St[i-1];
St[2]='.';
}//if((Exp<0)||(Exp>6))
else
{ for(i=NDIG+2;i>Exp;i--)
St[i]=St[i-1];
St[Exp+1]='.';
}//else if((Exp<0)||(Exp>6))
while (*StS++);
*StS--;
p=StS;
*StS--;
while(*StS=='0')
*StS--=' ';
StS=p;
*StS++='\0';
*StS--;
if(x!=0)
{ if(((Exp<1)||(Exp>(NDIG))))
{ if(State)
*StS++='E';
Exp--;
if(Exp<0)
{ *StS++='-';
Exp=-Exp;
}//if(Exp<0)
else
{ *StS++=' ';
}//else if(Exp<0)
*StS++=(Exp/10)+'0';
*StS++=(Exp%10)+'0';
*StS++='\0';
}// if((Exp<0)||(Exp>NDIG))
}
return 0;
}