Code: Select all
Chip type : ATtiny13A
AVR Core Clock frequency: 1,200000 MHz
Memory model : Tiny
External RAM size : 0
Data Stack size : 16
*******************************************************/
#include <tiny13a.h>
#include <delay.h>
#define S1 PINB.3
#define S2 PINB.4
#define HL1 PORTB.2
#define HL2 PORTB.1
#define OFF 1
#define ON 0
#define HOLD 200 // время равно: секунда * 100
unsigned char counter1;
unsigned char counter2;
unsigned char trigger;
unsigned char blink;
void main(void)
{
DDRB= (0<<ddb5) | (0<<ddb4) | (0<<ddb3) | (1<<ddb2) | (1<<ddb1) | (0<<ddb0);
PORTB=(0<<portb5)| (1<<portb4)| (1<<portb3)| (0<<portb2)| (0<<portb1)| (0<<portb0);
ACSR=(1<<acd);
// Watchdog Timer Prescaler: OSC/64k
#pragma optsize-
WDTCR=(0<<wdtif) | (0<<wdtie) | (0<<wdp3) | (1<<wdce) | (1<<wde) | (1<<wdp2) | (0<<wdp1) | (1<<wdp0);
WDTCR=(0<<wdtif) | (0<<wdtie) | (0<<wdp3) | (0<<wdce) | (1<<wde) | (1<<wdp2) | (0<<wdp1) | (1<<wdp0);
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
while (1)
{
if(S1==OFF&&S2==OFF&&HL1==0&&trigger==0)
{
MCUCR=(1<<se)|(1<<sm1);
#asm("sleep") // засыпаем
}
if(S1==ON&&HL1==0)
{
if(counter1<200)counter1++;
else HL1=1;
}
if(S1==OFF)counter1=0;
if(S1==ON&&HL1==1&&counter1==0)HL1=0;
if(S2==ON&&trigger==0)
{
if(counter2<200)counter2++;
else trigger=1;
}
if(S2==OFF)counter2=0;
if(S2==ON&&trigger==1&&counter2==0)trigger=0;
if(trigger)
{
if(blink<40)blink++;
else blink=0;
if(blink<20)HL2=1;
else HL2=0;
}
else
{
blink=0;
HL2=0;
}
#asm("wdr")
delay_ms(10);
}
}