include 'M64DEF.INC'
ORG 0X0000
JMP main
ORG 0X0020
JMP TIMER0_ISR
ORG 0X0050
main: 
LDI R20,low(RAMEND)
OUT SPL,R20
LDI R20,high(RAMEND)
OUT SPH,R16
LDI R20,0X07
OUT TCCR0,R20 ; f=10.24MHz/1024=10KHz       1/10KHz= 0.1 msec     4msec/0.1msec=40    256-40=216
LDI R20,216
OUT TCNT0,R20
LDI R20,0X01
OUT TIMSK,R20
LDI R20,0X0FF
OUT DDRD,R20
CLR R21
CLR R22
SEI

loop:
JMP loop


TIMER0_ISR:
LDI R20,216
OUT TCNT0,R20
INC R22
INC R22
INC R22
INC R22
CPI R22,101
BRSH NEXT
INC R21
OUT PORTD,R21
RETI


NEXT:
CPI R22,201
BRSH NEXT1
DEC R21
OUT PORTD,R21
RETI


NEXT1:
CLR R21
CLR R22
RETI



