コード例 #1
0
ファイル: motor_pwm.c プロジェクト: zandar/PWM-motor-control
/*
 *  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;
}
コード例 #2
0
void 
hw_init()
{
    led_pwm_init ();
}