Спойлер
Код: Выделить всё
#include <tiny13.h>
#include <delay.h>
unsigned int m_sec=0x00;//переменная мсек
unsigned int tim=0x00; //таймер
unsigned char min=0x00;//переменная мин
unsigned char hour=0x00;//переменная час
unsigned char count=0x00;
unsigned int counter=0x00;
// Timer 0 output compare A interrupt service routine
interrupt [TIM0_COMPA] void timer0_compa_isr(void) //прерывания по совпадению
{
m_sec++; //переменная 1/100 секунды увеличивается
counter++;
}
// Timer 0 output compare B interrupt service routine
interrupt [TIM0_COMPB] void timer0_compb_isr(void)
{
// Place your code here
}
void reset() //обнулення змінних
{
m_sec=0;min=0;hour=0;tim=0;
}
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port B initialization
// Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out
// State5=T State4=P State3=P State2=0 State1=0 State0=0
PORTB=0x18;
DDRB=0x07;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 9,375 kHz
// Mode: CTC top=OCR0A
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x02;
TCCR0B=0x05;
TCNT0=0x00;
OCR0A=0x5D;
OCR0B=0x00;
// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x00;
MCUCR=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x0C;
// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;
DIDR0=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
/*ТАЙМЕР ВИКЛЮЧЕННЯ ФІЛЬТРА*/
if(!PINB.3){PORTB.2=1;}
if(counter==100){count++;counter=0;}
if(count==10){PORTB.2=0;count=0;}
/*ГЕНЕРАЦІЯ ХВИЛИН І ГОДИН*/
if(m_sec==3000){tim++;} //30-секундний таймер для автокормушки
if(m_sec==6000){m_sec=0;min++;} //1 хвилина
if(min==60){min=0; hour++;} //1 година
/*КОРМУШКА*/
//запуск автоматичної кормушки на 30 секунд
if(hour==0&min==0&tim==0){PORTB.0=1;tim=0;}
else{PORTB.0=0;}
/*СВІТЛО*/
if(hour==0){PORTB.1=1;}//включення світла одразу після запуску
if(hour==4){PORTB.1=0;}//виключення світла через 4 години
if(hour==24){hour=0;} //24 години
/*ОБНУЛЕННЯ ТАЙМЕРА*/
if(!PINB.4){reset();} //обнулення таймера
}
}


