/************************************************** ***
Project : Human Motion detector
Version : 1
Author : SMH
Chip type : ATtiny13
Clock frequency : 9.600000 MHz
Memory model : Tiny
Data Stack size : 16
************************************************** ***/
#include <tiny13.h>
#include <delay.h>
unsigned char t;
unsigned char time_delay;
unsigned char time_reg;
unsigned char dip_read;
bit light;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
delay_ms(20);
if(PINB.1==0)
{
time_reg=0;
light=1;
}
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
if (light==1)
{
if (t==183) // 5 second delay
{
t=0;
time_reg++;
if (time_reg==time_delay) light=0;
}
t++;
}
}
// 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=In Func3=In Func2=Out Func1=In Func0=In
// State5=T State4=P State3=P State2=0 State1=T State0=T
PORTB=0x18;
DDRB=0x04;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 9.375 kHz
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x05;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x40;
MCUCR=0x02;
GIFR=0x40;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x02;
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/32k
// Watchdog Timer interrupt: Off
#pragma optsize-
WDTCR=0x1C;
WDTCR=0x0C;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Global enable interrupts
#asm("sei")
t=0;
light=1;
time_reg=0;
while (1)
{
dip_read=PINB;
dip_read=(dip_read&0x18)>>3;
switch (dip_read)
{
case 0:
time_delay=2;
break;
case 1:
time_delay=12;
break;
case 2:
time_delay=24;
break;
case 3:
time_delay=120;
break;
};
PORTB.2=light;
delay_ms(30);
#asm("wdr")
};
}
تو برنامه بالا از رله و دیب سوییچ استفاده شده
دوستان تو فهمیدن برنامه بالاموندم خواهشن کمک کنید!!!!!!!!!!!