0% found this document useful (0 votes)
2 views4 pages

Sample

The document contains assembly code for an embedded system that sets up interrupt service routines (ISRs) for external interrupts INT0 and INT1, while also preparing PORTB for output. It initializes the data direction and output for LEDs and includes logic for handling the interrupts to display different LED patterns. The code is structured to handle up to three interrupts, although the ISR for INT2 is commented out.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Sample

The document contains assembly code for an embedded system that sets up interrupt service routines (ISRs) for external interrupts INT0 and INT1, while also preparing PORTB for output. It initializes the data direction and output for LEDs and includes logic for handling the interrupts to display different LED patterns. The code is structured to handle up to three interrupts, although the ISR for INT2 is commented out.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

.

org 0x00

rjmp RESET

.org 0X02

rjmp INT0_ISR

.org 0X04

rjmp INT1_ISR

//.org 0X06

//rjmp INT2_ISR

RESET:

ldi R16, 0xFF

out DDRB, R16 ; PORTB as output for BARLED

ldi R16, 0x00

out PORTB, R16

CBI DDRB,2

CBI DDRD,2

CBI DDRD,3

SBI PORTB,2

SBI PORTD,2

SBI PORTD,3

; Cấu hình ngắt ngoài INT0, INT1, INT2

ldi R16, (1<<INT0)|(1<<INT1)

out EIMSK, R16 ; Cho phép INT0, INT1, INT2

ldi R16, (1<<ISC01)|(1<<ISC11) ; Ngắt theo cạnh xuống

STS EICRA, R16


// ldi R16, (1<<ISC21) ; Cạnh xuống cho INT2

// STS EICRA, R16

sei

LDI R17,0

LDI R18,0

LDI R19,0

LOOP: RJMP LOOP

INT0_ISR:

LDI ZH,HIGH(LED0<<1)

LDI ZL,LOW(LED0<<1)

ADD ZL,R17

LDI R20,0

ADC ZH,R20

LPM R20,Z

OUT PORTB,R20

INC R17

CPI R17,4

BRNE KETTHUC0

LDI R17,0

KETTHUC0: RETI

LED0: .DB 0B11000000,0B00110000,0B00001100,0B00000011

INT1_ISR:
LDI ZH,HIGH(LED1<<1)

LDI ZL,LOW(LED1<<1)

ADD ZL,R18

LDI R21,0

ADC ZH,R21

LPM R21,Z

OUT PORTB,R21

INC R18

CPI R18,4

BRNE KETTHUC1

LDI R18,0

KETTHUC1: RETI

LED1: .DB 0B00000011,0B00001100,0B00110000,0B11000000

/*INT2_ISR:

LDI ZH,HIGH(LED2<<1)

LDI ZL,LOW(LED2<<1)

ADD ZL,R19

LDI R22,0

ADC ZH,R22

LPM R22,Z

OUT PORTB,R22

INC R19

BRNE KETTHUC2

LDI R19,0

KETTHUC2: RETI
LED2: .DB 0B00011000,0B00100100,0B01000010,0B10000001*/

You might also like