LED Blink in assembly with timer1 output compare interrupt not working I was trying to have some fun with avr-assembly on my arduino and I tried the following codes to blink my LED
first I tried the ISR approach and when It didn't work I tried the CTC mode one,
both codes are listed respectively. on the first one the LED lightsup and stay that way (no blinking) on the second one it just stays off
one more thing to note is on trying to load OCR1AL first The led would blink nicely if my hand got near PORTD pins for some reason,
I guessed it's some grounding problem and It's fixed when I pulled high all PORTD pins and it disappeared completely when I figured out that I need to load (the high byte) OCR1AH first
.nolist
.include &quot;m328Pdef.inc&quot; 
.list

.org    0x0000
jmp     Init


.org    0x0016
jmp     TIMER1_COMPA

.EQU    LED_PIN = PB1

Init:
    ;ldi    r16, 255
    ;out        DDRD, r16
    ;out    PORTD, r16

    ;First configure The led pin as output and initilize it to high
    sbi     DDRB, LED_PIN
    sbi     PORTB, LED_PIN

    ;Second Enable Global Interrupts
    sei

    ;Enable the Output compare Interrupt in the TIMSK1 Register
    ldi     r16, 0b00000010 
    sts     TIMSK1, r16

    ; Reset the TCCR1A 
    ldi     r16, 0b00000000
    sts     TCCR1A, r16

    ; Set the prescalar to 256 in the Timer Control 1B register
    ldi     r16, 0b00000111 
    sts     TCCR1B, r16

    ;Now load the value for Output compare register 31250 or   01111011 00100000  or 15625 =  00111101 00001001
    ldi     r16, 0b00111101
    ldi     r17, 0b00001001 
    sts     OCR1AH, r16
    sts     OCR1AL, r17


LOOP:

    rjmp    LOOP

TIMER1_COMPA:
    ;First Reset the coutner 
    ldi     r16, 0
    sts     TCNT1H, r16
    sts     TCNT1L, r16

    ;Second Toggle the Pin (LED) state
    sbi     PINB, LED_PIN

    reti




CTC:
.nolist
.include &quot;m328Pdef.inc&quot; 
.list

.org    0x0000
jmp     Init


.org    0x0016
jmp     TIMER1_COMPA

.EQU    LED_PIN = PB1

Init:
    ;ldi    r16, 255
    ;out        DDRD, r16
    ;out    PORTD, r16

    ;First configure The led pin as output and initilize it to high
    sbi     DDRB, LED_PIN
    sbi     PORTB, LED_PIN

    ;Second Enable Global Interrupts
    sei

    ;Enable the Output compare Interrupt in the TIMSK1 Register
    ldi     r16, 0b00000010 
    sts     TIMSK1, r16

    ; Reset the TCCR1A 
    ldi     r16, 0b01000000
    sts     TCCR1A, r16

    ; Set the prescalar to 256 in the Timer Control 1 registers
    ldi     r16, 0b00001111 
    sts     TCCR1B, r16

    ;Now load the value for Output compare register 31250 or   01111011 00100000  or 15625 =  00111101 00001001
    ldi     r16, 0b00111101
    ldi     r17, 0b00001001 
    sts     OCR1AH, r16
    sts     OCR1AL, r17


LOOP:
    rjmp    LOOP

TIMER1_COMPA:
    ;First Reset the coutner 
    ;ldi    r16, 0
    ;sts    TCNT1H, r16
    ;sts    TCNT1L, r16

    ;;Second Toggle the Pin (LED) state
    ;sbi        PINB, LED_PIN

    reti
I am not set up to test your code right now, perhaps later.  But:
    ; Set the prescalar to 256 in the Timer Control 1B register
    ldi     r16, 0b00000111 
    sts     TCCR1B, r16

When set to ones, the low order three bits of TCCR1B, select an external clock source at the T1 pin, for clocking on a rising edge.  Probably what's happening is that when you finger is near enough the T1 pin you are capacitively coupling mains frequency to it causing it to tick.
/256 prescaler would have 100 in the lower three bits.
If I manage to get a proper environment up to test your code, I'll look into it a bit more thoroughly.