; ######################################################################################### ; # Indiana University # ; # Computer Science Department # ; # # ; # Program to demonstrate timer interrupts # ; # # ; # DESCRIPTION: # ; # # ; # Program to setup the timer and generate a 1Hz flashing "0" on the 7 segment display # ; # # ; # AUTHOR: # ; # Bryce Himebaugh (bhimebau@cs.indiana.edu) # ; # IUCS Staff # ; # 4/19/01 # ; # # ; ######################################################################################### SECTION code START: ; "START" label required (debugger) at beginning of code move.l #0x320,a0 ; address in vector table for vector 200, Timer interrupt move.l (a0),-(sp) ; save the current vector 200 handler on stack move.l #timer_interrupt,(a0) ; place the address of timer interrupt handler into vector table jsr init_timer ; initialize the registers for the timer ; %%% Replace with assignment 6 code %%% main_loop: nop nop nop nop nop bra main_loop ; loop here forever ; %%% End of Replace %%% ;### Restoration of original timer handler address move.l #0x320,a0 ; address in vector table for vector 200, Timer interrupt move.l (sp)+,(a0) ; restore the original timer interrupt vector clr.b d1 TRAP #15 ; exit to the system init_timer: ; The timer on the board is 24 bits wide. The timer is physically implemented ; with three 8 bit wide count registers. There are also three 8 bit wide preload registers. ; The timer counts with a period of 5.12uS. The timer counts down from the 24-bit preload value ; to zero and then reloads from the preload registers. ; ; Timer Registers (each is byte wide) ; 0xC0004F.L Timer Preload High Byte ; 0xC00053.L Timer Preload Middle Byte ; 0xC00057.L Timer Preload Low Byte ; 0xC0005F.L Timer Current Count High Byte ; 0xC00063.L Timer Current Count Middle Byte ; 0xC00067.L Timer Current Count Low Byte ; 0xC00047.L Timer Interrupt Vector Number - sets specific "user defined" vector for timer. ; 0xC00043.L Timer control - Lowest bit=1 -> timer on ; Lowest bit=0 -> timer off ; Timer is preloaded with 0x02FAF0 (195,312). 195,312 ticks * 5.12uS/tick = 1 second IRQ Rate ; For assignment #7, make IRQ rate = 1 millisecond (0.001 second) move.b #0x02,0xC0004F.L ; Timer Preload High Byte move.b #0xFA,0xC00053.L ; Timer Preload Middle Byte move.b #0xF0,0xC00057.L ; Timer Preload Low Byte move.b #0xC8,0xC00047.L ; Interrupt vector #200 generated by timer move.b #0xA1,0xC00043.L ; Timer control - countdown/reload mode, generate IRQ, counter on rts disp_7_seg: move.l a0,-(sp) lea seg_out_dat,a0 ; load the base address of the 7-seg data into a0 add.l d0,a0 move.b (a0),0xd00003.l; write the data at base+d0 -> offsets by d0 into the table move.l (sp)+,a0 rts timer_interrupt: ; Timer Interrupt Hander ; Must reset the timer status register to prevent re-entry into the IRQ on exit ; 0xC0006B.L Timer Status Register link a6,#0 ; preserve the entry stack pointer-4 in a6 (frame pointer) movem.l d0-d2/a0-a2,-(sp) ; save any regs that might be used move.b #0x01,0xC0006B.L ; reset the timer status register ; Replace with Assignment 7 Code move.l 6(A6),d0 ; Grab the calling PC from the stack andi.l #0x000F,d0 ; Clear all but the low nibble of d0 jsr disp_7_seg ; Jump to the display routine ; End Replacement ; cleanup movem.l (sp)+,d0-d2/a0-a2 ; restore the saved regs. unlk a6 ; restore the frame pointer (a6) rte ; return from exception, restores status of the machine seg_out_dat: dc.b 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98,0x88,0x83,0xC6,0xA1,0x86,0x8e