Ejemplo n.º 1
0
void mars_power_led_off(struct mars_brick *brick, bool val)
{
	bool oldval = brick->power.led_off;
	if (val != oldval) {
		//MARS_DBG("brick '%s' type '%s' led_off %d -> %d\n", brick->brick_path, brick->type->type_name, oldval, val);
		set_led_off(&brick->power, val);
		mars_trigger();
	}
}
Ejemplo n.º 2
0
/* decrease the number of active LEDs */
void decrement_leds(void) {
	if (n_of_leds == 1) set_led_off(LED0);
	else if (n_of_leds == 2) set_led_off(LED1);
	else if (n_of_leds == 3) set_led_off(LED2);
	else if (n_of_leds == 4) set_led_off(LED3);
	else if (n_of_leds == 5) set_led_off(LED4);
	else if (n_of_leds == 6) set_led_off(LED5);
	else if (n_of_leds == 7) set_led_off(LED6);
	else if (n_of_leds == 8) set_led_off(LED7);
	if (n_of_leds > 0) n_of_leds--;
}
Ejemplo n.º 3
0
void set_led_color_on( int r, int g, int b, bool on)
{
    usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,RGB_R, r, 0, buffer, sizeof(buffer), 5000);
    usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,RGB_G, g, 0, buffer, sizeof(buffer), 5000);
    usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,RGB_B, b, 0, buffer, sizeof(buffer), 5000);
    usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,SET, 0, 0, buffer, sizeof(buffer), 5000);
    if( on)
        set_led_on();
    else
        set_led_off();
}
Ejemplo n.º 4
0
/******************************************************************************
 *                                 Local Functions                            *
 ******************************************************************************/
etos_isr_ret_e module_timer_isr_idic(u32 current_tick, void *arg)
{
    etos_isr_ret_e ret = ETOS_ISR_RESCHEDULE_DISABLE;
    u32 timer_no = (u32)arg;
    u32 *sp_addr = g_os_boot_sp;

    current_tick = current_tick;

    _timer_intr_cnt++;

    switch (timer_no) {
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
#if 0
            if ((_timer_intr_cnt % 256) == 0) {
                xlogt(LOG_MODULE_DRV, "INTR: timer tick: (256 tick ~= 4s) 0x%x curr=%d\r\n", os_get_cpu_intr_enabled(),
                      etos_sched_get_tick());
            }
#else
            if ((_timer_intr_cnt % 10) == 0) {
                //xlogt(LOG_MODULE_DRV, "INTR: timer tick: intr:0x%x curr=%d\r\n", os_get_cpu_intr_enabled(), etos_sched_get_tick());
                _timer_intr_flag ^= 1;
                if (_timer_intr_flag) {
                    set_led_on(2);
                } else {
                    set_led_off(2);
                }
            }
#endif
            ret = ETOS_ISR_RESCHEDULE_UPDATE_TICK | ETOS_ISR_RESCHEDULE_ENABLE;
            break;
        default:
            break;
    }

    return ret;
}
Ejemplo n.º 5
0
void loop(void)

