; ; Lab1-b assembler program ; .include"m8515def.inc"; include the ATMEGA8515(L) definitions file .org $000 rjmp RESET .org $007; set start address to Timer 0 overflow rjmp ISRTIME ; jump if timer0 overflows .def outval = r16; labelling regisers .def temp = r17; .def counter = r18; RESET: ; Initialise the stack pointer (standard method) ldi temp,low(RAMEND) ; lower half outSPL,temp ldi temp,high(RAMEND) ; upper half outSPH,temp ; set up portb ser temp outDDRB, temp ; set all pins of PORTB as outputs ldi outval, 0xAA; set to zero outPORTB, outval ; output to port B ; initialize timer 0 ldi temp, 0x05 outTCCR0, temp ; set timer 0 prescaling to lowest /1024 clr temp ; clear all bits outTCNT0, temp ; clear the timer ; setup timer 0's overflow interrupt in temp, TIMSK; load Timer Interrupt Mask Register sbr temp, 1<<TOIE0 ; set the timer 0 overflow interrupt enable bit outTIMSK, temp ; save Timer Interrupt Mask Register ldi counter, 0x04 sei; enable interrupts LOOP: ; do nothing, just loop forever(waiting for timer0 overflow) rjmp LOOP ISRTIME: ; interrupt service routine ; is executed every 2^16 pre-scaled cycles dec counter cpi counter, 0x00 brne BACK com outval ; Toggle ODD and EVEN Pins outPORTB, outval ; output to port B ldi counter, 0x04 BACK: reti; return from interrupt (different to normal return)