int main() { init_clock(); init_gpio(); init_usart(); init_pwm(); while(1) {} }
int main() { init(); init_pwm(); while(1) { if(toDoCalibrage) { sendSignalCalibrage(toDoCalibrage); // Fin de calibrage sendCalibrageDone(); toDoCalibrage = 0; } if(semit) { emit(); semit = 0; } } return 0; }
int main(void) { timer_init(); /* initialize the scheduler timer */ led_init(); /* initialize led */ init_uart(); /* initialize uart*/ init_pwm(); init_m_one(); init_m_two(); //init_slip(SLIP_BUFFER_SIZE); /* initialize slip protocol*/// Deprecated!!! /* Initialize two buffers */ slip_rx_buffer = (char*)malloc(sizeof(char)*SLIP_BUFFER_SIZE); slip_tx_buffer = (char*)malloc(sizeof(char)*SLIP_BUFFER_SIZE); sei(); for (;;) /* go into an endless loop */ { //uart_tx_str((uint8_t*) "THIS IS SPARTA!!"); /* handle 20ms tasks */ if (t20ms != 0) /* if the interrupt has timed out after 20ms */ { t20ms --; task_20ms(); /* run the 20ms task */ } slip_task(); } return 0; /* just for the principle as we never get here */ }
void main() { uint16 i = 0; uint8 j = 0; init_clock(); init_pwm(); init_ports(); //init_uart(); pwm = 0; pwm_ctl(true); HBR1 = 1; HBR2 = 0; while(1) { while(pwm > 0) { for(j = 0; j < 16; j++) for(i = 1; i; i++); pwm -= 2; } while(pwm < 64) { for(j = 0; j < 16; j++) for(i = 1; i; i++); pwm += 2; } /*if(HBR1) { HBR1 = 0; HBR2 = 1; } else { HBR2 = 0; HBR1 = 1; }*/ } }
void main(void) { init_pwm(); while(1) { } }
void main() { u8 resultat; init_picstar(); // 1 solution // port d en sortie pour affichier un resultat LATD=0; TRISD=0; init_adc(); // code de l'exercise 2 // initialiser le pwm sur RC2 init_pwm(); // code a développer while(1) { u8 tmp; #ifdef ACTIVE_MOTEUR resultat=get_adc0(); set_pwm(1,resultat); // pwm duty = potentiometre #else if((resultat+=PLIMITE)>255)resultat=255; set_freq(1,resultat); #endif LATD=resultat; // affiche la vitesse du moteur en binaire sur les LED's delay_ms(10); } // end while }// fin of program
PUBLIC void setupHardware(void) { //inicializa as configuraçoes do micrococontrolador init_mcu(); //Inicializa driver das interrupcoes interrupt_init(); //Inicializa as portas do microcontrolador init_gpio(); //Inicializa UART init_uart(); //Inicializa TMR0 init_timer0(); //Inicializa I2C init_i2c(); //Inicializa ADs init_AD(); //Inicializa PWM init_pwm(); }
int main (void) { pwm_frame_t * next_pwm = malloc(sizeof(pwm_frame_t)); initialize_pru(); start_pru(); pru_pwm_frame_t * pwm_out = get_pwm_pointer(); init_pwm(next_pwm); output_pwm(next_pwm, pwm_out); signal(SIGINT, signal_handler); while(pruDataMem_int[0] != 0){ scanf("%d %d %d %d", &(next_pwm->zero), &(next_pwm->one), &(next_pwm->two), &(next_pwm->three)); printf("ping: %d\n", pruDataMem_int[1]/5800); pruDataMem_int[2] = 0; next_pwm->zero *= 1000; next_pwm->one *= 1000; next_pwm->two *= 1000; next_pwm->three *= 1000; output_pwm(next_pwm, pwm_out); } uninitialize_pru(); return(0); }
int main(int argc,char **argv) { int i; //iterator pid *x,*y,*z; //structs representing 3 pid controllers imu_t *imu; fd_set net_set; double oldmag,magdiff; struct timeval timeout; int axes[4]={0,0,0,0}; int x_adjust,y_adjust,z_adjust; int sock = init_net(); register_int(); x=init_pid(3500,000,000); y=init_pid(3400,000,1000); z=init_pid(000,000,000); timeout.tv_sec=0; timeout.tv_usec=REFRESH_TIME; for(i=0;i<4;i++) { //initialize PWM modules motors[i]=init_pwm(i); } imu = init_imu(); update_imu(imu); oldmag=imu->mpu.fusedEuler[VEC3_Z] * RAD_TO_DEGREE; while(1) { ////printf("loop\n"); FD_ZERO(&net_set); FD_SET(sock,&net_set); if(select(sock+1,&net_set,(fd_set *) 0,(fd_set *) 0, &timeout)==1) { ////printf("reading from the socket\n"); //read from sock if(!update_axis(sock,axes)) { break; } } else { ////printf("reading from the imu\n"); //update imu update_imu(imu); timeout.tv_sec=0; timeout.tv_usec=REFRESH_TIME; magdiff=imu->mpu.fusedEuler[VEC3_Z] * RAD_TO_DEGREE-oldmag; if(magdiff>300) { magdiff-=360; } if(magdiff<-300) { magdiff+=360; } x_adjust = update_pid(x,0/*axes[1]*.00061*/,imu->mpu.fusedEuler[VEC3_X] * RAD_TO_DEGREE); y_adjust = update_pid(y,0/*axes[2]*.00061*/,imu->mpu.fusedEuler[VEC3_Y] * RAD_TO_DEGREE); //printf("X axis value: %lf\n",imu->mpu.fusedEuler[VEC3_X]*RAD_TO_DEGREE); //printf("Y axis value: %lf\n",imu->mpu.fusedEuler[VEC3_Y]*RAD_TO_DEGREE); z_adjust = update_pid(z,axes[3]*.00061,magdiff); oldmag=imu->mpu.fusedEuler[VEC3_Z] * RAD_TO_DEGREE; set_duty(motors[0],900000+axes[0]*16-z_adjust-y_adjust+x_adjust); set_duty(motors[1],900000+axes[0]*16+z_adjust-y_adjust-x_adjust); set_duty(motors[2],900000+axes[0]*16-z_adjust+y_adjust-x_adjust); set_duty(motors[3],900000+axes[0]*16+z_adjust+y_adjust+x_adjust); } } exit_fxn(0); }
void setup_pwm() { // R_FORWARD on P3.4 init_pwm(&TB1CTL); set_pwm_resolution(&TB1CCR0, PWM_RES); set_pwm_value(&TB1CCR1, PWM_RES / DIVIDE_BY_TWO); set_pwm_output(&TB1CCTL1); P3DIR |= R_FORWARD; P3SEL0 |= R_FORWARD; P3SEL1 &= ~R_FORWARD; start_pwm(&TB1CTL); // L_FORWARD on P3.6 init_pwm(&TB2CTL); set_pwm_resolution(&TB2CCR0, PWM_RES); set_pwm_value(&TB2CCR1, PWM_RES / DIVIDE_BY_TWO); set_pwm_output(&TB2CCTL1); P3DIR |= L_FORWARD; P3SEL0 |= L_FORWARD; P3SEL1 &= ~L_FORWARD; start_pwm(&TB2CTL); // R_REVERSE on P3.5 set_pwm_value(&TB1CCR2, PWM_RES / DIVIDE_BY_TWO); set_pwm_output(&TB1CCTL2); P3DIR |= R_REVERSE; P3SEL0 |= R_REVERSE; P3SEL1 &= ~R_REVERSE; // L_REVERSE on P3.7 set_pwm_value(&TB2CCR2, PWM_RES / DIVIDE_BY_TWO); set_pwm_output(&TB2CCTL2); P3DIR |= L_REVERSE; P3SEL0 |= L_REVERSE; P3SEL1 &= ~L_REVERSE; }
void control_init(void) { init_gpio(); init_pwm(); LPLD_UART_Init(UART2, 115200); //裁判机 LPLD_UART_RIE_Enable(UART2, uart2_recv_isr); while (!GetCmdAction()); while(1) { right_set_v(V_SLOW); left_set_v(V_SLOW); scan_infrared(r1, r2, r3, r4); if(IS_AT_CORNER()) break; } motor_time_wait = 0; while (1) { if(motor_time_wait < 100000)//等待电机反应时间 不然直接下一步有影响 没有彻底停下来 { motor_time_wait ++; right_set_v(0); left_set_v(0); } else { motor_time_wait = 0; break; } } can_interrupt = 1; //计时器寄存器每减少50过1us LPLD_UART_Init(UART1, 19200); //读卡器 LPLD_UART_Init(UART3, 9600); //蓝牙 LPLD_UART_Init(UART4, 9600); LPLD_UART_Init(UART5, 19200); //读卡器 LPLD_UART_RIE_Enable(UART1, uart1_recv_isr); LPLD_UART_RIE_Enable(UART3, uart3_recv_isr); //LPLD_UART_RIE_Enable(UART4, uart4_recv_isr); LPLD_UART_RIE_Enable(UART5, uart5_recv_isr); LPLD_LPTMR_Init(MODE_PLACC, 0, LPTMR_ALT1, IRQ_DISABLE, NULL); //UP_LCD_Init(); //初始化LCD LPLD_ADC_Init(ADC0, MODE_16, CONV_SING); memset(control_callbacks, NULL, sizeof(control_callbacks)); memset(r1, 0, sizeof(r1)); memset(r2, 0, sizeof(r2)); memset(r3, 0, sizeof(r3)); memset(r4, 0, sizeof(r4)); LPLD_PIT_Init(PIT0, 5000, pit_isr0); //电机控制 LPLD_PIT_Init(PIT1, 100000, pit_isr1); //计时 TIME_PASSED = 0; }
int main(void) { init_pwm(); while (1) { move_to_angle(105); delay(1000); } }
int main(void) { init_pwm(); init_adc(); while(1) // Loop Forever { sleep_mode(); } }
void init_v7(void *stack_base) { struct v7_create_opts opts; v7_val_t dht11, debug; opts.object_arena_size = 164; opts.function_arena_size = 26; opts.property_arena_size = 400; opts.c_stack_base = stack_base; v7 = v7_create_opt(opts); v7_set_method(v7, v7_get_global(v7), "dsleep", dsleep); v7_set_method(v7, v7_get_global(v7), "crash", crash); #if V7_ESP_ENABLE__DHT11 dht11 = v7_create_object(v7); v7_set(v7, v7_get_global(v7), "DHT11", 5, 0, dht11); v7_set_method(v7, dht11, "read", DHT11_read); #else (void) dht11; #endif /* V7_ESP_ENABLE__DHT11 */ debug = v7_create_object(v7); v7_set(v7, v7_get_global(v7), "Debug", 5, 0, debug); v7_set_method(v7, debug, "mode", Debug_mode); v7_set_method(v7, debug, "print", Debug_print); sj_init_timers(v7); sj_init_v7_ext(v7); init_gpiojs(v7); init_adcjs(v7); init_i2cjs(v7); init_pwm(v7); init_spijs(v7); init_wifi(v7); mongoose_init(); sj_init_http(v7); sj_init_ws_client(v7); /* NOTE(lsm): must be done after mongoose_init(). */ init_device(v7); #ifndef DISABLE_OTA init_updater(v7); #endif #ifndef DISABLE_C_CLUBBY sj_init_clubby(v7); #endif v7_gc(v7, 1); }
/** * \brief Initializes the motors * * \param * * \return void */ void motors_init(void) { init_ext_int(); init_pwm(); set_l_m_forward(); set_r_m_forward(); l_motor.ref_rpm=0; r_motor.ref_rpm=0; l_motor.rpm=1; r_motor.rpm=1; l_motor.break_count=1; r_motor.break_count=1; }
int main(int argc, char *argv[]) { init(); init_pwm(); while(1){ PORTCbits.RC0 = 1; delay_ms(20); PORTCbits.RC0 = 0; delay_ms(20); } return 0; }
void InitApp(void) { TRISBbits.TRISB0 = 1; //set as INPUT TRISBbits.TRISB1 = 0; //set as OUTPUT TRISBbits.TRISB2 = 1; //set as INPUT TRISBbits.TRISB3 = 1; //set as INPUT TRISBbits.TRISB4 = 0; //set as OUTPUT TRISBbits.TRISB5 = 0; //set as OUTPUT ANSELBbits.ANSB0 = 0; //set as DIGITAL ANSELBbits.ANSB2 = 0; //set as DIGITAL ANSELBbits.ANSB3 = 0; //set as DIGITAL TRISCbits.TRISC6 = 0; //set as OUTPUT TRISCbits.TRISC7 = 0; //set as OUTPUT TRISDbits.TRISD0 = 0; //set as OUTPUT TRISDbits.TRISD1 = 0; //set as OUTPUT TRISDbits.TRISD2 = 0; //set as OUTPUT TRISDbits.TRISD3 = 0; //set as OUTPUT TRISDbits.TRISD4 = 0; //set as OUTPUT TRISDbits.TRISD5 = 1; //set as INPUT TRISDbits.TRISD5 = 1; //set as INPUT TRISEbits.TRISE0 = 1; //set as INPUT TRISEbits.TRISE1 = 1; //set as INPUT ANSELEbits.ANSE0 = 0; //set as DIGITAL ANSELEbits.ANSE1 = 0; //set as DIGITAL PORTEbits.RE0 = 0; //set as ViL PORTEbits.RE1 = 0; //set as ViL TRISFbits.TRISF0 = 0; //set as OUTPUT TRISFbits.TRISF1 = 0; //set as OUTPUT TRISFbits.TRISF2 = 0; //set as OUTPUT TRISFbits.TRISF3 = 0; //set as OUTPUT TRISFbits.TRISF4 = 0; //set as OUTPUT TRISFbits.TRISF5 = 0; //set as OUTPUT TRISFbits.TRISF6 = 0; //set as OUTPUT TRISGbits.TRISG1 = 0; //set as OUTPUT TRISGbits.TRISG2 = 0; //set as OUTPUT init_adc(); init_pwm(); INTCONbits.GIE = 0b1; //enable interrupt INTCONbits.TMR0IE = 0b1; INTCONbits.TMR0IF = 0b0; }
int main(void) { SystemInit(); SystemCoreClockUpdate(); led_init(); init_interupt(); init_pwm(pwm_pin_num, pwm_channel, period, 0); init_coil(); init_timer(); init_ADC(); init_timer(); #ifdef DEBUG_WEIGHT int a; for (a = 0; a < COUNT; a++) { temp[a] = 0; } #endif printf("Weight Meassure. clibration: %d \n Press Button 1 to calibrate \n", calibrate); delay_ms(5000); if (button_pressed_1) { calibrate = true; button_pressed_1 = false; printf("Device will be calibrated \n"); } else { printf("Stock calibration will be used bei Temperatur:%g \n",calibration_temp); calibrate = false; } while (1) { measure_button(); //Funktion zum Start der Messung delay_ms(5); catapult_button(); check_temperatur(MAX_TEMP); delay_ms(2000); // printf("%g\n",compute_temperatur()); } return 0; }
static int __init aml_ir_receiver_probe(struct platform_device *pdev) { int r; dbg("ir receiver probe\n"); if(pdev != NULL) irreceiver_data = pdev->dev.platform_data; if(irreceiver_data == NULL){ printk(KERN_ERR "can't get platform data\n"); return -1; } r = alloc_chrdev_region(&irreceiver_id, 0, DEIVE_COUNT, DEVICE_NAME); if (r < 0) { printk(KERN_ERR "Can't register major for ir receiver device\n"); return r; } irreceiver_class = class_create(THIS_MODULE, DEVICE_NAME); if (IS_ERR(irreceiver_class)) { unregister_chrdev_region(irreceiver_id, DEIVE_COUNT); printk(KERN_ERR "Can't create class for ir receiver device\n"); return -1; } cdev_init(&irreceiver_device, &aml_ir_receiver_fops); irreceiver_device.owner = THIS_MODULE; cdev_add(&(irreceiver_device), irreceiver_id, DEIVE_COUNT); irreceiver_dev = device_create(irreceiver_class, NULL, irreceiver_id, NULL, "irreceiver%d", 0); //kernel>=2.6.27 if (irreceiver_dev == NULL) { dbg("irreceiver_dev create error\n"); class_destroy(irreceiver_class); return -EEXIST; } device_create_file(irreceiver_dev, &dev_attr_switch); device_create_file(irreceiver_dev, &dev_attr_keyvalue); device_create_file(irreceiver_dev, &dev_attr_log); ir_hardware_init(); init_pwm(); init_timer_b(); return 0; }
int main(int argc, char** argv) { //---------- FLASH ------------ // MCHP_FLASH_ENABLE non fonctionnel // MCHPCONbits.FAEN = 1; non fonctionnel // while(MCHPCONbits.FCBUSY); non fonctionnel // NVMCONbits.WR = 1; // NVMCONbits.NVMOP = ?; init_pins(); init_preset(); init_Menus(); INTCONbits.MVEC = TRUE; //Multi-vector interrupt mode asm volatile("ei"); //Autorise les macro-ASM (interruptions) init_lcd(); create_tab_env(); create_tab_frequenz(); create_tab_period(); init_MIDI(); init_pwm(); init_dac(); /* PMCON = 0; PMAEN = 0; PMMODE = 0; PMADDR = 0; PMSTAT = 0; PMDIN = 0; PMDOUT = 0; AD1CON1 = 0; AD1CON2 = 0; AD1CON3 = 0; AD1CHS = 0; AD1CSSL = 0; U2STA = 0; U2MODE = 0;*/ update_menu(); while (42) { boutons(); processEncodeur(); } return (0); }
void main() { init(); // set PORTA5 & PORTA2 to output TRISA5 = 0; TRISA2 = 0; init_pwm(); /* generates symetric 1 MHZ signal */ while(1) { LATA5 = 1; LATA5 = 1; // add 3 CPU cycles to generate symetric signal LATA5 = 1; // LATA5 = 1; // LATA5 = 0; } }
void main() { u16 resultat; u8 compteur=0; init_picstar(); init_adc(); // code de l'exercise 2 // initialiser le pwm sur RC2 init_pwm(); // code a développer // initialise l'écran lcd init_lcd(); set_backlight(ON); while(1) { u16 tmp; resultat=get_adc0(); #ifdef ACTIVER_MOTEUR set_pwm(1,resultat); // pwm duty = potentiometre lcd_gotoxy(0,0); fprintf(_H_USER,"HELLO WORLD %3u ", compteur & 0xff); lcd_gotoxy(0,1); fprintf(_H_USER,"ADC= %u ",resultat); #else // si non activer le son if((resultat+=PLIMITE)>255)resultat=255; set_freq(1,resultat); lcd_gotoxy(0,0); fprintf(_H_USER,"ADC= %u ", resultat); lcd_gotoxy(0,1); // calcul de la frequence en 10khz tmp=120000L/16/resultat; fprintf(_H_USER,"Freq=%u.%1u khz ",tmp/10 & 0xff, tmp%10 &0xff); #endif delay_ms(10); } // end while }// fin of program
/* initialise the PWM software stack */ bool_t init_pwm_if(pwm_if_channel_t channel) { bool_t retVal = FALSE; if (init_pwm_reinit_flag == FALSE) { if (channel < PWM_CH_MAX) { retVal = init_pwm((pwm_channel_t)(channel)); if (retVal == TRUE) { init_pwm_reinit_flag = TRUE; } } } return (retVal); }
int main(void) { init_pwm(); init_fader(); //teste HSV Methode //Rot (0,255,X): // V= 50, 16% duty und 12mA // V=100, 30% duty und 23mA // V=255, 71% duty und 597mA //runHSV(0,4095,4095); //rot //runHSV(1320,4095,4095); //grün //runHSV(2640,4095,4095); //blau runHSV(0,0,1000); //weiß //teste Slot Animation /*HSV_anim anim1 = {0,4095,4095,+3960,0,0,500}; runSlot(anim1);*/ //teste Program Animation /*newProgram(); //FLASH HSV_anim anim2 = {0,4095,0,0,0,3000,500}; setSlot(anim2); HSV_anim anim3 = {1320,4095,0,0,0,3000,500}; setSlot(anim3); HSV_anim anim4 = {2640,4095,0,0,0,3000,500}; setSlot(anim4); runProgram();*/ /*newProgram(); //pulsierendes Weiß HSV_anim anim2 = {0,0,10,0,0,1010,100}; setSlot(anim2); HSV_anim anim3 = {0,0,1010,0,0,-1000,100}; setSlot(anim3); runProgram();*/ sei(); while(1){ faderThread(); } }
int main(void) { init_rand(); init_pwm(); // enable timer overflow interrupt TIMSK0 = (1 << TOIE0) | (1 << OCIE0A); static filter_state candle[3] = {}; while(1) { cli(); for (int i = 0; i < 3; i++) { pwm[i] = next_intensity(&candle[i]); } sei(); // sleep till next update while (!tick) sleep_mode(); tick = false; } }
__task void adc_test(void) { float sol_v, sol_i, batt_v, batt_i, temp; init_pwm(40000); init_adc(); set_duty_cycle(82); while (1) { sol_v = get_adc_voltage(ADC_SOL_V); sol_i = get_adc_voltage(ADC_SOL_I); batt_v = get_adc_voltage(ADC_BATT_V); batt_i = get_adc_voltage(ADC_BATT_I); temp = get_adc_voltage(ADC_TEMP); TRACE_INFO("6,%f,%f,%f,%f,%f\n", sol_v, sol_i, batt_v, batt_i, temp ); os_dly_wait(100); } }
int main(void) { #ifdef USART_DEBUG usart0_init(); #endif init_pwm(); ir_init(); control_init(); fe_init(); sei(); #ifdef USART_DEBUG usart0_puts("Initialized\n\r"); #endif while (1) { ir_handler(); control_handler(); pwm_handler(); fe_handler(); } }
int main() { // Turn button pull up resistor on by setting PA2 and PA3 PORTA |= (1 << 3) | (1 << 2); // Clock divider - Data sheet Page 82 TCCR0B = (0<<CS02) | (1<<CS01) | (1<<CS00); // does not effect _delay_ms() init_pwm(); for(;;) { if (CLOSED || BUTTON_DOWN) { led_level(255); out_on(); } else { led_level(0); out_off(); } } }
/** main function */ int main(void) { init_output(); init_pwm(); #if SERIAL_UART init_uart(); #endif #if RC5_DECODER init_rc5(); #endif #if I2C init_i2c(); #endif global_pwm.channels[0].brightness = 50; global_pwm.channels[0].target_brightness = 50; #if STATIC_SCRIPTS init_script_threads(); #if RS485_CTRL == 0 /* start the example scripts */ script_threads[0].handler.execute = &memory_handler_flash; script_threads[0].handler.position = (uint16_t) &colorchange_red; script_threads[0].flags.disabled = 0; //script_threads[1].handler.execute = &memory_handler_flash; //script_threads[1].handler.position = (uint16_t) &testscript_flash2; //script_threads[1].flags.disabled = 0; // //script_threads[2].handler.execute = &memory_handler_eeprom; //script_threads[2].handler.position = (uint16_t) &testscript_eeprom; //script_threads[2].flags.disabled = 0; //script_threads[0].handler.execute = &memory_handler_flash; //script_threads[0].handler.position = (uint16_t) &blinken; //script_threads[0].flags.disabled = 0; #endif #endif #if I2C_MASTER i2c_global.send_messages[0].command.size = 4; i2c_global.send_messages[0].command.code = COMMAND_SET_COLOR; i2c_global.send_messages[0].command.set_color_parameters.colors[0] = 0x10; i2c_global.send_messages[0].command.set_color_parameters.colors[1] = 0x10; i2c_global.send_messages[0].command.set_color_parameters.colors[2] = 0x10; i2c_global.send_messages_count = 1; #endif #if RS485_CTRL /* init command bus */ UCSR0A = _BV(MPCM0); /* enable multi-processor communication mode */ UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); /* 9 bit frame size */ #define UART_UBRR 8 /* 115200 baud at 16mhz */ UBRR0H = HIGH(UART_UBRR); UBRR0L = LOW(UART_UBRR); UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(UCSZ02); /* enable receiver and transmitter */ #endif /* enable interrupts globally */ sei(); while (1) { /* after the last pwm timeslot, rebuild the timeslot table */ if (global.flags.last_pulse) { global.flags.last_pulse = 0; update_pwm_timeslots(); } /* at the beginning of each pwm cycle, call the fading engine and * execute all script threads */ if (global.flags.new_cycle) { global.flags.new_cycle = 0; update_brightness(); #if STATIC_SCRIPTS execute_script_threads(); #endif continue; } #if SERIAL_UART /* check if we received something via uart */ if (fifo_fill(&global_uart.rx_fifo) > 0) { check_serial_input(fifo_load(&global_uart.rx_fifo)); continue; } #endif #if RC5_DECODER /* check if we received something via ir */ if (global_rc5.new_data) { static uint8_t toggle_bit = 2; /* if key has been pressed again */ if (global_rc5.received_command.toggle_bit != toggle_bit) { /* if code is 0x01 (key '1' on a default remote) */ if (global_rc5.received_command.code == 0x01) { /* install script into thread 1 */ script_threads[1].handler.execute = &memory_handler_flash; script_threads[1].handler.position = (uint16_t) &green_flash; script_threads[1].flags.disabled = 0; script_threads[1].handler_stack_offset = 0; } /* store new toggle bit state */ toggle_bit = global_rc5.received_command.toggle_bit; } /* reset the new_data flag, so that new commands can be received */ global_rc5.new_data = 0; continue; } #endif #if RS485_CTRL if (UCSR0A & _BV(RXC0)) { uint8_t address = UCSR0B & _BV(RXB80); /* read nineth bit, zero if data, one if address */ uint8_t data = UDR0; static uint8_t buffer[8]; static uint8_t fill = 0; if (UCSR0A & _BV(MPCM0) || address) { /* if MPCM mode is still active, or ninth bit set, this is an address packet */ /* check if we are ment */ if (data == 0 || data == RS485_ADDRESS) { /* remove MPCM flag and reset buffer fill counter */ UCSR0A &= ~_BV(MPCM0); fill = 0; continue; } else {/* turn on MPCM */ UCSR0A |= _BV(MPCM0); continue; } } /* else this is a data packet, put data into buffer */ buffer[fill++] = data; if (buffer[0] == 0x01) { /* soft reset */ jump_to_bootloader(); } else if (buffer[0] == 0x02 && fill == 4) { /* set color */ for (uint8_t pos = 0; pos < 3; pos++) { global_pwm.channels[pos].target_brightness = buffer[pos + 1]; global_pwm.channels[pos].brightness = buffer[pos + 1]; } UCSR0A |= _BV(MPCM0); /* return to MPCM mode */ } else if (buffer[0] == 0x03 && fill == 6) { /* fade to color */ for (uint8_t pos = 0; pos < 3; pos++) { global_pwm.channels[pos].speed_h = buffer[1]; global_pwm.channels[pos].speed_l = buffer[2]; global_pwm.channels[pos].target_brightness = buffer[pos + 3]; } UCSR0A |= _BV(MPCM0); /* return to MPCM mode */ } } #endif #if I2C_MASTER i2c_master_check_queue(); #endif } }
/*### Mainloop ###*/ int main(void) { WDT_TRIGGERED(); //Watchdogreset? init_sys(); init_pwm(); init_timer(); dist_init(); uart_init(UART_BAUD_SELECT(UART_MCU_BAUD_RATE,F_CPU)); //Bluetooth comm_init(); init_adc(); mot.off = 0; //The higher the task_i of the task is, the higher is the priority MAIN_LED_OFF(); tasks[TASK_TIMER_ID].state = -1; tasks[TASK_TIMER_ID].period = TASK_PERIOD_TIMER; tasks[TASK_TIMER_ID].elapsedTime = 0; tasks[TASK_TIMER_ID].running = 0; tasks[TASK_TIMER_ID].task_fct = &task_timer; tasks[TASK_SPEEDREG_ID].state = -1; tasks[TASK_SPEEDREG_ID].period = TASK_PERIOD_SPEEDREG; tasks[TASK_SPEEDREG_ID].elapsedTime = 0; tasks[TASK_SPEEDREG_ID].running = 0; tasks[TASK_SPEEDREG_ID].task_fct = &task_speedreg; tasks[TASK_ANASENS_ID].state = -1; tasks[TASK_ANASENS_ID].period = TASK_PERIOD_ANASENS; tasks[TASK_ANASENS_ID].elapsedTime = 0; tasks[TASK_ANASENS_ID].running = 0; tasks[TASK_ANASENS_ID].task_fct = &task_anasens; if(get_incrOk()) debug = 1; else debug = 0; sei(); //Enable global interrupts. The Operating System and every task in it is running now and the cam already can regulate its initial aparture bt_putStr_P(PSTR("\r\n\n\n\n\n\n\n\n")); bt_putStr_P(PSTR("–––––––––––––––––––––––\r\n")); bt_putStr_P(PSTR("| RIOS Scheduler v1.0 |\r\n")); bt_putStr_P(PSTR("–––––––––––––––––––––––\r\n")); bt_putStr_P(PSTR("rcj2015 v2.0\r\n")); bt_putStr_P(PSTR("Subcontroller ATmega2560\r\n")); bt_putStr_P(PSTR("Baud rate: "));bt_putLong(UART_COMM_BAUD_RATE); bt_putStr_P(PSTR(" Baud.\r\n")); bt_putStr_P(PSTR("\r\n")); bt_putLong(timer); bt_putStr_P(PSTR(": System initialized, ")); bt_putLong(TASKS_NUM); bt_putStr_P(PSTR(" running tasks.\n\n")); if(check_res) { motor_activate(0); //Shut down motor driver if(debug > 0){bt_putStr_P(PSTR("\r\n")); bt_putLong(timer); bt_putStr(PSTR(": WARNING: RECOVERED AFTER AN UNEXPECTED SHUTDOWN!!!\n\n"));} _delay_ms(5000); } wdt_enable(WDTO_1S); //activate watchdog timer_get_tast = 120; while(1) { wdt_reset(); //////////////////////////////////////////////////////////////////////////// comm_handler(); //Handle and respond to comm requests. comm_reg_gateway(); //////////////////////////////////////////////////////////////////////////// if((timer_get_tast == 0) && (setup == 0)) { timer_get_tast = -1; mot.off = 0; } if(get_t1()) //Always reset... { mot.off = 1; timer_get_tast = 120; } ////////////////////LED etc...////////////////////////////////////// if(timer_mainloop == 0) { if(check_res || fatal_err) //Flashing of the Info LED when there is an error led_fault = 1; else if(timer_nocomm == 0) led_fault = 85; //Blink green if no communication/waiting for command else if(mot.off) led_fault = 30; else led_fault = 0; if(fatal_err) led_top = LED_TOP_FAT_ERR; else led_top = LED_TOP_NORMAL; if(check_res) { if(!(debug_err_sendOneTime & (1<<0))) { if(debug > 1){bt_putStr_P(PSTR("\n\r")); bt_putLong(timer); bt_putStr_P(PSTR(": ERROR: RESET"));} debug_err_sendOneTime |= (1<<0); } } else debug_err_sendOneTime &= ~(1<<0); //Batterie/Akku if(batt_raw > 0) { batt_mV = (batt_raw*15)-300; if(batt_mV < batt_mV_old) { batt_mV_old = batt_mV; batt_percent = (0.037*batt_mV) - 363; } if(batt_percent < 20) //Batterie led_heartbeatColor = batt_percent; } //////////////////////////////////////////////////////////////////////////// //LED heartbeat if(rgb_led_mode == 0) led_rgb(led_heartbeatColor, led_fault, led_top); else led_hsvToRgb(rgb_led_hue, rgb_led_sat, rgb_led_val); timer_mainloop = TIMER_MAINLOOP; } } return 0; }