;***************************************************************************
;* File Name		:mc_test1.asm
;* Title		:Microcontroller Test
;* Date	 		:28/03/97
;* Version 		:1.0
;* Target MCU		:AT90S1200
;* 
;* DESCRIPTION
;* Test of Timer0 Overflow and External Interrupt on AVR Evaluation Board 
;* Oscillator frequency CK is 4 MHz (T = 0.25 us)
;***************************************************************************

;***** Directives

.device at90s1200		; Device is AT90S1200
.nolist
.include "1200def.inc"
.list
.listmac

.def	temp 	= r16
.def	byte 	= r17
.def	reload	= r18

;***** Macros

.MACRO	SBIs_HR			; Set Bits in I/O Register 32 up
	in 	temp,@0
	ori 	temp, @1
	out 	@0, temp
.ENDMACRO

;***** Interrupt vector table

	rjmp	RESET		; Reset handle
	rjmp	EX_INT0		; External Interrupt0 handle
	rjmp	OVF0		; Overflow0 Interrupt handle
	reti			; Analog Comparator Interrupt handle

;***** Interrupt handlers

EX_INT0:swap	reload		; Rotate Reload 
	reti

OVF0:	out	PORTB, byte	; Output Bit Pattern
	rol	byte		; Rotate Bit Pattern
	out	TCNT0, reload	; Reload Timer/Counter0
	reti


;***** Main

RESET:	ldi	reload,$07	; Initialize Reload Value
	
	sec
	ldi	byte, $FE
	out	PORTB,byte	; Initialize PortB

	ser	temp
	out	DDRB,temp	; PORTB = all outputs

	ldi	temp, 0b00000101
	out	TCCR0, temp	; Prescaler CK/1024 => 256 us
	
	ldi	temp, TOV0<<1
	out	TIMSK, temp 	; T/C0 Interrupt Enable

	SBIs_HR	MCUCR,0b00000010; Interrupt on falling edge of INT0 

	SBIs_HR	GIMSK,0b01000000; External Interrupt0 Enable

	sei			; Global Interrupt Enable
	
loop:	rjmp 	loop		; Repeat forever
	

