Спойлер
/*****************************************************This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 16.11.2013
Author :
Company :
Comments:
Chip type : ATtiny13
AVR Core Clock frequency: 9,600000 MHz
Memory model : Tiny
External RAM size : 0
Data Stack size : 16
*****************************************************/
#include <tiny13.h>
unsigned int counter;
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
if(++counter > 732) PORTB.4= 0; // если истекли 20 сек
}
// Declare your global variables here
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=Out Func3=In Func2=Out Func1=Out Func0=Out
// State5=T State4=0 State3=T State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0x17;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 9,375 kHz
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x05;
TCNT0=0x00;
OCR0A=0x00;
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=0x02;
// 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) // если вход == 1
{
counter= 0; // сбрасываем счетчик
PORTB.4= 1; // устанавливаем порт в "1"
}
};
}
принцып такой после того как таймер благополучно осчитал свое время 20 сек и если на pinb3 за это время не появилась лог 1 то таймер должен уснут. а при появлении лог1 на этом пине должен пробудить его . или пробуждать придется pinb0?? так как на тини 13 там находится INTo, кажется она вызывает из глубокого сна.