So I've a bit of problem that for the life of me, I cannot find an answer to or what may be happening.
I am using an ATtiny2313 which I have clocked at 20MHz using an external crystal. For clarity, I am building this using ASM because I need exact timing for this project.
When I enable SEI, the entire program just halts at that point except for the clock cycle immediately following the SEI command. Anything after that never happens. Also, if I run the program in Atmel Studio 6 with F5 to debug, adding a breakpoint on the first line immediately after SEI, will break the program. Anything after that, will not break the program (it never gets called).
There's three lines commented in the code explaining what is happening (or rather not happening).
To further explaining what I eventually want to achieve with this is to output a stable VGA signal. However, that is not the problem.
Thank you guys.
; ========================================================= ; == VGA Test == ; == Author: Jamison Jerving == ; == Date: August 4, 2013 == ; ========================================================= .org 0x0000 rjmp reset .org 0x0004 rjmp video ; ========================================================= ; == Called when a reset happens. == ; ========================================================= reset: ; Setup the stack pointer. ldi r16,low(ramend) out spl,r16 ; Enable Timer1 and WGM12 to count up to OCR1A. ldi r16,(1 << cs10 | 1 << wgm12) sts tccr1b,r16 ; Set the Output Compare Interrupt Enable A for Timer1. ldi r16,(1 << ocie1a) sts timsk,r16 ; Set OCR1A to count up to 65k ldi r16,low(65535) sts ocr1al,r16 ldi r16,high(65535) sts ocr1ah,r16 ; Setup Port B. ldi r16,0b0000_1111 out ddrb,r16 ; Enable Global Interrupts sei ; <--- All program execution, except the immediate next clock cycle, ; seems to stop after SEI is called. If I comment this line out, ; The program in main executes just fine. ; ========================================================= ; == Main Program Loop == ; ========================================================= ldi yl,0 ; With SEI enabled, adding a breakpoint here, the program breaks in debug. Any line after this never breaks. ldi yh,0 main: ; ON ldi r16,0 ; With SEI enabled, adding a breakpoint here, the program never seems to reach this line. cp yl,r16 cpc yh,r16 brne skip1 sbi portb,2 skip1: ; OFF ldi r16,low(32767) ldi r17,high(32767) cp yl,r16 cpc yh,r17 brne skip2 cbi portb,2 skip2: adiw yl,1 rjmp main ; ========================================================= ; == Video Interrupt Timer == ; ========================================================= video: ; Save the status register. in r16,sreg push r16 ldi xl,tcnt1l ldi xh,tcnt1h ; ON ldi r16,0 cp xl,r16 cpc xh,r16 brne skip3 sbi portb,3 skip3: ; OFF ldi r16,low(32767) ldi r17,high(32767) cp xl,r16 cpc xh,r17 brne skip4 cbi portb,3 skip4: ; Restore the status register. pop r16 out sreg,r16 reti