Include 'M64DEF.INC' 
ORG 0x0000 
JMP main 
ORG 0X0002
JMP EXT_INT0_ISR
ORG 0X0004
JMP EXT_INT1_ISR
ORG 0x0020 
JMP Timer0_ISR 
ORG 0x0050 
main : LDI R16, low(RAMEND) 
OUT SPL, R16 
LDI R16, high(RAMEND) 
OUT SPH, R16 
LDI R16, 0x07 ; Prescaler =1024   4.096MHZ/1024=4KHZ    1/4KHZ=250usec         50msec/250usec=200      256-200=56
OUT TCCR0, R16
LDI R16, 56 
OUT TCNT0, R16 
LDI R16, 0x01 
OUT TIMSK, R16 
LDI R16,0X00
OUT DDRB,R16
LDI R16,0X0A
OUT EICRA,R16
LDI R16,0X03
OUT EIMSK,R16
CLR R18 ; for 1sec
CLR R19 ; for 10sec
CLR R20 ; for10sec
CLR R21
CLR R22
SEI

loop:
IN R17,PINB
JMP loop




Timer0_ISR:
LDI R16, 56 
OUT TCNT0, R16
CPI R21,1
BREQ stop
INC R18
CPI R18,20
BREQ PLUSE_ONE
RETI


PLUSE_ONE:
INC R17
RETI

stop:
CLR R18
CPI R22,1
BREQ NEXT1
INC R19
CPI R19,200
BREQ NEXT2
RETI


NEXT1 :
CLR R22
RETI

NEXT2:
CLR R21
RETI


EXT_INT0_ISR:
LDI R21,1
RETI

EXT_INT1_ISR
LDI R22,1
RETI


