AVR Assembler, Blink LED, 8-bit Timer/Counter0

AVR Assembler, Blink LED, 8-bit Timer/Counter0
Çeşme:
http://www.instructables.com/id/Command-Line-Assembly-Language-Programming-for-Ard-2/
  1. Arduino UNO
.nolist .include "../m328Pdef.inc" .list ;============== ; Declarations: .def temp = r16 .def overflows = r17 .def coin = r18 .org 0x0000 ; memory (PC) location of reset handler rjmp start ; jmp costs 2 cpu cycles and rjmp costs only 1 ; so unless you need to jump more than 8k bytes ; you only need rjmp. Some microcontrollers therefore only ; have rjmp and not jmp .org 0x0020 ; memory location of Timer0 overflow handler rjmp overflow_handler ; go here if a timer0 overflow interrupt occurs start: ldi coin, 0xff ldi temp, (1<<CS02)|(1<<CS00) out TCCR0B, temp ; set the Clock Selector Bits CS00, CS01, CS02 to 101 ; this puts Timer Counter0, TCNT0 in to FCPU/1024 mode ; so it ticks at the CPU freq/1024 ldi temp, (1<<TOIE0) sts TIMSK0, temp ; set the Timer Overflow Interrupt Enable (TOIE0) bit ; of the Timer Interrupt Mask Register (TIMSK0) sei ; enable global interrupts -- equivalent to "sbi SREG, I" clr temp out TCNT0, temp ; initialize the Timer/Counter to 0 sbi DDRB, 5 ;====================== loop: nop rjmp loop overflow_handler: inc overflows cpi overflows, 50 brne PC+3 clr overflows rcall togglebit sbrs coin, 0 cbi PORTB, 5 sbrc coin, 0 sbi PORTB, 5 reti togglebit: sbrc coin, 0 rjmp PC+3 sbrs coin, 0 rjmp PC+3 andi coin, 0xfe rjmp PC+2 ori coin, 0x01 ret ;overflow_handler: ; inc overflows ; cpi overflows, 20 ; brne PC+3 ; clr overflows ; com coin ; cpi coin, 0xff ; brne PC+2 ; out PORTB, coin ; cpi coin, 0x00 ; brne PC+2 ; out PORTB, coin ; reti