Include 'M64DEF.INC' 
ORG 0x0000 
JMP main 
ORG 0x0020 
JMP Timer0_ISR 
ORG 0x0014 
JMP Timer2_ISR 
ORG 0x0050 
main : LDI R16, low(RAMEND) 
OUT SPL, R16 
LDI R16, high(RAMEND) 
OUT SPH, R16 
LDI R16, 0x05
OUT TCCR2, R16 
LDI R16, 0x07 
OUT TCCR0, R16 
LDI R16, 56 
OUT TCNT0, R16 
LDI R16, 216 
OUT TCNT2, R16 
LDI R16, 0x41 
OUT TIMSK, R16 
LDI R16, 0x00 
OUT DDRA, R16 
SBI DDRB,5 
CBI PORTB.5
CLR R16 
CLR R17 
CLR R18 
CLR R20 
SEI 
Loop : JMP Loop

Timer0_ISR : 
LDI R16, 56
OUT TCNT0, R16
CALL EV_50ms
RETI


EV_50ms : 
INC R17
CPI R17, 100
BRNE EV_50end
IN R20, PINA
CLR R17
SBI PORTB, 5

EV_50end : RET

Timer2_ISR :
LDI R16, 216
OUT TCNT2, R16
CALL EV_10ms
RETI
EV_10ms :
INC R18
ANDI R20, 0x01
BRNE odd_A
LDI R19, 03
JMP next
odd_A : LDI R19, 38
next : CP R18, R19
BRNE EV_10end
LDI R16, 0x00
OUT TCCR2, R16
CBI PORTB, 5
CLR R18
EV_10end : RET
