ДИПЛОМНИЙ ПРОЕКТ / програма без коментаріїв
.docx# Include <avr/interrupt.h> ISR (TIMER0_OVF_vect) { / / Giving counter such values / / To the next overflow occurred in 10 ms. / / Formula: 256 - 8 MHz / 1024/100 Hz = 177,785 = ~ 178 TCNT0 = 178; } int main () { / / In addition to the first overflow interrupt occurred / / 10 ms, and be here to reset the counter. TCNT0 = 178; / / Ratio of the frequency divider 1024 TCCR0 = 0x07; / / Enable interrupt filling counter TIMSK | = (1 << TOIE0); / / Enable global interrupt sei (); / / Infinite loop program while (1) continue; } # Include <avr/interrupt.h> unsigned long frequency; / / Interrupt events occur ISR (TIMER1_CAPT_vect) { / / Reset the counter TCNT1 = 0; / / The result is true only in the case / / If the counter does not overflow if (! (TIFR & (1 << TOV1)))
#include <avr/interrupt.h>
ISR(TIMER0_OVF_vect)
{
TCNT0 = 178;
}
int main()
{
TCNT0 = 178;
TCCR0 = 0x07;
TIMSK |= (1 << TOIE0);
sei();
while (1) continue;
}
#include <avr/interrupt.h>
unsigned long frequency;
ISR(TIMER1_CAPT_vect)
{
TCNT1 = 0;
if (!(TIFR & (1 << TOV1)))
{
// Расчёт частоты из обратной величины периода.
frequency = (unsigned long)8000000 /
(unsigned long)ICR1;
}
else
{
// Частота меньше, чем 122 Hz
frequency = 0;
// Обнуление флага при переполнении счётчика
TIFR &= ~(1 << TOV1);
}
}
int main()
{
// Регистрация нарастающего фронта, коэффициент делителя частоты 1
TCCR1B = (1 << ICES1) | (1 << CS10);
// Разрешение прерывания совершения события
TIMSK = (1 << TICIE1);
// Разрешение глобальных прерываний
sei();
// Бесконечный цикл программы
while (1) continue;
}
#include <avr/io.h>
int main()
{
// Установить выводы выходами
DDRB |= (1 << PIN5) | (1 << PIN6);
// Выходы A и B во время сравнения низкими,
// режим "Fast PWM", делитель частоты 8
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11);
// Наибольшее значение счётчика. Формула:
// TOP = 8 MHz / 8 / 50 Hz
ICR1 = 20000;
// Полупериод первого мотора 1 ms, второго 2 ms
OCR1A = 1000;
OCR1B = 2000;
// Бесконечный цикл программы
while (1) continue;
}
/ / Calculate the frequency of the inverse of the period. frequency = (unsigned long) 8000000 / (Unsigned long) ICR1; } else { / / Frequency less than 122 Hz frequency = 0; / / Reset the overflow flag counter TIFR & = ~ (1 << TOV1); } } int main () { / / Register the rising edge, the ratio of the frequency divider 1 TCCR1B = (1 << ICES1) | (1 << CS10); / / Enable interrupt-event TIMSK = (1 << TICIE1); / / Enable global interrupts sei (); / / Infinite loop program while (1) continue; } # Include <avr/io.h> int main () { / / Set the output terminal DDRB | = (1 << PIN5) | (1 << PIN6); / / Outputs A and B during the comparison low / / Mode "Fast PWM", a frequency divider 8 TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11); TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11); / / The greatest value of the counter. Formula: / / TOP = 8 MHz / 8/50 Hz ICR1 = 20000; / / The half-life of the first motor 1 ms, 2 ms second OCR1A = 1000; OCR1B = 2000; / / Infinite loop program while (1) continue; }