예제 #1
0
void initializer()
{
	// Calibrate the oscillator:
    OSCCAL_calibration();   

	// Initialize the USART
	USARTinit();
	
	// set PORTD for output
	DDRD = 0xFF;
	
	// Display instructions on PC
	sendFString(TALKING_TO);
	sendFString(WHO_DEMO);
	
	sendFString(ENTER);
	sendFString(TEXT_CTC);
	
	sendFString(ENTER);
	sendFString(TEXT_SINE);
	sendFString(TO_START);	
	sendFString(TEXT_SINE);
	sendFString(WAVE);

	sendFString(ENTER);
	sendFString(TEXT_SQUARE);
	sendFString(TO_START);	
	sendFString(TEXT_SQUARE);
	sendFString(WAVE);
	
	sendFString(ENTER);
	sendFString(TEXT_SAWTOOTH);
	sendFString(TO_START);	
	sendFString(TEXT_SAWTOOTH);
	sendFString(WAVE);
	
	sendFString(ENTER);
	sendFString(TEXT_TRIANGLE);
	sendFString(TO_START);	
	sendFString(TEXT_TRIANGLE);
	sendFString(WAVE);	
	
	
	MilliSec_init(250); // default to 1000 Hz	
	
	DigitalOscilloscopeTimerInit();

	ADC_init();
	
	startSine();
}
예제 #2
0
파일: demo.c 프로젝트: HoboJ/avr
void initializer ( void )
{
	// Calibrate the oscillator:
    OSCCAL_calibration ();   
	// Initialize the USART
	USARTinit ();
	
	// say hello
	//sendString ( "PC_Comm.c ready to communicate.\r" );   	 
	// identify yourself specifically
	//sendString ( "You are talking to the PC_Comm demo.\r" );

    menu ();
}
예제 #3
0
void initializer()
{
	// Calibrate the oscillator:
    OSCCAL_calibration();   

	// Initialize the USART
	USARTinit();
	
	// initialize the LCD
    LCD_Init();                 
	
	// Display instructions on PC
	sendFString(TALKING_TO);
	sendFString(WHO_DEMO);
	
	LCD_puts_f(LCD_START_msg, 1);

}
예제 #4
0
void initializer()
{
	// Calibrate the oscillator:
    OSCCAL_calibration();   

	// Initialize the USART
	USARTinit();
	
	// Initialize timer0 to play a tune
	Timer0_Init();
	
	// initialize piezo-element
    sbi(DDRB, 5);               // set OC1A as output
    sbi(PORTB, 5);              // set OC1A high	
	
	// Display instructions on PC
	sendFString(TALKING_TO);
	sendFString(WHO_DEMO);
	sendFString(ENTER);
	sendFString(TEXT_FUR_ELISE);
	sendFString(ENTER);	
	sendFString(TEXT_TURKEY_MARCH);	
	sendFString(ENTER);	
	sendFString(TEXT_MINUET);	
	sendFString(ENTER);	
	sendFString(TEXT_AULD_LANG_SYNE);	
	sendFString(ENTER);	
	sendFString(TEXT_SIRENE1);	
	sendFString(ENTER);	
	sendFString(TEXT_SIRENE2);	
	sendFString(ENTER);	
	sendFString(TEXT_WHISTLE);	
	sendFString(ENTER);	
	sendFString(VOLUME_UP);	
	sendFString(THE_VOLUME);
	sendFString(ENTER);	
	sendFString(VOLUME_DOWN);	
	sendFString(THE_VOLUME);
	sendFString(ENTER);	
	sendFString(STOP);		


}
예제 #5
0
void initializer()
{
	// Calibrate the oscillator:
    OSCCAL_calibration();   

	// Initialize the USART
	USARTinit();
	
	// set PORTD for output
	DDRD = 0xFF;
	
	MilliSec_init(250); // default to 1000 Hz

	
	// say hello
	sendString("\rPC_Comm.c ready to communicate.\r");   	 
	// identify yourself specifically
	sendString("You are talking to the Precision Blinking demo.\r");

}
예제 #6
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;
}
예제 #7
0
void main(void)
{
    OSCCON = 0b01100001;  //4 MHz
    OSCTUNE= 0;
    //INTCON = 0;
    //Count1micros = 0;
    Count4ms = 0;
    //Delay(2);
    initports();
    USARTinit();
//USARTWriteString("Serial init\n\rchecking for config enable...\n\r");
    while(SERIALDETECT == 1)
    {
        //USARTWriteString("\n\rEnter Config\n\r");USARTWriteString(strnw);
        //USARTWriteString("\n\rEnter ");
        getData();
    }
    ENB = 0;
    nSLEEP = 1;
    DECAY = 1;
    initall();
    int i;
    for( i = 0 ; i < 4 ; i++)
    {
        CurTotNoStep = 270; CurStepDir = ANTICLKVIZ; CurStepMode = MIC32STEP ;

        Make_Table( CurTotNoStep );
        while(!MotionComplete);
    }

    while(Crankflg == 0)
    {
        get_Actrpm();
        Calc_SetPoint();
        USARTWriteChar('N');USARTWriteString(strnw);
    }

    for( i = 0 ; i < 4 ; i++)
    {
        CurTotNoStep = 225; CurStepDir = CLKVIZ; //CurStepMode = MIC32STEP ;
        Make_Table( CurTotNoStep );
        while(!MotionComplete);
    }
        //MoveMotor();
    while(1)
    {
        if(MS100Flag)
        {
            MS100Flag = 0;
            Calc_Err(PIDCycleNo);
            
            if((PIDCycleNo >= 2) /*&& Crankflg*/ )
            {
                Calc_PID_op();
            }//USARTWriteString("100 ms done \n\r");
            /*else
            {
                USARTWriteChar('N');USARTWriteString(strnw);
                //USARTWriteString("no crank\n\r");
            }*/
        }
    }
}
예제 #8
0
파일: main.c 프로젝트: sdeodhar/RPi
void main(void)
{
    int8u dec_key;

    OSCTUNE = 0;
    OSCCON = 0b01100011;//0b01110011;
    //TRISA = 0b11000001;
    //TRISE = 0;
    //TRISC = 0b0111;

    TRISA=0b11000001;
    //TRISAbits.RA6=1;
    //TRISAbits.RA7=1;
    TRISC=0b0111;
    TRISE=0b000000000;
    TRISB7=0;    TRISD3=0;
    TRISD2=0;    TRISD1=0;
    TRISD0=1;    TRISB0=0;
    TRISB1=0;    TRISD4=0;
    TRISD5=0;    TRISD6=0;      TRISD7=0;

    USARTinit();
    lcd_init();
    Initcustom_char();
    cur_gain = 0.25;
    /*strncpy( Lcd_LINE1 , Lcd_L1 , 16 ) ;
    strncpy( Lcd_LINE2 , Lcd_L2 , 16 ) ;
    Display();
    strncpy( Lcd_LINE1 , Lcd_L3 , 16 ) ;
    strncpy( Lcd_LINE2 , Lcd_L4 , 16 ) ;
    Display();*/

    //while(1);
    Adc_init();
    Init_i2c();
    Init_stat_isr();
    Init_PWM();
    dutyvolt = 0; dutycurrent = 0;
    Set_PWM_Duty();
    /*while(1)
    {
        Display();
        USARTWriteChar('U');
        USARTWriteString(" Hi All\n\r");
        dec_key = getkey();dispnum( dec_key  ,1,2);
        Get_ADC_Count();   dispnum( ADC_Count,5,7);
        DelayMs(1000);
    }*/

    FFT_ready_flag = 0;
    while(1)
    {
        if(FFT_ready_flag)
        {
            INT0IE = 0;

            Read_FFT(0,128);
            FFT_ready_flag = 0;

            Calc_percentageFull();
            Disp_Mill_fill();

            INT0IE = 1;
        }
    }
}
예제 #9
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;
}
예제 #10
0
파일: main.c 프로젝트: u60/cube-o-mania
int main()
{
	volatile signed int i, aColumn, aLevel, mask, mux, patterncntr;

	patterncntr = 0;
	Hold = 0;

	InitPorts();
	CARDinit();
	USARTinit();

	while (1) 
	{
	
		while (patterncntr < numanimas)
		{
			X = 0;
			eX = 0;
			XChanged = 0;
			dX = pgm_read_byte(&AnimationA[patterncntr].hold);
			fademode = pgm_read_byte(&AnimationA[patterncntr].fade);

			for (i = 0; i < MaxLedPins; i++)
			{	
				eY[i] = 0;
				/*
				aDivRes = div(i, LedPinsPerLevel);
				aLevel = aDivRes.quot;
				aLedPin = i;
				aLedPin %= LedPinsPerLevel;
				*/
			  	YStart = pgm_read_byte(&AnimationA[patterncntr].pwm[i]);
				PWM[i] = YStart;
				if (patterncntr < numanimas-1) idx = patterncntr+1; else idx = 0;
				YEnd = pgm_read_byte(&AnimationA[idx].pwm[i]);
				dY[i] = YEnd-YStart;		 
			}
			Hold = 0;

			while (Hold <= pgm_read_byte(&AnimationA[patterncntr].hold))
			{
				
				if (fademode > 0) fade();

				for (i=0; i<=PWMres; i++)
				{	
					
					CARDloop();
					USARTloop();
					
					mux = MaxMux;
					while (mux > 0)
					{
						mux--;
						for (aColumn = LedPinsPerColumn-1; aColumn >= 0; aColumn--)
						{	
							mask = 0;
							aLevel = MaxLevels;
							while (aLevel > 0)
							{	
								aLevel--;
								idx = aColumn+mux * LedPinsPerColumn + aLevel * LedPinsPerLevel;
								if (i < PWM[idx]) mask |= (1 << aLevel);
							}
							SetLevelPins(mask);
			
						}
						switch (mux)
						{
							case 0 :
							   SetLevelPins(15);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   break;
							case 1 :
							   SetLevelPins(0);
							   SetLevelPins(15);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   break;
							case 2 :
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(15);
							   SetLevelPins(0);
							   break;
							case 3 :
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(15);
							   break;
						}
						i = i;	
						Latch();
					}		
				}
			if (fademode == 0)	Hold++;	
			} 
			Hold = 0;
			patterncntr++;	
		}
		patterncntr = 0;
	}
}