Exemplo n.º 1
0
void kuwa(){
    lcd_set_char('(');
    lcd_set_char(0xdf);
    lcd_set_char(0x07); // "Д"
    lcd_set_char(0xdf);
    lcd_set_char(')');
}
void Splash() {

	lcd_init();
	
	struct animStep anim[16];
	char name[3];

	lcd_set_char(0,(unsigned char*)Aini0);
	lcd_set_char(1,(unsigned char*)Aini1);
	lcd_set_char(2,(unsigned char*)Aini2);
	lcd_set_char(3,(unsigned char*)Aini3);
	lcd_set_char(4,(unsigned char*)Aini4);
	lcd_set_char(5,(unsigned char*)Aini5);
	lcd_set_char(6,(unsigned char*)Aini6);
	lcd_set_char(7,(unsigned char*)Aini7);

	int animLength = 13; 
	int i;
	
	anim[0]  = createStep(6,8,2);
	anim[1]  = createStep(6,8,2);
	anim[2]  = createStep(0,8,2);
	anim[3]  = createStep(1,8,2);
	anim[4]  = createStep(2,8,2);
	anim[5]  = createStep(3,8,2);
	anim[6]  = createStep(4,9,2);
	anim[7]  = createStep(3,10,2);
	anim[8]  = createStep(4,11,2);
	anim[9]  = createStep(3,12,2);
	anim[10] = createStep(1,12,2);
	anim[11] = createStep(0,12,2);
	anim[12] = createStep(7,12,2);

	name[0] = 'D';
	name[1] = 'L';
	name[2] = 'L';


	for(i = 0; i < animLength; i++) {
		if(i == 6) {
			lcd_gotoxy(i+2,2);
			_lcd_write_byte(5,1);
		}
		else if(i > 6 && i < 10) {
			lcd_gotoxy(i+2,2);
			_lcd_write_byte(6,1);
			lcd_gotoxy(i+2,1);
			_lcd_write_byte(name[i-7],1);
		}
		lcd_gotoxy(anim[i].posx,anim[i].posy);
		_lcd_write_byte(anim[i].sprite,1);
		_delay_ms(100);
	}

	_delay_ms(1000);
	lcd_clear();


}
int Draw(object* obj, int start) {
	// make empty array of tiles
	unsigned char screen[20][4][8];
	int a,b,c;
	for(a = 0; a < 20; a++)
		for(b = 0; b < 4; b++)
			for(c = 0; c < 8; c++)
				screen[a][b][c] = 0;

	//calculate pixels to be drawn
	int y,x;
	for(y = 0; y < obj->h; y++) {
		for(x = 0; x < obj->w; x++) {
			screen[(obj->y + y)/CHARH][(obj->x + x)/CHARW][(obj->x + x)%CHARW] |= (1<<((SCREEN_HEIGHT-1-(obj->y + y))%CHARH));
		}
	}

	// generate sprites and draw
	int spriteNum = start;
	for(y = obj->y-(obj->y%CHARH); y < obj->y+obj->h; y+= CHARH) {
		for(x = obj->x-(obj->x%CHARW); x < obj->x+obj->w; x+= CHARW) {
			if(spriteNum < 7) {
				lcd_set_char(spriteNum,(unsigned char*)screen[y/CHARH][x/CHARW]);
				lcd_gotoxy(y/CHARH, x/CHARW);
				_lcd_write_byte(spriteNum++,1);
			}
		}
	}
	return spriteNum;
		
}
Exemplo n.º 4
0
// LCD character allocation
void lcd_locate(unsigned char row, unsigned char col)
{
	// set instruction input mode
    RS      =   0;
//	lcd_set_char(0x80 | col | (0x40 * row) );
	lcd_set_char(0x80 | ( col + 20*(unsigned int)(row/2) ) | ( 0x40 * (row%2) ) );
	// set data input mode
    RS      =   1;
}
Exemplo n.º 5
0
void shakin(){
    lcd_set_char('(');
    lcd_set_char(0x60);
    lcd_set_char(0xa5);
    lcd_set_char(0x06); // "ω"
    lcd_set_char(0xa5);
    lcd_set_char(0x27);
    lcd_set_char(')');
}
Exemplo n.º 6
0
void shobon(void){
    lcd_set_char('(');
    lcd_set_char(0x27);
    lcd_set_char(0xa5);
    lcd_set_char(0x06); // "ω"
    lcd_set_char(0xa5);
    lcd_set_char(0x60);
    lcd_set_char(')');
}
Exemplo n.º 7
0
int main(void)
{

    // for 74HC595 port setting for LCD
    SoftSPI_Init();
    
    // for 74HC595 port setting for LED array
    SoftSPI_LED_Init();
    
    // Initialize LCD
	lcd_init();
	
    // Timer for PWM driver initialize
    timer0_init();
    
    // TachoMeter counter initialize
    timer1_init();

    // delay counter initialize
    timer2_init();
    
    // PWM output port definition
    DDRD |= (1<<PD6);
    
	// USART initialize
	USARTinit(UBRR);
	
	// Ext. Interupt setting
	ExtInterrupt_init();
    
    // TicToc initialize
    tictoc_init(FOSC, Ndiv1);
    
    // Tacho Meter Initialize
    TachoMeter_init(FOSC,Ndiv1);
    
    // Bar-Meter Initialize
    BarMeter_init();
    
    // Facemark character Initialize
    FaceMark_init();
    
    // Set Initial Target IDs
    set_initial_t_id();
    
	// Declarations
	unsigned char*   opening_message0 = "Multi-Function Meter";
    unsigned char*   opening_message1 = "     Timer Test     ";
    unsigned char*   opening_message2 = "   Firmware Rev.6   ";
    
	uint8_t         n, m;					// 'for' loop variables
    
	uint8_t         index = 0;				// LCD displaying data index
	
	uint16_t		maxv = 2352;			// maximum decimal angle data value from 'Defi Link Unit II'
    
	uint8_t         id;						// ID index for processing
    
	uint8_t         valid_packet[Ndata];	// Validtity indicator
	
	uint8_t			low4bits[4];			// Extracted lower 4 bits from byte data
	uint16_t        dec_ang;				// Angle data (decimal)
	float           dec_nrm;				// Angle data (decimal)
	float			value[Ndata];			// Decoded value
    uint16_t        mult_factor[3];		// Multiplying factor for hexadecimal to decimal decoding
    
	uint8_t         digits_int[5];			// Digits integer data
	unsigned char	digits_char[5];			// Digits character data for display
    
	float           div_factor;				// Dividing factor for integer
	uint8_t         digits_valid;			// Indicate digits in integer are valid or invalid
    
    // value = eq_grad * dec_nrm + eq_intercept
    // Gradient-term of decoding equation
	uint16_t eq_grad[] = {
        3,	// Turbo
        9000,	// Tacho
        10,	// Oil pres.
        6,	// Fuel pres.
        900,	// Ext. Temp.
        100,	// Oil Temp.
        100	// Water Temp.
    };
    
    // Intercept-term of decoding equation
    int16_t eq_intercept[] = {
        -1,	// Turbo
        0,	// Tacho
        0,	// Oil pres.
        0,	// Fuel pres.
        200,	// Ext. Temp.
        50,	// Oil Temp.
        20	// Water Temp.
    };
    
    // Definition of number of significant figure
	uint8_t   Nsig[] = {				// Number of significant figures
        3,	// Turbo
        4,	// Tacho
        3,	// Oil pres.
        3,	// Fuel pres.
        4,	// Ext. Temp.
        3,	// Oil Temp.
        3	// Water Temp.
    };
    
    // Deifinition of number of integer figure
	uint8_t	Nint[] = {				// Number of integr digits
        1,	// Turbo
        4,	// Tacho
        2,	// Oil pres.
        1,	// Fuel pres.
        4,	// Ext. Temp.
        3,	// Oil Temp.
        3	// Water Temp.
    };
    
    uint8_t	SIGN[] = {				// Show +/-, enable showing is '1'
        1,	// Turbo
        0,	// Tacho
        0,	// Oil pres.
        0,	// Fuel pres.
        0,	// Ext. Temp.
        0,	// Oil Temp.
        0	// Water Temp.
    };
    
	uint8_t	Nspace[7];				// Number of space between character and digits
    float   Resolution[7];


    RxName[0]		=   "BOOST";
    RxName[1]		=   "TACHO";
    RxName[2]		=   "OIL.P";
    RxName[3]		=   "FUEL.P";
    RxName[4]		=   "EXT.T";
    RxName[5]		=   "OIL.T";
    RxName[6]		=   "WATER.T";

/*
	RxName[0]		=   "Boost";
	RxName[1]		=   "Tacho";
	RxName[2]		=   "Oil.P";
	RxName[3]		=   "Fuel.P";
	RxName[4]		=   "ExTmp";
	RxName[5]		=   "Oil.T";
	RxName[6]		=   "Water.T";
*/
    
/*
	RxName[0]	=   "BS";
	RxName[1]	=   "TC";
	RxName[2]	=   "OP";
	RxName[3]	=   "FP";
	RxName[4]	=   "ET";
	RxName[5]	=   "OT";
	RxName[6]	=   "WT";
*/
    
/*
	RxName[0]	=   "Boost";
	RxName[1]	=   "Tacho";
	RxName[2]	=   "Oil press";
	RxName[3]	=   "Fuel press";
	RxName[4]	=   "Ext. Temp.";
	RxName[5]	=   "Oil Temp.";
	RxName[6]	=   "Water Temp.";
*/
    
    // Definition of Resolution for processing and number of space for display
    for(n=0;n<7;n++){
        Resolution[n] = 1;
        for(m=0;m<Nsig[n]-Nint[n];m++){
            Resolution[n] = Resolution[n] / 10;
        }
        RxNameLength[n] = StrLength(RxName[n]);
        Nspace[n]       = DISP_W - RxNameLength[n] - ( Nsig[n] + (Nsig[n]!=Nint[n]) + SIGN[n] );
    }
    
    
	mult_factor[0] = 1;
	mult_factor[1] = 16;
	mult_factor[2] = 256;
    
    
//    delay_cnt = (unsigned long int)( ( WAIT*1.0 ) * ( (1.0*FOSC)/(1.0*Ndiv2) ) / 256.0 / 1000.0 );
    delay_cnt = (unsigned long int)( ( WAIT*1.0 ) * ( (1.0*FOSC)/1000.0/(1.0*Ndiv2) ) / 256.0 );
    
/*
    // opening @ LED array
    for(n=0;n<=8;n++){
        send_bits_595_LED(0x01 << n);
        _delay_ms(60);
    }

    // opening @ LCD
	_delay_ms(50);
	lcd_locate(1,0);
	for(n=0;n<LCD_W;n++){
		lcd_set_char(opening_message0[n]);
		_delay_ms(20);
	}
    lcd_locate(2,0);
    for(n=0;n<LCD_W;n++){
        lcd_set_char(opening_message1[n]);
        _delay_ms(20);
    }
    lcd_locate(3,0);
    for(n=0;n<LCD_W;n++){
        lcd_set_char(opening_message2[n]);
        _delay_ms(20);
    }
    
    // opening @ LED array
    for(n=0;n<=8;n++){
        send_bits_595_LED(~( 0xff << n ));
        _delay_ms(30);
    }
    _delay_ms(250);
    for(n=0;n<=8;n++){
        send_bits_595_LED( 0xff >> n );
        _delay_ms(30);
    }
    _delay_ms(50);
    for(n=0;n<2;n++){
        send_bits_595_LED(0xff);
        _delay_ms(75);
        send_bits_595_LED(0x00);
        _delay_ms(75);
    }
    
    // Clear Opening
	for(m=0;m<4;m++){
		lcd_locate(m,0);
		for(n=0;n<LCD_W;n++){
			lcd_set_char(0x20);
			_delay_ms(15);
		}
	}
*/
    
    // Initialize data display for Defi Link Tap
    for ( index = 0; index < Ndata; index++ ){
        data_updated[index] = 1;
    }
    
    // Enable Interrupt
    sei();

    // Timer Test
    DDRC = 0b00000001;
    PORTC = 0b00000001;
    // Timer Test
    
	////// Main Process start //////
	while(1){
        
        if(lcd_update){
            DisplayItemInfo();
            lcd_locate((chg_index&0x03)>>1,8-(1-chg_index%2));
            lcd_update = 0;
		}

        ////// Measure Process //////
        
        //// Defi Link Tap ////
		for ( index = 0; index < Ndata; index++ ){
			
            if( data_updated[index] == 1 ){
                data_updated[index] = 0;
                
                // Rx data read
                id = t_id[index];
                
                // Judge data validity
                for( n = 1; n < 4; n++ ){
                    if( ( ( (data[index][n] >= '0') & (data[index][n] <= '9') )
                         |( (data[index][n] >= 'A') & (data[index][n] <= 'F') ) ) ){
                        valid_packet[index] = 1;
                    }else{
                        valid_packet[index] = 0;
                        break;
                    }
                }
                // end of judge
                
                if ( valid_packet[index] == 1 ) {
                    // Change char to angle-dec
                    dec_ang = 0;
                    for( n = 1; n < 4; n++){ // data[0] is neglected because of it is control data
                        if  ( (data[index][n] & 0xf0) == 0x30 ){
                            low4bits[n] = (unsigned int)(data[index][n] & 0x0f);
                        }else if ( (data[index][n] & 0xf0) == 0x40 ){
                            low4bits[n] = (unsigned int)(data[index][n] & 0x0f) + 9;
                        }else{
                            break;
                        }
                        dec_ang = dec_ang + low4bits[n] * mult_factor[3-n];
                    }
                    // end of Change char to angle-dec
                    
                    // Change angle-dec to normlized-dec
                    dec_nrm = (float)dec_ang / (float)maxv;
                    // end of Change angle-dec to normlized-dec
                    
                    // Change dec to ISO
                    value[index] = dec_nrm * eq_grad[id] + eq_intercept[id];
                    // end of change dec to ISO
                }

            }
		}
        
        rpm = TachoMeter();
        
/*
        //debug
        if( rpm > 8000 ){
            rpm = 0;
        }else{
            rpm = rpm + 10;
        }
        //debug
*/
        
        // Fuel Pump Driver
        OCR0A = FuelPumpDriver(rpm, value[2],value[3]);
        // value[2] ... Fuel Pressure
        // value[3] ... Boost

        
        ////// Display Process //////
        if(    ( ( (0xffff - timer2_cnt_last) > delay_cnt ) && ( (timer2_cnt - timer2_cnt_last)             > delay_cnt ) )
            || ( ( (0xffff - timer2_cnt_last) < delay_cnt ) && ( (timer2_cnt + (0xffff - timer2_cnt_last))  > delay_cnt ) ) ){

            timer2_cnt_last = timer2_cnt;

            // Timer Test
            PORTC = ~PORTC;
            // Timer Test
            

            //// Defi Link Tap ////
            for ( index = 0; index < Ndata; index++ ){
                
                // Rx data read
                id = t_id[index];

                // clear value area of LCD
                lcd_locate(index,RxNameLength[id]);
                for (n=0;n<=(DISP_W-RxNameLength[id])-1;n++) {
                    lcd_set_char(' ');
                }
                // end of clear value area
                
                // pad blank area of LCD
                lcd_locate(index,RxNameLength[id]);
                for (n=0;n<Nspace[id];n++){
                    lcd_set_char(' ');
                }
                // end of pad blank area of LCD
                
                // display value
                if ( valid_packet[index] == 1 ) {
                    lcd_set_numeric(value[index],Nint[id],Nsig[id]-Nint[id],SIGN[id]);
                }else if( valid_packet[index] == 0 ){
                    for(n=0;n<(Nsig[id]!=Nint[id])+SIGN[id];n++){
                        lcd_set_char(' ');
                    }
                    for(n=0;n<Nsig[id];n++){
                        lcd_set_char('*');
                    }
                }
                // end of display value

            }
            

            // Display Facemark
            lcd_locate(2,13);
            if((unsigned int)rpm < 3000){
                shobon();
            }else if((unsigned int)rpm < 5000){
                shakin();
            }else{
                kuwa();
                lcd_set_str("  ");
            }

 
            // Update Indicator
            lcd_locate(2,12);
            lcd_set_char(0xff);
 
            
        }else{

            // Clear Update Indicator
            lcd_locate(2,12);
            lcd_set_char(' ');
            
        }
        
        //// Real-Time Update items
        

        // Display RPM
        lcd_locate(0,12);
        lcd_set_numeric((unsigned int)rpm,5,0,0);
        lcd_set_str("RPM");
        
        // Display RPM @ Bar Meter
        lcd_locate(3,12);
        BarMeter_disp((unsigned int)rpm);

        
	}

    return 0;
}
Exemplo n.º 8
0
int main(void)
{

    // for 74HC595 port setting for LCD
    SoftSPI_Init();
    
    // for 74HC595 port setting for LED array
    SoftSPI_LED_Init();
    
    // Initialize LCD
	lcd_init();
	
    // Interval Measure
    timer1_init();

    // PWM putput port definition
    DDRD |= (1<<PD6);
    
    // PWM counter init
    timer0_init();
    
	// USART initialize
	USARTinit(UBRR);
	
	// Ext. Interupt setting
	ExtInterrupt_init();
    
    // Bar-Meter Initialize
    BarMeter_init();
    
    // Facemark character Initialize
    FaceMark_init();
    
    // Set Initial Target IDs
    set_initial_t_id();

	// Declarations
	unsigned char*   opening_message0 = "Multi-Function Meter";
    unsigned char*   opening_message1 = " w/ FuelPump Driver ";
    unsigned char*   opening_message2 = "  Firmware  Rev.3   ";
    
	uint8_t         n, m;					// 'for' loop variables
    
    uint8_t        FPDcomp = 0xff;
    
	uint8_t         index = 0;				// LCD displaying data index
	
	uint16_t		maxv = 2352;			// maximum decimal angle data value from 'Defi Link Unit II'
    
	uint8_t         id;						// ID index for processing
    
	uint8_t         valid_packet[Ndata];	// Validtity indicator
	
	uint8_t			low4bits[4];			// Extracted lower 4 bits from byte data
	uint16_t        dec_ang;				// Angle data (decimal)
	float           dec_nrm;				// Angle data (decimal)
	float			value[Ndata];			// Decoded value
	uint8_t         digits_int[5];			// Digits integer data
	unsigned char	digits_char[5];			// Digits character data for display
    
	uint16_t        mult_factor[3];		// Multiplying factor for hexadecimal to decimal decoding
	float           div_factor;				// Dividing factor for integer
	uint8_t         digits_valid;			// Indicate digits in integer are valid or invalid
    
    // value = eq_grad * dec_nrm + eq_intercept
    // Gradient-term of decoding equation
	uint16_t eq_grad[] = {
        3,	// Turbo
        9000,	// Tacho
        10,	// Oil pres.
        6,	// Fuel pres.
        900,	// Ext. Temp.
        100,	// Oil Temp.
        100	// Water Temp.
    };
    
    // Intercept-term of decoding equation
    int16_t eq_intercept[] = {
        -1,	// Turbo
        0,	// Tacho
        0,	// Oil pres.
        0,	// Fuel pres.
        200,	// Ext. Temp.
        50,	// Oil Temp.
        20	// Water Temp.
    };
    
    // Definition of number of significant figure
	uint8_t   Nsig[] = {				// Number of significant figures
        3,	// Turbo
        4,	// Tacho
        3,	// Oil pres.
        3,	// Fuel pres.
        4,	// Ext. Temp.
        3,	// Oil Temp.
        3	// Water Temp.
    };
    
    // Deifinition of number of integer figure
	uint8_t	Nint[] = {				// Number of integr digits
        1,	// Turbo
        4,	// Tacho
        2,	// Oil pres.
        1,	// Fuel pres.
        4,	// Ext. Temp.
        3,	// Oil Temp.
        3	// Water Temp.
    };
    
    uint8_t	SIGN[] = {				// Show +/-, enable showing is '1'
        1,	// Turbo
        0,	// Tacho
        0,	// Oil pres.
        0,	// Fuel pres.
        0,	// Ext. Temp.
        0,	// Oil Temp.
        0	// Water Temp.
    };
    
	uint8_t	Nspace[7];				// Number of space between character and digits
    float   Resolution[7];
    
    RxName[0]		=   "BOOST";
    RxName[1]		=   "TACHO";
    RxName[2]		=   "OIL.P";
    RxName[3]		=   "FUEL.P";
    RxName[4]		=   "EXT.T";
    RxName[5]		=   "OIL.T";
    RxName[6]		=   "WATER.T";

/*
	RxName[0]		=   "Boost";
	RxName[1]		=   "Tacho";
	RxName[2]		=   "Oil.P";
	RxName[3]		=   "Fuel.P";
	RxName[4]		=   "ExTmp";
	RxName[5]		=   "Oil.T";
	RxName[6]		=   "Water.T";
*/
    
/*
	RxName[0]	=   "BS";
	RxName[1]	=   "TC";
	RxName[2]	=   "OP";
	RxName[3]	=   "FP";
	RxName[4]	=   "ET";
	RxName[5]	=   "OT";
	RxName[6]	=   "WT";
*/
    
/*
	RxName[0]	=   "Boost";
	RxName[1]	=   "Tacho";
	RxName[2]	=   "Oil press";
	RxName[3]	=   "Fuel press";
	RxName[4]	=   "Ext. Temp.";
	RxName[5]	=   "Oil Temp.";
	RxName[6]	=   "Water Temp.";
*/
    
    // Definition of Resolution for processing and number of space for display
    for(n=0;n<7;n++){
        Resolution[n] = 1;
        for(m=0;m<Nsig[n]-Nint[n];m++){
            Resolution[n] = Resolution[n] / 10;
        }
        RxNameLength[n] = StrLength(RxName[n]);
        Nspace[n]       = DISP_W - RxNameLength[n] - ( Nsig[n] + (Nsig[n]!=Nint[n]) + SIGN[n] );
    }
    
	mult_factor[0] = 1;
	mult_factor[1] = 16;
	mult_factor[2] = 256;
    for(m=0;m<3;m++){
        for(n=0;n<=m;n++){
            
        }
    }
    
    
    // opening @ LED array
    for(n=0;n<=8;n++){
        send_bits_595_LED(0x01 << n);
        _delay_ms(50);
    }

    // opening @ LCD
	_delay_ms(50);
	lcd_locate(1,0);
	for(n=0;n<LCD_W;n++){
		lcd_set_char(opening_message0[n]);
		_delay_ms(20);
	}
    lcd_locate(2,0);
    for(n=0;n<LCD_W;n++){
        lcd_set_char(opening_message1[n]);
        _delay_ms(20);
    }
    lcd_locate(3,0);
    for(n=0;n<LCD_W;n++){
        lcd_set_char(opening_message2[n]);
        _delay_ms(20);
    }
    
    // opening @ LED array
    for(n=0;n<=8;n++){
        send_bits_595_LED(~( 0xff << n ));
        _delay_ms(30);
    }
    _delay_ms(250);
    for(n=0;n<=8;n++){
        send_bits_595_LED( 0xff >> n );
        _delay_ms(30);
    }
    _delay_ms(50);
    for(n=0;n<2;n++){
        send_bits_595_LED(0xff);
        _delay_ms(75);
        send_bits_595_LED(0x00);
        _delay_ms(75);
    }
    
    // Clear Opening
	for(m=0;m<4;m++){
		lcd_locate(m,0);
		for(n=0;n<LCD_W;n++){
			lcd_set_char(0x20);
			_delay_ms(15);
		}
	}
    
    // Enable Interrupt
    sei();

	// Main function start this
	while(1){

        if(lcd_update){
            DisplayItemInfo();
            lcd_locate((chg_index&0x03)>>1,8-(1-chg_index%2));
            lcd_update = 0;
		}

        
        ////// Measure Sequence //////
        
        //// Defi Link Tap ////
		for ( index = 0; index < Ndata; index++ ){
			
			// Rx data read
			id = t_id[index];
            
			// Judge data validity
			for( n = 1; n < 4; n++ ){
                if( ( ( (data[index][n] >= '0') & (data[index][n] <= '9') )
                     |( (data[index][n] >= 'A') & (data[index][n] <= 'F') ) ) ){
					valid_packet[index] = 1;
				}else{
				 	valid_packet[index] = 0;
		 			break;
				}
			}
			// end of judge
            
			if ( valid_packet[index] == 1 ) {
				// Change char to angle-dec
                dec_ang = 0;
				for( n = 1; n < 4; n++){ // data[0] is neglected because of it is control data
					if  ( (data[index][n] & 0xf0) == 0x30 ){
						low4bits[n] = (unsigned int)(data[index][n] & 0x0f);
					}else if ( (data[index][n] & 0xf0) == 0x40 ){
						low4bits[n] = (unsigned int)(data[index][n] & 0x0f) + 9;
					}else{
						break;
					}
					dec_ang = dec_ang + low4bits[n] * mult_factor[3-n];
				}
				// end of Change char to angle-dec
                
                // Change angle-dec to normlized-dec
                dec_nrm = (float)dec_ang / maxv;
                // end of Change angle-dec to normlized-dec
                
				// Change dec to ISO
				value[index] = dec_nrm * eq_grad[id] + eq_intercept[id];
                // end of change
				
            }
		}
        
        
        // Tacho Meter
            //Median Filter
            for(n=0;n<Nmed;n++){
                proc_array[n] = meas_array[n];
            }
            BubbleSort();
        
            // Calculate frequency
            if(meas_array[tacho_n] >= 0xffff){          // Too Long Gap Pulse
                freq = 0;
            }else{                                      // Last Pulse
                freq = FOSC / Ndiv1 / meas_array[tacho_n];
            }
        
            // Decide measured frequency is valid or invalid
            if( ( freq - freq_cur ) < RPM_DIFF/60.0 ){  // Tracking
                freq_cur = freq;
            }else{                                      // Force Track
                
                // add 2014/11/9
                // 小さいヒゲの分だけ回転数が上がってしまうので、小さいヒゲのカウントをマージ
                cnt = proc_array[Nmed-1];
                for(n=0;n<Nmed-1;n++){
//                    if( proc_array[n] < proc_array[Nmed-1]/20 ){ //3500rpm以上が表示されない
                    if( proc_array[n] < 100 ){
                        cnt = cnt +proc_array[n];
                    }else{
                        break;
                    }
                }
                
//                freq_cur = FOSC / Ndiv1 / proc_array[Nmed>>1]; //debug
                //メディアンフィルタで中央値を取るとノイズを拾う。。。
                
                freq_cur = FOSC / Ndiv1 / cnt;
            }
//        freq_cur = freq;
        
            // Calcurate RPM
            rpm = (unsigned long int)( 60.0 * freq_cur / Npulse );

        
        // Fuel Pump Driver
        if( rpm > 5000 ) FPDcomp = 0xff;
        else FPDcomp = rpm / 5000.0 * 0xff + 0x48;
        OCR0A = FPDcomp;

        
        
        ////// Display sequence //////
        
        //// Defi Link Tap ////
        for ( index = 0; index < Ndata; index++ ){
            
            // Rx data read
            id = t_id[index];

            // clear value area of LCD
            lcd_locate(index,RxNameLength[id]);
            for (n=0;n<=(DISP_W-RxNameLength[id])-1;n++) {
                lcd_set_char(' ');
            }
            // end of clear value
            
            // pad blank area of LCD
            lcd_locate(index,RxNameLength[id]);
            for (n=0;n<Nspace[id];n++){
                lcd_set_char(' ');
            }
            // end of pad blank area of LCD
            
            if ( valid_packet[index] == 1 ) {
                lcd_set_numeric(value[index],Nint[id],Nsig[id]-Nint[id],SIGN[id]);
            }else if( valid_packet[index] == 0 ){
                for(n=0;n<(Nsig[id]!=Nint[id])+SIGN[id];n++){
                    lcd_set_char(' ');
                }
                for(n=0;n<Nsig[id];n++){
                    lcd_set_char('*');
                }
            }

        }
        
        // Display RPM
        lcd_locate(0,12);
        lcd_set_numeric((unsigned int)rpm,5,0,0);
        lcd_set_str("RPM");
        
        // Display Freq
        lcd_locate(1,12);
        if((unsigned int)rpm < 3000){
            shobon();
        }else if((unsigned int)rpm < 5000){
            shakin();
        }else{
            kuwa();
            lcd_set_str("  ");
        }

/*
        // Display Freq
        lcd_locate(1,12);
        lcd_set_numeric((unsigned int)freq,5,0,0);
        lcd_set_str("Hz");
*/
        
/*
        // Display FuelPump Duty
        lcd_locate(2,12);
        lcd_set_str("DUTY ");
        lcd_set_numeric((unsigned int)(FPDcomp*1.0/0xff*100),3,0,0);
*/
        
        //debug
        lcd_locate(2,12);
        lcd_set_str("L");
        lcd_set_numeric((unsigned int)TCNT_LIM,7,0,0);
        
        // Display Bar Meter RPM
        lcd_locate(3,12);
        BarMeter_disp((unsigned int)rpm);

        /*
        // Display Bar Meter FuelPump Duty
        lcd_locate(3,12);
        BarMeter_disp((unsigned int)(FPDcomp*1.0/0xff*100));
        */
        
        LEDarray((unsigned int)rpm);

        // カウントデータデバグ用
/*
        lcd_locate(1,0);
        for(n=0;n<3;n++){
            lcd_set_numeric(proc_array[n+0],4,0,0);
        }
        lcd_locate(2,0);
        for(n=0;n<3;n++){
            lcd_set_numeric(proc_array[n+3],4,0,0);
        }
        lcd_locate(3,0);
        for(n=0;n<3;n++){
            lcd_set_numeric(proc_array[n+6],4,0,0);
        }
*/
        _delay_ms(WAIT);
        
	}

    return 0;
}
Exemplo n.º 9
0
// Set Facemark character
void FaceMark_init(){
    unsigned int code;
    unsigned int addr;
    
    //code 0-5 is used in "BarMeter"
    // "ω"
    code = 6;
    addr = 0;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00000000);
    addr = 1;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00000000);
    addr = 2;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00000000);
    addr = 3;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00000000);
    addr = 4;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00010001);
    addr = 5;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00010101);
    addr = 6;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00010101);
    addr = 7;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00001010);
    
    // "Д"
    code = 7;
    addr = 0;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0x00);
    addr = 1;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0x00);
    addr = 2;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00011100);
    addr = 3;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00010100);
    addr = 4;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00010100);
    addr = 5;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00010010);
    addr = 6;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00011111);
    addr = 7;
    lcd_set_CGRAMaddr(code,addr);
    lcd_set_char(0b00010001);
    
}