[an error occurred while processing this directive]
Например, так
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено _Bill 23 января 2006 г. 16:58
В ответ на: Блин, не могу разобраться с таймером0 у меги 8515L... Помогите пожалуйста... Как сделать, хотя бы элементарную задержку... Включать-то таймер вроде написано как , а как потом просигнализировать, что он отсчитал и надо, к примеру, инкреминтировать какую-нить переменную... отправлено monofin 23 января 2006 г. 16:50


/* Constant definitions */

#define _1_SEC 1000000L // The number of uSs in 1S

#define PRESCALE0 256 // Timer0 prescaler value
#define PERIOD0 2500 // Timer0 overflow interrupt period (2.5 mS)
#define TIMER0_VALUE 256 - (PERIOD0 / ((_1_SEC / (FOSC / PRESCALE0))))

#define PRESCALE1 64 // Timer1 prescaler value
#define PERIOD1 500UL // Timer1 compare match interrupt period (0.5 mS)
#define OCR1_VAL (PERIOD1 / ((_1_SEC / (FOSC / PRESCALE1))))

//
// Static variable locations
//
static struct {
char _20mS; // 20 mS interval counter
char _100mS; // 0.1 S interval counter
}
intervals;
//
// ** InitTimers -- the function initiates MCU "on-board" timers
//
void InitTimers(void)
{
TCNT0 = TIMER0_VALUE; // Preload Timer0
TCNT1 = 0; // and Timer1
TCCR0 = 0x04; // Run Timer0
OCR1A = OCR1_VAL; // Load Timer1 compare match regicter
TCCR1A = 0; // and run the timer
TCCR1B = 0x0B; //
intervals._20mS = 0; // Reset counter
TIMSK = (1< _SEI(); // and go
}
//
// ***** Timer interrupt handlers *****
//
// ** Timer0 overflow interrupt handler
//
#pragma vector = TIMER0_OVF_vect
__interrupt void Timer0_Int(void)
{
TCNT0 = TIMER0_VALUE; // Reload Timer0
IntFlags |= TIMER0_BIT; // Set the flags
if (!(++intervals._20mS & 0x07)) // 20 mS interval
{ //
if (Mode & DELAY_BIT) // Reatart delay is doing
{ //
if (++intervals._100mS >= 5) // 100 mS interval is over
{ //
intervals._100mS = 0; // Clear counter
IntFlags |= _0_1_S_BIT; // Set the flag
} //
} //
IntFlags |= BUTTON_BIT; // Set the flag to buttons polling time
IntFlags |= DISPLAY_BIT; // Set the flag to display coounter
if (!(intervals._20mS & 0x7F))
{
if (Mode & PASWRD_BIT) // Password time-out
{ //
if (++TimoutCnt >= PSWD_TIM) // Time-out
IntFlags |= TIMOUT_BIT; //
}
IntFlags |= _320MS_BIT; // Set the flag
}
}
}


Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 
NoIX ключ Запомнить

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание

E-mail: info@telesys.ru