Include 'M64DEF.INC'
ORG 0X0000
JMP main
ORG 0X000A
JMP EXT_INT4_ISR
ORG 0X0050

main:
LDI R16,low(RAMEND)
OUT SPL,R16
LDI R16,high(RAMEND)
OUT SPH,R16
LDI R16,0X01
OUT EICRB,R16 
LDI R16,0X10
OUT EIMSK,R16
LDI R16,0X00
OUT DDRA,R16
LDI R16, 0X0FF
OUT DDRB,R16
LDI R17,0 ; مشخص کردن لبه بالا رونده و پایین رونده
LDI R21,0X00
SEI

main_loop:
IN R20,PINA
COM R20 
OUT PORTB,R20
JMP main_loop

JMP EXT_INT4_ISR:
CPI R17,0
BREQ LOW
OUT PORTB,R21
SBI PORTB,0
SBI PORTB,1
SBI PORTB,2
SBI PORTB,3
SBI PORTB,4
SBI PORTB,5
SBI PORTB,6
SBI PORTB,7
CLR R17
RETI

LOW:
COM R20
OUT PORTB,R20
SER R17
RETI