{

		
	//if throttle is lower than throttle_low - or is over 100 beyond throttle_high -  bot stays powered down 
	
	sei();  //enable interrupts 


	while ( throttle < throttle_low || throttle > (throttle_high + 100))
	{


		motors_off();

		//interrupt blinking if stick isn't centered (helps to verify TX is working)
		if ( leftright > heading_leftthresh ) _delay_ms(200);
		if ( leftright < heading_rightthresh ) _delay_ms(200);

		//sit there and flash LED
		
		toggle_led();
		_delay_ms(50);		


	}




	cli();                //disable interrupts - bad things seem to happen if the RC interrupts get triggered while doing math...

	//Are we going forward or backwards?
	if ( forwardback > forwardback_forwardthresh) forward = 1; else forward = 0;
	if ( forwardback < forwardback_backthresh) backward = 1; else backward = 0;

	flashy_led = 0;

	accel_raw_data = read_adc();               //get accel data 
	accel_read = accel_raw_data;                              //move it over to single in case we want to do floating point
	accel_read = accel_read - base_accel;                     //compensate for base (2.5v) level
	g = accel_read * g_per_adc_increment;                    //convert to g's

	rpm = g * 89445;                                //calculate RPM from g's - derived from "G = 0.00001118 * r * RPM^2"

	rpm = rpm / radius;

	rpm = pow(rpm, .5);
	
	
	periodms = rpm / 60;                                      //convert RPM to duration of each spin in milliseconds
		
	if (periodms == 0) periodms = 1;                          //must prevent any possible division by zero!!!
	periodms = 1 / periodms;
	periodms = periodms * 1000;

	periodms = periodms * tracking_comp;                      //compensate with user-set tracking adjustment


	alternate_motor_cycle = !alternate_motor_cycle;     //alternates alternate_motor_cycle - used to balance spin

  
	if ( forward == 1 ) periodms = periodms * forward_comp;   //extra compensation if going forward
	if ( backward == 1 ) periodms = periodms * backward_comp; //extra compensation if going backward


	
	total_fudge_factor = fudge_factor + (fudge_factor_per_ms * periodms);
	periodms = periodms - total_fudge_factor;                       					   //compensate for time spent doing reads / calculations
	

	delaytime_single = periodms / 2;                          //sets period in MS for each half of spin

	//converts throttle reading from remote into percentage (400 = low, 560 = high)
	throttle_percent = (throttle - throttle_low) + 40;    //this gives a range from about 20% to 100%
	throttle_percent = throttle_percent / 2;
	if ( throttle_percent > 100 ) throttle_percent = 100;    //don't got over 100%



	//calculates + modifies changes to heading based on input from transmitter
	steering_multiplier = heading_center - leftright;
	steering_multiplier = steering_multiplier * turn_speed;
	steering_multiplier = 1 - steering_multiplier;		//starts with 1 as a base value (ie - if it was 0.0 it becomes 1.0 - so there's no change in heading)
	delaytime_single = delaytime_single * steering_multiplier;
	
	
	delaytime_long = delaytime_single;

	digitdif = delaytime_single - delaytime_long;


	//code that waits X microseconds to compensate for integer math
	digitdif = digitdif  * 10;                                 //converts digit dif to 50's of microseconds


	//caps on timing if going too slow or fast
	if ( delaytime_long > 500) delaytime_long = 500;
	if ( delaytime_long < 5) delaytime_long = 5;

	periodms = delaytime_long * 2;                           //we re-use periodms (full cycle length) for LED calculations - so it needs to be updated with any timing adjustments
	periodms_long = periodms;

	//set heading beacon size and location

	led_on = periodms * led_adjust;
	led_on = led_on / 100;
	led_off = periodms / 3;                                  //led signal is 33% of circle
	led_off = led_off + led_on;


	if (led_off >= periodms_long ) //if led_off is "later" or at end of cycle - shift led_off behind by one cycle
	{                        
		led_off = led_off - periodms_long;
	}

	if ( led_off < 1 ) led_off = led_off + periodms_long;

	if ( g > max_g && throttle_percent > 20 ) throttle_percent = 20;       //if we're over max RPM for translation - reduce throttle

	//throttling

	full_power_spin = 0;
	if ( rpm < min_rpm ) full_power_spin = 1;                //if we're under the minimum RPM for translation - do the full power spin!
	if ( rpm > max_allowed_rpm ) throttle_percent = 6;       //if we're over max RPM for translation - reduce power
	
	
	//if throttle is at or over 50% throttle - adjust time spent in braking
	if ( throttle_percent > 50 )
	{                          

		flashy_led = 1;                                        //flash the LED to indicate we're in fast mode

		braking_length = delaytime_long * 25;                  
		braking_length = braking_length / throttle_percent;    

		begin_brake = delaytime_long / 2;
		begin_brake = begin_brake - braking_length;

		end_brake = delaytime_long / 2;
		end_brake = end_brake + braking_length;
	
		if ( begin_brake < 1 )	begin_brake = 1;               //make sure begin_brake isn't getting set to 0
			
		power_kill_part1 = 0;                                  //power_kill not used if throttle over 50%
		power_kill_part2 = delaytime_long;

	}


	if ( throttle_percent <= 50 )                           //if throttle under 50% - kill the motors for a portion of each spin
	{
		begin_brake = 1;
		end_brake = delaytime_long;

		power_kill_length = 50 - throttle_percent;           //set time in each cycle to cut power (throttling)
		power_kill_length = power_kill_length * delaytime_long;
		power_kill_length = power_kill_length / 150;

		power_kill_part1 = power_kill_length;
		power_kill_part2 = delaytime_long - power_kill_length;

	}


	if ( full_power_spin == 1 )      //if we're actually doing full power this spin (no translation) - ignore any calculations / reset variables
	{
		end_brake = 1;
		begin_brake = 0;

		power_kill_part1 = 0;
		power_kill_part2 = delaytime_long;
	}


	sei();  //enable interrupts - out of all the critical stuff

	led_ref = 0;

	//Do translational drift driving

	//Cycle 1 ("front" 180 degrees of spin)

	for (x = 1; x <= delaytime_long; x++)
	{

		motors_left();                                        //start off under full power

		led_ref = led_ref + 1;

		if ( x >= begin_brake && x < end_brake )         //switch to single motor as soon as entering braking cycle
		{
			//if sitting still
			if ( forward == 0 && backward == 0 )
			{
				if ( alternate_motor_cycle == 0 ) motor1_on();  //alternates which motor is used each cycle if ( sitting still
				if ( alternate_motor_cycle == 1 ) motor2_on();  //this prevents unwanted "translation" due to any imbalances
			}

			//if ( going forward / back set motors appropriately (this is "where it happens")
			if ( forward == 1 ) motor1_on();
			if ( backward == 1 ) motor2_on();
		}

		if ( x >= end_brake ) motors_left();                 //if we hit end of brake cycle - go to full power

		if ( x < power_kill_part1 ) motors_off();            //if th rottle is less that 100% - kill power at appropriate time
		if ( x > power_kill_part2 ) motors_off();            //if throttle is less that 100% - kill power at appropriate time

		if ( led_ref == led_on ) led_is_on_now = 1;         //turn on heading led
		if ( led_ref == led_off ) led_is_on_now = 0;        //turn off heading led

		
		if ( led_is_on_now == 1 )
		{
			//flash the LED if we're in flashy mode - otherwise it's just on
			if ( flashy_led == 1 ) toggle_led(); else set_led_on();
		}

		if ( led_is_on_now == 0 ) set_led_off();

		_delay_ms(1);

	}

	for (delay_loop = 1; delay_loop <  digitdif; delay_loop++)
	{                           
		//in theory we should wait 25 microseconds - but I'm assuming the overhead takes up 1us
		wait24us();                                             
	}

  
	//Cycle 2 (back 180 degrees of spin) - same as above except motors are reversed (there are some moderately-good reasons this isn't a subroutine)


	for (x = 1; x <= delaytime_long; x++)
	{

		motors_left();                                        //start off under full power

		led_ref = led_ref + 1;

		if ( x >= begin_brake && x < end_brake )         //switch to single motor as soon as entering braking cycle
		{
			//if sitting still
			if ( forward == 0 && backward == 0 )
			{
				if ( alternate_motor_cycle == 0 ) motor2_on();  //alternates which motor is used each cycle if ( sitting still
				if ( alternate_motor_cycle == 1 ) motor1_on();  //this prevents unwanted "translation" due to any imbalances
			}

			//if ( going forward / back set motors appropriately (this is "where it happens")
			if ( forward == 1 ) motor2_on();
			if ( backward == 1 ) motor1_on();
		}

		if ( x >= end_brake ) motors_left();                //if we hit end of brake cycle - go to full power

		if ( x < power_kill_part1 ) motors_off();           //if throttle is less that 100% - kill power at appropriate time
		if ( x > power_kill_part2 ) motors_off();           //if throttle is less that 100% - kill power at appropriate time

		if ( led_ref == led_on ) led_is_on_now = 1;         //turn on heading led
		if ( led_ref == led_off ) led_is_on_now = 0;        //turn off heading led

		
		if ( led_is_on_now == 1 )
		{
			//flash the LED if we're in flashy mode - otherwise it's just on
			if ( flashy_led == 1 ) toggle_led(); else set_led_on();
		}

		if ( led_is_on_now == 0 ) set_led_off();

		_delay_ms(1);


	}

	for (delay_loop = 1; delay_loop <  digitdif; delay_loop++)
	{                           
		//in theory we should wait 25 microseconds - but I'm assuming the overhead takes up 1us
		wait24us();                                             
	}
	
	

}
Ejemplo n.º 6
0
void main(void)
{
// Declare your local variables here
bit flag_start_pause1,flag_start_pause2,f_m1,key_enter_press_switch1;
char min_r,min_n;
float time_pause1,time_pause2,adc_value1,adc_value3;
float data_register,k_f,adc_filter,adc_value2;


if      (MCUCSR & 0x01){/* Power-on Reset */MCUCSR&=0xE0;}
else if (MCUCSR & 0x02){/* External Reset */MCUCSR&=0xE0;}
else if (MCUCSR & 0x04){/* Brown-Out Reset*/MCUCSR&=0xE0;}
else if (MCUCSR & 0x08){/* Watchdog Reset */MCUCSR&=0xE0;}
else if (MCUCSR & 0x10){/* JTAG Reset     */MCUCSR&=0xE0;};

PORTA=0b11111111;DDRA=0b11111111;
PORTB=0b00000000;DDRB=0b10110011;
PORTC=0b11111000;DDRC=0b11111011;
PORTD=0b11110000;DDRD=0b00001000;

TCCR0=0x02;TCNT0=TCNT0_reload;OCR0=0x00;

TCCR1A=0x00;TCCR1B=0x05;TCNT1H=0x00;TCNT1L=0x01;
ICR1H=0x00;ICR1L=0x04;OCR1AH=0x00;OCR1AL=0x02;
OCR1BH=0x00;OCR1BL=0x03;

ASSR=0x00;TCCR2=0x03;TCNT2=TCNT2_reload;OCR2=0x00;

MCUCR=0x00;MCUCSR=0x00;TIMSK=0xFF;

UCSRA=0x00;UCSRB=0xD8;UCSRC=0x86;UBRRH=0x00;UBRRL=0x33;
ACSR=0x80;SFIOR=0x00;SPCR=0x52;SPSR=0x00;WDTCR=0x1F;WDTCR=0x0F;

// test:
// for (i=1;i<30;i++)
//         {
//         ee_float=&(reg[i]);
//         *ee_float=FAKTORY[i];//проверка граничных значений
//         }
// 
goto a1;

//Ожидание включения питания 
ee_float=&(reg[18]);
k_f=*ee_float;
if ((k_f>MAX_MIN[18,1])||(k_f<MAX_MIN[18,0])) k_f=FAKTORY[18];//проверка граничных значений
k_f=*ee_float;
k=k_f;i=0;
while (i<k)
        {
        if ((key_1==0)&&(key_4==0)&&(key_2==1)&&(key_3==1)) i++;
        else i=0;
        delay_ms(1000);
        }
power=1;

#asm("sei")
//Показать основные настройки
for (i=7;i<MAX_REGISTER;i++)
        {
        hex2dec(i-6);
        set_digit_on('a','_',des,ed);
        set_digit_off('a','_',des,ed);
        set_led_on(0,0,0,1,0,0,0,0);
        set_led_off(0,0,0,1,0,0,0,0);
        delay_ms(700);
        ee_float=&(reg[i]);
        k_f=*ee_float;
        if ((k_f>MAX_MIN[i,1])||(k_f<MAX_MIN[i,0])) *ee_float=FAKTORY[i];//проверка граничных значений
        k_f=*ee_float;
        if ((i==14)||(i==13)||(i==14)||(i==21)||(i==22))
                {
                k_f=k_f*100;
                set_led_on(0,0,0,1,0,1,0,0);
                set_led_off(0,0,0,1,0,1,0,0);
                }
        else 
                {
                set_led_on(0,0,0,1,0,0,0,0);
                set_led_off(0,0,0,1,0,0,0,0);
                }
        
        hex2dec(k_f);
        set_digit_on(tis,sot,des,ed);
        set_digit_off(tis,sot,des,ed);
        delay_ms(700);
        }
a1:

key_mode_press=0;
key_plus_press=0;
key_mines_press=0;
key_enter_press=0;
key_mode_press_switch=0;
key_plus_press_switch=0;
key_minus_press_switch=0;

#asm("sei")
mode=0;
x=0;
start_time=sys_time;
while (1)
        {
        if (read_reg(6)==0)buzer_buzer_en=0;
        else buzer_buzer_en=1;
        #asm("wdr");
        //измерение
        if (++buf_end>8) buf_end=0;buf[buf_end]=read_adc();min_r=9;
        //модальный фильтр
        for (j=0;j<9;j++)
                {
                rang[j]=0;
                for (i=0;i<9;i++)
                        {
                        if (i!=j)
                                {
                                if (buf[j]<buf[i]) rang[j]--;
                                if (buf[j]>buf[i]) rang[j]++;
                                }
                        }
                if (cabs(rang[j])<min_r) {min_r=cabs(rang[j]);min_n=j;}
                }
        //ФНЧ
        ee_float=&(reg[17]);
        k_f=*ee_float;
        if (k_f==0)
                {adc_filter=buf[min_n];}
        else
                {
                k_f=0.002/k_f;
                adc_filter=k_f*buf[min_n]+(1-k_f)*adc_filter;
                }
        
        //первичное преобразование
//         ee_float=&kal[0];
//         adc_value1=adc_filter+*ee_float;
//         ee_float=&kal[1];
//         adc_value1=adc_value1*(*ee_float);

        adc_value1=adc_filter*1.006/100;

        //вторичное преобразование//???????????????????????????????
        k_f=(read_reg(22)-read_reg(21))/(read_reg(14)-read_reg(13));
        adc_value2=read_reg(21)-k_f*read_reg(13)+adc_value1*k_f;
//        adc_value2=adc_value1adc_filter/100;
                
        //авария
        if (adc_value2<(read_reg(13)*(1-read_reg(15)/100))) {avaria=1;}
        else if (adc_value2>(read_reg(14)*(1+read_reg(16)/100))) {avaria=1;}
        else avaria=0;





        //уставка 1,2
        ee_float=&(reg[7]);k_f=*ee_float;//гистерезис
        ee_float=&(reg[1]);
        if (adc_value2>((*ee_float)*(1+k_f/100))) {alarm1=1;}//set_led_alarm1_on(1);//}
        else {alarm1=0;alarm_alarm1=0;flag_start_pause1=0;}//set_led_alarm1_on(0);//}
        ee_float=&(reg[2]);
        if (adc_value2>((*ee_float)*(1+k_f/100))) {alarm2=1;}//set_led_alarm2_on(1);//}
        else {alarm2=0;flag_start_pause2=0;}//set_led_alarm2_on(0);//}





        //пауза 1,2
        if (alarm_alarm1==1){relay_alarm1=1;}
        else relay_alarm1=0;
        if (alarm_alarm2==1){relay_alarm2=1;}
        else relay_alarm2=0;

        
        if ((flag_start_pause1==1))//&&(alarm_alarm1==0))
                {
                if ((sys_time-time_pause1)>(read_reg(3)*2000)){alarm_alarm1=1;}
                }
        else if (alarm1==1)
                {
                time_pause1=sys_time;
                flag_start_pause1=1;
                }
        if ((flag_start_pause2==1))//&&(alarm_alarm2==0))
                {
                if ((sys_time-time_pause2)>(read_reg(4)*2000))alarm_alarm2=1;
                }
        else if (alarm2==1)
                {
                time_pause2=sys_time;
                flag_start_pause2=1;
                }












        //возврат из меню
        if (((sys_time-start_time_mode)>read_reg(20)*2000)){mode=0;f_m1=0;}

        if ((key_enter_press_switch==1)&&(mode==0)){key_enter_press_switch=0;key_enter_press_switch1=1;}
        if ((key_enter_press_switch1==1)&&(key_enter==1))
                {
                if ((sys_time-whait_time)>3000)
                        {
                        mode=10;start_time_mode=sys_time;key_enter_press_switch1=0;
                        }
                }

        //МЕНЮ
        if (mode==0)
                {
                if (alarm_alarm2==0)
                        {

                        if (read_reg(12)==0)adc_value3=adc_value1;
                        else adc_value3=adc_value2;
                        }
                else
                        {
                        if (read_reg(12)==0)adc_value3=adc_value1;
                        else adc_value3=adc_value2;
                        }

                
                hex2dec(adc_value3*100);
                }
                
        if (mode==1)//уставка №1
                {
                set_led_on(0,0,1,1,0,0,0,0);//светодиод предупр.,норма 
                set_led_off(0,0,0,1,0,0,0,0);//светодиод норма

                if ((((sys_time-start_time_mode)<read_reg(19)*2000))&&(f_m1==0))//пока время индикации наименования
                        {
                        tis='У';sot='_';des=1;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        set_led_on(0,0,1,1,0,1,0,0);//светодиод предупр.,норма, запятая 2
                        count_register=1;
                        hex2dec(data_register*100);
                        f_m1=1;
                        }
                }
        if (mode==2)//уставка №2
                {
                set_led_on(0,1,0,1,0,0,0,0);//светодиод аварийн.,норма
                set_led_off(0,0,0,1,0,0,0,0);//светодиод норма

                if ((((sys_time-start_time_mode)<read_reg(19)*2000))&&(f_m1==0))//пока время индикации наименования
                        {
                        tis='У';sot='_';des=2;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        set_led_on(0,1,0,1,0,1,0,0);//светодиод аварийн.,норма, запятая 2
                        count_register=2;
                        hex2dec(data_register*100);
                        f_m1=1;
                        }
                }
        if (mode==3)//время до уставки 1
                {
                set_led_on(0,0,1,1,0,0,0,0);//светодиод предупр.,норма, запятая 2
                set_led_off(0,0,0,1,0,0,0,0);//светодиод норма
                if ((((sys_time-start_time_mode)<read_reg(19)*2000))&&(f_m1==0))//пока время индикации наименования
                        {
                        tis=3;sot='_';des=1;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        count_register=3;
                        hex2dec(data_register);
                        f_m1=1;
                        }
                }
        if (mode==4)//время до уставки 2
                {
                set_led_on(0,1,0,1,0,0,0,0);//светодиод аварийн.,норма, запятая 2
                set_led_off(0,0,0,1,0,0,0,0);//светодиод норма
                if ((((sys_time-start_time_mode)<read_reg(19)*2000))&&(f_m1==0))//пока время индикации наименования
                        {
                        tis=3;sot='_';des=2;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        count_register=4;
                        hex2dec(data_register);
                        f_m1=1;
                        }
                }
        if (mode==5)//режим маскирование
                {
                set_led_on(0,1,1,1,0,0,0,0);//светодиод аварийн.,предупр.,норма
                set_led_off(0,0,0,1,0,0,0,0);//светодиод норма
                if ((((sys_time-start_time_mode)<read_reg(19)*2000))&&(f_m1==0))//пока время индикации наименования
                        {
                        tis=6;sot='_';des='_';ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        count_register=5;
                        hex2dec(data_register);
                        f_m1=1;
                        }
                }

        if (mode==6)//режим маскирование
                {
                set_led_on(0,1,1,1,0,0,0,0);//светодиод аварийн.,предупр.,норма
                set_led_off(0,0,0,1,0,0,0,0);//светодиод норма
                if ((((sys_time-start_time_mode)<read_reg(19)*2000))&&(f_m1==0))//пока время индикации наименования
                        {
                        tis='c';sot='_';des='_';ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        count_register=6;
                        hex2dec(data_register);
                        f_m1=1;
                        }
                }
//----------------------------------------------------------
        if (mode==10)
                {
                if (count_register<7) count_register=7;
                hex2dec(count_register-6);
                if (des==0) des='_';
                tis='a';sot='_';
                set_digit_off(' ',' ',' ',' ');
                set_led_on(0,0,1,1,0,0,0,0);
                set_led_off(0,0,0,1,0,0,0,0);
                }

        if (mode==11)
                {
                if ((count_register==14)||(count_register==13)||(count_register==14)||(count_register==21)||(count_register==22))
                        {
                        hex2dec(data_register*100);
                        set_led_on(0,0,1,1,0,1,0,0);
                        set_led_off(0,0,0,1,0,1,0,0);
                        }
                else 
                        {
                        hex2dec(data_register);
                        set_led_on(0,0,1,1,0,0,0,0);
                        set_led_off(0,0,0,1,0,0,0,0);
                        }
                }
        
        
        if (key_plus_press==1)
                {
                start_time_mode=sys_time;
                if (count_key==0){if (mode==10)if (++count_register>MAX_REGISTER)count_register=MAX_REGISTER;}
                if ((count_key==0)||(count_key==21)||(count_key1==102))
                        {
                        if ((mode==11)||(mode==3)||(mode==4)||(mode==5)||(mode==6))
                                {
                                if ((count_register==13)||(count_register==14)||(count_register==21)||(count_register==22))data_register=data_register+0.01;
                                else data_register=data_register+1;
                                if (data_register>MAX_MIN[count_register,1])data_register=MAX_MIN[count_register,1];
                                }
                        if ((mode==1)||(mode==2))
                                {
                                data_register=data_register+0.01;
                                if (data_register>MAX_MIN[count_register,1])data_register=MAX_MIN[count_register,1];
                                }
                        if (count_key==0)count_key=60;if (count_key==21)count_key=20;
                        }
                rekey();
                }
        else if ((mode!=100)&&(key_enter_press==0)&&(key_mines_press==0)){count_key=0;count_key1=0;count_key2=0;}

        if (key_mines_press==1)
                {
                start_time_mode=sys_time;
                if (count_key==0){if (mode==10)if (--count_register<7)count_register=7;}
                if ((count_key==0)||(count_key==21)||(count_key1==102))
                        {
                        if ((mode==11)||(mode==3)||(mode==4)||(mode==5)||(mode==6))
                             {
                             if ((count_register==13)||(count_register==14)||(count_register==21)||(count_register==22))data_register=data_register-0.01;
                             else data_register=data_register-1;
                             if (data_register<MAX_MIN[count_register,0])data_register=MAX_MIN[count_register,0];
                             }
                        if ((mode==1)||(mode==2))
                                {
                                data_register=data_register-0.01;
                                if (data_register<MAX_MIN[count_register,0])data_register=MAX_MIN[count_register,0];
                                }
                        if (count_key==0)count_key=60;if (count_key==21)count_key=20;
                        }
                rekey();
                }
        else if ((mode!=100)&&(key_enter_press==0)&&(key_plus_press==0)){count_key=0;count_key1=0;count_key2=0;}

        if ((key_enter_press_switch==1)&&(key_plus_press==0)&&(key_mines_press==0)&&(key_mode_press==0)&&(mode!=0)&&(mode!=10))
                {
                ee_float=&reg[count_register];
                *ee_float=data_register;
                start_time_mode=sys_time;
                if (count_register==21)
                        {
                        ee_float=&kal[0];
                        *ee_float=adc_filter;
                        }
                if (count_register==22)
                        {
                        ee_float=&kal[0];
                        k_f=*ee_float;
                        ee_float=&kal[1];
                        *ee_float=20/(adc_filter-k_f);
                        }
                if (count_register==30)
                        {
                        for (i=0;i<30;i++)
                                {
                                ee_float=&reg[i];
                                *ee_float=FAKTORY[i];
                                }
                        }
                set_digit_on(' ',3,'a','п');
                set_digit_off(' ',3,'a','п');
                set_led_on(0,0,0,1,0,0,0,0);
                set_led_off(0,0,0,1,0,0,0,0);
                delay_ms(3000);key_enter_press_switch=0;
                set_digit_off(' ',' ',' ',' ');
                start_time_mode=sys_time;start_time=sys_time;
                f_m1=0;
                }
        if ((key_mode_press_switch==1)&&(key_4==1))
                {
                key_mode_press_switch=0;f_m1=0;
                start_time_mode=sys_time;
                switch (mode)
                        {
                        case 0: mode=1;data_register=read_reg(1);break;
                        case 1: mode=2;data_register=read_reg(2);break;
                        case 2: mode=3;data_register=read_reg(3);break;
                        case 3: mode=4;data_register=read_reg(4);break;
                        case 4: mode=5;data_register=read_reg(5);break;
                        case 5: mode=6;data_register=read_reg(6);break;
                        case 6: mode=0;break;
                        case 10:mode=11;data_register=read_reg(count_register);break;
                        case 11:mode=10;break;
                        case 100:mode=100;break;
                        }
                }

        if (((sys_time-start_time)>250)) 
                {
                set_digit_on(tis,sot,des,ed);
                if (((mode>0)&&(mode<7))||(mode==11))
                        {
                        if((key_plus_press==1)||(key_mines_press==1)) set_digit_off(tis,sot,des,ed);
                        else set_digit_off(' ',' ',' ',' ');
                        }
                if (mode==0)
                        {
                        set_digit_off(tis,sot,des,ed);
                        set_led_on(0,0,0,1,0,1,0,0);
                        set_led_off(0,0,0,1,0,1,0,0);
                        }
                start_time=sys_time;
                }
        };
}
Ejemplo n.º 7
0
int main( int argc, char** argv )
{
        int devfd;
        int value, ret;

#if ( defined(DIRECT_IO_ACCESS) && !defined(DJGPP) ) 
#if (defined(LINUX_ENV))
	iopl(3);
#endif
#if (defined(FreeBSD_ENV))
	int iofl;
	SET_IOPL();
#endif
#endif
	fprintf(stdout, "=== Lanner platform miscellaneous utility ===\n");;
	fprintf(stdout, PLATFORM_NAME" Status LED "CODE_VERSION"\n\n");;

#ifdef DIRECT_IO_ACCESS
	sled_gpio_init();
        printf("Set LED RED for 4 seconds...\n");
        set_led_green();
        sleep(4);
        printf("Set LED GREEN for 4 seconds...\n");
        set_led_amber();
        sleep(4);
        printf("Set LED DARK\n");
        set_led_off();
        printf("Test Finished.\n");

#if (defined(FreeBSD_ENV))
	RESET_IOPL();
#endif

#else

        devfd = open("/dev/sled_drv", O_RDONLY);
        if(devfd == -1)
        {
                printf("Can't open /dev/sled_drv\n");
                return -1;
        }
        printf("Set LED AMBER for 4 seconds...\n");
        value  =  LED_SET_STATUS_AMBER;
        ret = ioctl(devfd, IOCTL_LED_SET_STATUS, &value);
        sleep(4);
        printf("Set LED GREEN for 4 seconds...\n");
        value  =  LED_SET_STATUS_GREEN;
        ret = ioctl(devfd, IOCTL_LED_SET_STATUS, &value);
        sleep(4);
        printf("Set LED DARK\n");
        value  =  LED_SET_STATUS_OFF;
        ret = ioctl(devfd, IOCTL_LED_SET_STATUS, &value);
        printf("Test Finished.\n");
        close(devfd);
        return 0;


#endif //DIRECT_IO_ACCESS

	return 0;
}
Ejemplo n.º 8
0
void main(void)
{
// Declare your local variables here
//eeprom *int ee_int;
float time_filter;
// Reset Source checking
if (MCUCSR & 1)
{/* Power-on Reset*/MCUCSR&=0xE0;}
else if (MCUCSR & 2)
{/* External Reset*/MCUCSR&=0xE0;/* Place your code here*/}
else if (MCUCSR & 4)
{// Brown-Out Reset
   MCUCSR&=0xE0;/* Place your code here*/}
else if (MCUCSR & 8){// Watchdog Reset
   MCUCSR&=0xE0;/* Place your code here*/}
else if (MCUCSR & 0x10){// JTAG Reset
   MCUCSR&=0xE0;/* Place your code here*/};

PORTA=0xFF;DDRA=0xFF;
PORTB=0x00;DDRB=0xB3;
PORTC=0b11111000;DDRC=0b11111011;
PORTD=0b11110000;DDRD=0x00;

TCCR0=0x02;TCNT0=TCNT0_reload;OCR0=0x00;

TCCR1A=0x00;TCCR1B=0x05;TCNT1H=0x00;TCNT1L=0x01;
ICR1H=0x00;ICR1L=0x04;OCR1AH=0x00;OCR1AL=0x02;
OCR1BH=0x00;OCR1BL=0x03;

ASSR=0x00;TCCR2=0x03;TCNT2=TCNT2_reload;OCR2=0x00;

MCUCR=0x00;MCUCSR=0x00;

TIMSK=0xFF;

UCSRA=0x00;UCSRB=0xD8;UCSRC=0x86;UBRRH=0x00;UBRRL=0x33;
ACSR=0x80;SFIOR=0x00;
SPCR=0x52;SPSR=0x00;
WDTCR=0x1F;WDTCR=0x0F;

count_register=1;
data_register=1234;
time_filter=2;
#asm("sei")
mode=0;
x=0;
start_time=sys_time;
while (1)
        {
        #asm("wdr");
        for (i=0;i<9;i++)rang[i]=0;
        if (++buf_end>8) buf_end=0;
        buf[buf_end]=read_adc();
        for (j=0;j<9;j++)
                {
                for (i=0;i<9;i++)
                        {
                        if (buf[j]<buf[i]) rang[j]--;
                        if (buf[j]>buf[i]) rang[j]++;
                        }
                }
        for(i=0;i<9;i++){if (rang[i]<0)rang[i]=0-rang[i];}
        j=0;for(i=0;i<9;i++){if (rang[j]>rang[i])j=i;}

        xx=(6-time_filter)*0.002;xx=xx*buf[j];
        yy=1-((6-time_filter)*0.002);yy=yy*x;x=xx+yy;
        adc_buf=x+0.5;
        
        if (mode==0)
                {
                hex2dec(adc_buf);
                }
                
        if (((sys_time-start_time_mode)>15000)) mode=0;
        if (mode==1)//уставка №1
                {
                set_led_on(0,0,1,1,0,0,0,0);
                set_led_off(0,0,0,1,0,0,0,0);
                if (((sys_time-start_time_mode)<5000))
                        {
                        tis='У';sot='_';des=1;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        tis=' ';sot=5;des=4;ed=3;
                        set_digit_off(' ',' ',' ',' ');
                        }
                }
        if (mode==2)//уставка №2
                {
                set_led_on(0,1,0,1,0,0,0,0);
                set_led_off(0,0,0,1,0,0,0,0);
                if (((sys_time-start_time_mode)<5000))
                        {
                        tis='У';sot='_';des=2;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        tis=' ';sot=7;des=6;ed=5;
                        set_digit_off(' ',' ',' ',' ');
                        }
                }
        if (mode==3)//время до уставки 1
                {
                if (((sys_time-start_time_mode)<5000))
                        {
                        set_led_on(0,0,1,1,0,0,0,0);
                        set_led_off(0,0,0,1,0,0,0,0);
                        tis=3;sot='_';des=1;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        tis=' ';sot=7;des=6;ed=5;
                        set_digit_off(' ',' ',' ',' ');
                        }
                }
        if (mode==4)//время до уставки 2
                {
                if (((sys_time-start_time_mode)<5000))
                        {
                        set_led_on(0,1,0,1,0,0,0,0);
                        set_led_off(0,0,0,1,0,0,0,0);
                        tis=3;sot='_';des=2;ed=' ';
                        set_digit_off(' ',' ',' ',' ');
                        }
                else
                        {
                        tis=' ';sot=7;des=6;ed=5;
                        set_digit_off(' ',' ',' ',' ');
                        }
                }
        if (mode==5)
                {
                tis=' ';sot=5;des=5;ed=' ';
                set_digit_off(' ',' ',' ',' ');
                set_led_on(0,0,1,1,0,1,0,0);
                set_led_off(0,0,0,1,0,1,0,0);
                }

        if (mode==10)
                {
                hex2dec(count_register);
                if (des==0) des='_';
                tis='a';sot='_';//des=count_register;ed=' ';
                set_digit_off(' ',' ',' ',' ');
                set_led_on(0,0,1,1,0,0,0,0);
                set_led_off(0,0,0,1,0,0,0,0);
                }

        if (mode==11)
                {
                hex2dec(data_register);
//                tis=' ';sot=1;des=2;ed=3;
                set_led_on(0,0,1,1,0,1,0,0);
                set_led_off(0,0,0,1,0,1,0,0);
                }
        
        
        if (key_plus_press==1)
                {
                start_time_mode=sys_time;
                if (count_key==0){if (mode==10)if (++count_register>MAX_REGISTER)count_register=MAX_REGISTER;}
                if ((count_key==0)||(count_key==21)||(count_key1==102))
                        {
                        if (mode==11){if (++data_register>MAX_MIN[count_register,1])data_register=MAX_MIN[count_register,1];}
                        if (count_key==0)count_key=60;if (count_key==21)count_key=20;
                        }
                rekey();
                }
        else if ((mode!=100)&&(key_enter_press==0)&&(key_mines_press==0)){count_key=0;count_key1=0;}

        if (key_mines_press==1)
                {
                start_time_mode=sys_time;
                if (count_key==0){if (mode==10)if (--count_register>MAX_REGISTER)count_register=MAX_REGISTER;}
                if ((count_key==0)||(count_key==21)||(count_key1==102))
                        {
                        if (mode==11){if (--data_register<MAX_MIN[count_register,0])data_register=MAX_MIN[count_register,0];}
                        if (count_key==0)count_key=60;if (count_key==21)count_key=20;
                        }
                rekey();
                }
        else if ((mode!=100)&&(key_enter_press==0)&&(key_plus_press==0)){count_key=0;count_key1=0;}

        if ((key_enter_press==1)&&(key_plus_press==0)&&(key_mines_press==0)&&(key_mode_press==0))
                {
                mode=100;
                ee_int=count_register*2;
                *ee_int=data_register;
                start_time_mode=sys_time;
                }
        else if (mode==100)
                {
                if ((sys_time-start_time_mode)>3250)
                        {
                        start_time_mode=sys_time;start_time=sys_time;mode=10;
                        }
                }

        if (key_mode_press_switch==1)
                {
                key_mode_press_switch=0;
                start_time_mode=sys_time;
                switch (mode)
                        {
                        case 0: mode=1;break;
                        case 1: mode=2;break;
                        case 2: mode=3;break;
                        case 3: mode=4;break;
                        case 4: mode=5;break;
                        case 5: mode=10;break;
                        case 10:mode=11;break;
                        case 11:mode=10;break;
                        case 100:mode=100;break;
                        }
                }

        if (((sys_time-start_time)>250)) 
                {
                set_digit_on(tis,sot,des,ed);
                if (mode==100)
                        {
                        set_digit_on(' ',3,'a','п');
                        set_digit_off(' ',3,'a','п');
                        set_led_on(0,0,0,0,0,0,0,0);
                        set_led_off(0,0,0,0,0,0,0,0);
                        }
                if (mode==11)
                        {
                        if((key_plus_press==1)||(key_mines_press==1)) set_digit_off(tis,sot,des,ed);
                        else set_digit_off(' ',' ',' ',' ');
                        }
                if (mode==0)
                        {
                        set_digit_off(tis,sot,des,ed);
                        set_led_on(0,0,0,1,0,1,0,0);
                        set_led_off(0,0,0,1,0,1,0,0);
                        }
                start_time=sys_time;
                }
        };
}