External Interrupt ATMEGA328
Quote from Ragmar on October 13, 2024, 1:11 pmHello, everyone!
I need help with External Interrupt (INT0). I tried a simple circuit design to test this feature. When PD2 is activated, the flag INTF0 is correctly set, but Program Counter doesn't load interrupt vector value (0x0002). My SIMULIDE version is 1.1.0.
.ORG 0x0000 RJMP CONFIGURACAO .ORG 0x0002 EINT0: RCALL TRATAMENTO_INT0 RETI .ORG 0x0034 CONFIGURACAO: LDI R16,0b11101011 OUT DDRD,R16 CLR R16 OUT PORTD,R16 LDI R16,0b00000011 ;<== RISING EDGE OF INT0 STS EICRA,R16 LDI R16,0b00000001 OUT EIMSK,R16 SEI PRINCIPAL: RJMP PRINCIPAL SALVAR_STATUS: IN R17,SREG RET CARREGAR_STATUS: OUT SREG,R17 RET PAUSAR_INTERRUPCAO: CLI RET PAUSAR_CONTAGEM: CLR R16 OUT TCCR0B,R16 OUT TCNT0,R16 RET TRATAMENTO_INT0: RCALL SALVAR_STATUS RCALL PAUSAR_INTERRUPCAO IN R16,PORTD LDI R18,0x00000001 EOR R16,R18 OUT PORTD,R16 RCALL CARREGAR_STATUS RET
Hello, everyone!
I need help with External Interrupt (INT0). I tried a simple circuit design to test this feature. When PD2 is activated, the flag INTF0 is correctly set, but Program Counter doesn't load interrupt vector value (0x0002). My SIMULIDE version is 1.1.0.
.ORG 0x0000
RJMP CONFIGURACAO
.ORG 0x0002 EINT0:
RCALL TRATAMENTO_INT0
RETI
.ORG 0x0034 CONFIGURACAO:
LDI R16,0b11101011
OUT DDRD,R16
CLR R16
OUT PORTD,R16
LDI R16,0b00000011 ;<== RISING EDGE OF INT0
STS EICRA,R16
LDI R16,0b00000001
OUT EIMSK,R16
SEI
PRINCIPAL:
RJMP PRINCIPAL
SALVAR_STATUS:
IN R17,SREG
RET
CARREGAR_STATUS:
OUT SREG,R17
RET
PAUSAR_INTERRUPCAO:
CLI
RET
PAUSAR_CONTAGEM:
CLR R16
OUT TCCR0B,R16
OUT TCNT0,R16
RET
TRATAMENTO_INT0:
RCALL SALVAR_STATUS
RCALL PAUSAR_INTERRUPCAO
IN R16,PORTD
LDI R18,0x00000001
EOR R16,R18
OUT PORTD,R16
RCALL CARREGAR_STATUS
RET
Quote from arcachofo on October 15, 2024, 12:32 pmHi.
Seems that Stack Pointer is not initiallized in Simulide.
Until this issue is fixed you can initialize it in your CONFIGURACAO routine:;Initialise stack ldi SysValueCopy,high(RAMEND) out SPH, SysValueCopy ldi SysValueCopy,low(RAMEND) out SPL, SysValueCopy
Hi.
Seems that Stack Pointer is not initiallized in Simulide.
Until this issue is fixed you can initialize it in your CONFIGURACAO routine:
;Initialise stack
ldi SysValueCopy,high(RAMEND)
out SPH, SysValueCopy
ldi SysValueCopy,low(RAMEND)
out SPL, SysValueCopy