; ; This simple program uses interrupts and targets the atmega328P. It configures ; and enables both Int0 and Int1. The sense of both interrupts is configured ; to be rising-edge. Be sure to consult the ATmega328P reference for details. ; ; ; Some equates to associate names with numbers ; .equ _spl = 0x5d .equ _ddrd = 0x2a .equ _portd = 0x2b .equ _mcucr = 0x55 .equ _eimsk = 0x3d .equ _eicra = 0x69 rjmp entry nop rjmp isr_0 nop rjmp isr_1 nop .org 0x60 isr_0: add r17,r1 reti .org 0x70 isr_1: add r18,r1 reti .org 0x80 ; was 0x74, 0xc8 bumps up against 0x100 threshold. entry: com r1 neg r1 ; r1 = 1 ldi r16,0 ldi r17,0 ldi r18,0 call InitInt0 call InitInt1 ; mdw: do this manually in the simulator ; sei ; enable interrupts sink: add r16,r1 rjmp sink InitInt0: push r24 lds r24,_ddrd ; load DDRD andi r24,0xfb ; clear PD2 pin sts _ddrd,r24 ; write back to DDRD lds r24,_portd ; load PORTD ori r24,0x04 ; enable pullup for PORTD[2] sts _portd,r24 ; write back to PORTD ; this sets int0 to trigger on rising edge... lds r24,_eicra ; load EICRA ori r24,0x03 ; enable isc00,isc01 sts _eicra,r24 ; write back to EICRA lds r24,_eimsk ; load EIMSK ori r24,0x01 ; enable INT0 in EIMSK sts _eimsk,r24 ; write back to EIMSK pop r24 ret InitInt1: push r24 lds r24,_ddrd ; load DDRD andi r24,0xf7 ; clear PD3 pin sts _ddrd,r24 ; write back to DDRD lds r24,_portd ; load PORTD ori r24,0x08 ; enable pullup for PORTD[3] sts _portd,r24 ; write back to PORTD ; this sets int0 to trigger on rising edge... lds r24,_eicra ; load EICRA ori r24,0x0c ; enable isc10,isc11 sts _eicra,r24 ; write back to EICRA lds r24,_eimsk ; load EIMSK ori r24,0x02 ; enable INT1 in EIMSK sts _eimsk,r24 ; write back to EIMSK pop r24 ret