int motor_rtctl_init(void) { int ret = motor_pwm_init(); if (ret) { return ret; } motor_timer_init(); ret = motor_adc_init(); if (ret) { return ret; } motor_forced_rotation_detector_init(); configure(); motor_rtctl_stop(); return 0; }
//摆脚外力拉起到165°左右,使之倒立不少于5s,横杆转动不大于90° void function3(void) { if(flag) { // motor_pwm_set(); //500以上3500以下 // LCD_ShowxNum(30,200,5464,8,12,0); TIM2_Int_Init(20-1,8400-1);//PID 2ms motor_pwm_init(500-1,84-1); motor_pwm_stop(); flag=0; } }
/* * MAIN */ int main(void) { DDRB = 0x0E; // PB0 = in, PB1 - PB3 out PORTB |= 0x01; // set pull-up rezistor on PB0 - output DDRD &= ~0x04; // PD2 = in PORTD |= 0x04; // set pull-up rezistor on PD2 - input motor_pwm_init(); ADCSRA = 0xCB; ADMUX = 0x60; // Vref Vcc MCUCR |= 0x02; // interupr int0 acts on falling edge sei(); // global interrupt enable motor_start(MOTOR_1); while(1) { if ((PINB & 0x01) == SENSOR_MODE && int_wait == 0) { /* */ motor_stop(MOTOR_0); led_pwm_init(); SENSOR_ON; int_wait = 1; } else if ((PINB & 0x01) == !SENSOR_MODE) { SENSOR_OFF; LED_PWM_STOP; motor_start(MOTOR_0); int_wait = 0; } } return 0; }
//电机初始化 void motor_init(void) { motor_io_init(); motor_pwm_init(); }