Pulse_Sensor_V01/main.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_PrintFloat(float x, unsigned char length, unsigned char coma)
{
    if(x>=0)LCD_Display(' ');
    else
    {
        LCD_Display('-');           
        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_CursorShift(1,length);              
    P2OUT &=~0x02;
    _delay_cycles(lcd_delay);
    LCD_Command(0x04);                
    while(coma)                             
    {
        temp = n % 10;
        n = n / 10;
        LCD_Display(0x30 + temp);
        coma--;
        length--;
    }
    LCD_Display('.');                           
        while(length)                           
        {
            temp = n % 10;
            n = n / 10;
            LCD_Display(0x30 + temp);
            length--;
        }
    P2OUT &=~ 0x02;
    _delay_cycles(lcd_delay);
    LCD_Command(0x06);                
    LCD_CursorShift(1,store+1);                 
}
void LCD_PrintFloat ( float x , unsigned char length , unsigned char coma ) { if ( x >= 0 ) LCD_Display ( ' ' ) ; else { LCD_Display ( ' ' ) ; 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_CursorShift ( 1 , length ) ; P2OUT &= ~ 0x02 ; _delay_cycles ( lcd_delay ) ; LCD_Command ( 0x04 ) ; while ( coma ) { temp = n % 10 ; n = n / 10 ; LCD_Display ( 0x30 + temp ) ; coma -- ; length -- ; } LCD_Display ( ' ' ) ; while ( length ) { temp = n % 10 ; n = n / 10 ; LCD_Display ( 0x30 + temp ) ; length -- ; } P2OUT &= ~ 0x02 ; _delay_cycles ( lcd_delay ) ; LCD_Command ( 0x06 ) ; LCD_CursorShift ( 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.