/*----------------------------------------------------------------------------/ / * TinCan-Talker / / * This project, program codes and circuit diagrams, is opened under license / * policy of following trems. / / * This project is a free software and there is NO WARRANTY. / * No restriction on use. You can use, modify and redistribute it for / * personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY. / * Redistributions of source code must retain the above copyright notice. / / * Copyright (C) 2015, Makarov Vladimir, all right reserved. / /----------------------------------------------------------------------------*/ #define F_CPU 9600000 // MCU frequency for the delay library #include // I/O library #include // Delay library int k; // Sound value from ADCH void servo_move(int i) { OCR0A = i; } int main(void) // Main program { // Port B configuration DDRB = 0b00000001; // PB0 -> SPI.MOSI, PWM output // PB1 <- SPI.MISO // PB2 <- SPI.SCK, ADC1 input // PB3 <- not connected // PB4 <- not connected // PB5 <- SPI.RESET PORTB = 0b00000000; // ADC configuration ADCH = 0x00; // ADC Conversion Result (high byte) ADCL = 0X00; // ADC Conversion Result (low byte) ADMUX = // ADC Multiplexer Selection Register (1< 6.8ms (Period) |(0< OCR0Amax=74 while (1) { _delay_ms(100); ADCSRA |= (1< Pulse wight=1ms -> angle=180 degrees) if (k > 74) k = 74; // Pulse wight maх is 2ms -> OCR0Amax=74 if (k < 37) k = 37; // Pulse wight min is 1ms -> OCR0Amax=37 servo_move(k); // Open your mouth ))) } }