Author: Not specified | Language: asm |
Description: Not specified | Timestamp: 2017-09-25 00:07:41 +0000 |
View raw paste | Reply |
.include "m328def.inc"; include library for the AVR ATmega328 microcontroller
.org 0x0000
RJMP begin; jump to begin
.org 0x0002; address of enternal interrupt through pin INT0
RJMP EXT_INT0; jump to the ISR code 'EXT_INT0' when external interrupt is read through the pin INT0
.org 0x0034; sets initial program address at 0x0034
begin: SEI; enables interrupt bit
LDI R16,low(RAMEND); loads the low value of RAMEND into a register
OUT SPL,R16; sets stack pointer SPL
LDI R16,high(RAMEND); loads the high value of RAMEND into a register
OUT SPH, R16; sets stack pointer SPH
LDI R16, 0x02
STS 0x69, R16; sets the EICRA to generate interrupt on the falling edge of INT0
LDI R16, 0x01
STS 0x3D, R16; sets the EIMSK to enable interrupt through pin INT0
LDI R16,0xFB
OUT DDRD, R16; sets DDRD as 0xFB to set all pins of PORTD to output and pin 2 to input
looper: LDI R16,0x80
OUT PORTD, R16; sets pin 7 of PORTD to high
RCALL Delay; calls a subroutine starting at 'Delay' to create a delay of a second while the LED is on
LDI R16,0x04
OUT PORTD, R16; sets all pins of PORTD except pin 2 to low
RCALL Delay; calls a subroutine starting at 'Delay' to create a delay of a second while the LED is off
RJMP looper; jumps back to 'looper' to the next iteration of the loop
EXT_INT0:LDI R16,0x84; starts the ISR
OUT PORTD, R16; sets pins 7 and 2 of PORTD to high
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is on during the ISR
LDI R16,0x04
OUT PORTD, R16; sets all pins of PORTD except pin 2 to low
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is off during the ISR
LDI R16,0x84
OUT PORTD, R16; sets pins 7 and 2 of PORTD to high
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is on during the ISR
LDI R16,0x04
OUT PORTD, R16; sets all pins of PORTD except pin 2 to low
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is off during the ISR
RETI; Stops the ISR to return to the original task
Delay: LDI R17, 0x99; defines the starting of the subroutine loop with the looping variable at 0x99 (=153)
loop: RCALL Delay2; calls a nested subroutine 'Delay2'
DEC R17; decreases the looping value stored in the register
BRNE loop; if value at R17 is not zero, jumps back to 'loop' else continues
RET; returns to address where subroutine was called from
Delay_Int:LDI R17, 0x33; defines the starting of the subroutine loop with the looping variable at 0x33 (=51)
loopint: RCALL Delay2; calls a nested subroutine 'Delay2'
DEC R17; decreases the looping value stored in the register
BRNE loopint; if value at R17 is not zero, jumps back to 'loopint' else continues
RET; returns to address where subroutine was called from
Delay2: LDI R18, 0xFF; defines the starting of the subroutine loop with the looping variable at 0xFF (=1255)
loop2: RCALL Delay3; calls a nested subroutine 'Delay3'
DEC R18; decreases the looping value stored in the register
BRNE loop2; if value at R18 is not zero, jumps back to 'loop2' else continues
RET; returns to address where subroutine was called from
Delay3: LDI R19, 0xFF; defines the starting of the subroutine loop with the looping variable at 0xFF (=255)
loop3: DEC R19; decreases the looping value stored in the register
BRNE loop3; if value at R19 is not zero, jumps back to 'loop3' else continues
RET; returns to address where subroutine was called from
.org 0x0000
RJMP begin; jump to begin
.org 0x0002; address of enternal interrupt through pin INT0
RJMP EXT_INT0; jump to the ISR code 'EXT_INT0' when external interrupt is read through the pin INT0
.org 0x0034; sets initial program address at 0x0034
begin: SEI; enables interrupt bit
LDI R16,low(RAMEND); loads the low value of RAMEND into a register
OUT SPL,R16; sets stack pointer SPL
LDI R16,high(RAMEND); loads the high value of RAMEND into a register
OUT SPH, R16; sets stack pointer SPH
LDI R16, 0x02
STS 0x69, R16; sets the EICRA to generate interrupt on the falling edge of INT0
LDI R16, 0x01
STS 0x3D, R16; sets the EIMSK to enable interrupt through pin INT0
LDI R16,0xFB
OUT DDRD, R16; sets DDRD as 0xFB to set all pins of PORTD to output and pin 2 to input
looper: LDI R16,0x80
OUT PORTD, R16; sets pin 7 of PORTD to high
RCALL Delay; calls a subroutine starting at 'Delay' to create a delay of a second while the LED is on
LDI R16,0x04
OUT PORTD, R16; sets all pins of PORTD except pin 2 to low
RCALL Delay; calls a subroutine starting at 'Delay' to create a delay of a second while the LED is off
RJMP looper; jumps back to 'looper' to the next iteration of the loop
EXT_INT0:LDI R16,0x84; starts the ISR
OUT PORTD, R16; sets pins 7 and 2 of PORTD to high
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is on during the ISR
LDI R16,0x04
OUT PORTD, R16; sets all pins of PORTD except pin 2 to low
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is off during the ISR
LDI R16,0x84
OUT PORTD, R16; sets pins 7 and 2 of PORTD to high
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is on during the ISR
LDI R16,0x04
OUT PORTD, R16; sets all pins of PORTD except pin 2 to low
RCALL Delay_Int; calls a subroutine starting at 'Delay' to create a delay of a third of a second while the LED is off during the ISR
RETI; Stops the ISR to return to the original task
Delay: LDI R17, 0x99; defines the starting of the subroutine loop with the looping variable at 0x99 (=153)
loop: RCALL Delay2; calls a nested subroutine 'Delay2'
DEC R17; decreases the looping value stored in the register
BRNE loop; if value at R17 is not zero, jumps back to 'loop' else continues
RET; returns to address where subroutine was called from
Delay_Int:LDI R17, 0x33; defines the starting of the subroutine loop with the looping variable at 0x33 (=51)
loopint: RCALL Delay2; calls a nested subroutine 'Delay2'
DEC R17; decreases the looping value stored in the register
BRNE loopint; if value at R17 is not zero, jumps back to 'loopint' else continues
RET; returns to address where subroutine was called from
Delay2: LDI R18, 0xFF; defines the starting of the subroutine loop with the looping variable at 0xFF (=1255)
loop2: RCALL Delay3; calls a nested subroutine 'Delay3'
DEC R18; decreases the looping value stored in the register
BRNE loop2; if value at R18 is not zero, jumps back to 'loop2' else continues
RET; returns to address where subroutine was called from
Delay3: LDI R19, 0xFF; defines the starting of the subroutine loop with the looping variable at 0xFF (=255)
loop3: DEC R19; decreases the looping value stored in the register
BRNE loop3; if value at R19 is not zero, jumps back to 'loop3' else continues
RET; returns to address where subroutine was called from
View raw paste | Reply |