Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ДИПЛОМНИЙ ПРОЕКТ / Додатки2003 ворд / дод К (Обов'язковий) Лістинг програми. Плакат

.doc
Скачиваний:
42
Добавлен:
18.03.2016
Размер:
34.82 Кб
Скачать

Додаток К(обов’язковий). Лістинг програми

#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)))

{

// 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

OCR1A = 1000;

OCR1B = 2000;

 

// Infinite loop program

while (1) continue;

}