DS1307/LCD/LCD.c
/* In ra man hinh so thuc x voi so cho hien thi = length, so chu so sau dau phay la coma */
In ra man hinh so thuc x voi so cho hien thi = length, so chu so sau dau phay la coma
In ra man hinh so thuc x voi so cho hien thi = length so chu so sau dau phay la coma
void LCD_Put_Float(float x, unsigned char length, unsigned char coma)
{
    if(x>=0)LCD_Put_Char(' ');
    else
    {
        LCD_Put_Char('-');           
        x*=-1;
    }
    unsigned long n;
    unsigned char store,temp;
    store = length;                     
    length--;                               
    for(temp=0;temp<coma;temp++)
        x = x*10;
    n = x;                                  
    if((x-n)>=0.5)n++;
    LCD_Cursor_Shift(1,length);              
    PORT_LCD_RS &=~ LCD_RS;
    #ifdef USE_LCD_WAIT
    LCD_Wait();
    #else
    _delay_cycles(50*Freq_MHz);
    #endif
    LCD_DEC_CUR_SHIFT_OFF();                
    while(coma)                             
    {
        temp = n % 10;
        n = n / 10;
        LCD_Put_Char(0x30 + temp);
        coma--;
        length--;
    }
    LCD_Put_Char('.');                           
        while(length)                           
        {
            temp = n % 10;
            n = n / 10;
            LCD_Put_Char(0x30 + temp);
            length--;
        }
    PORT_LCD_RS &=~LCD_RS;
    #ifdef USE_LCD_WAIT
    LCD_Wait();
    #else
    _delay_cycles(50*Freq_MHz);
    #endif
    LCD_INC_CUR_SHIFT_OFF();                
    LCD_Cursor_Shift(1,store+1);                 
}
void LCD_Put_Float ( float x , unsigned char length , unsigned char coma ) { if ( x >= 0 ) LCD_Put_Char ( ' ' ) ; else { LCD_Put_Char ( ' ' ) ; x *= -1 ; } unsigned long n ; unsigned char store , temp ; store = length ; length -- ; for ( temp = 0 ; temp < coma ; temp ++ ) x = x * 10 ; n = x ; if ( ( x - n ) >= 0.5 ) n ++ ; LCD_Cursor_Shift ( 1 , length ) ; PORT_LCD_RS &= ~ LCD_RS ; #ifdef USE_LCD_WAIT LCD_Wait ( ) ; #else _delay_cycles ( 50 * Freq_MHz ) ; #endif LCD_DEC_CUR_SHIFT_OFF ( ) ; while ( coma ) { temp = n % 10 ; n = n / 10 ; LCD_Put_Char ( 0x30 + temp ) ; coma -- ; length -- ; } LCD_Put_Char ( ' ' ) ; while ( length ) { temp = n % 10 ; n = n / 10 ; LCD_Put_Char ( 0x30 + temp ) ; length -- ; } PORT_LCD_RS &= ~ LCD_RS ; #ifdef USE_LCD_WAIT LCD_Wait ( ) ; #else _delay_cycles ( 50 * Freq_MHz ) ; #endif LCD_INC_CUR_SHIFT_OFF ( ) ; LCD_Cursor_Shift ( 1 , store + 1 ) ; }
In ra man hinh so thuc x voi so cho hien thi = length, so chu so sau dau phay la coma
In ra man hinh so thuc x voi so cho hien thi = length so chu so sau dau phay la coma
// de trong 1 ki tu o dau cho hien thi dau //In so am // Luu lai do dai so thuc. // Giam di 1 cho dau "." // Chuyan thanh so nguyen. // Dich chuyen con tro sang phai // Chuyen sang che do in nguoc. // In ra phan truoc dau phay // In ra dau "." // In ra phan thap phan //if(temp!=n) // Chuyen lai che do in thuan // Nhay den vi tri tiep theo.