;***************************************************************************
;* File Name		:timer0.asm
;* Title		:Square Wave output
;* Date	 		:23/08/97
;* Version 		:1.0
;* Target MCU		:AT90S1200
;* 
;* DESCRIPTION
;* Square Wave Generation of 1 kHz by Timer0 Overflow
;***************************************************************************

;***** Directives

.device at90s1200		; Device is AT90S1200
.nolist
.include "1200def.inc"
.list
.listmac

.def	temp 	= r16
.def	mask 	= r17
.def	reload	= r18

;***** Interrupt vector table

	rjmp	RESET		; Reset handle
	reti			; External Interrupt0 handle
	rjmp	OVF0		; Overflow0 Interrupt handle
	reti			; Analog Comparator Interrupt handle

;***** Interrupt handlers

OVF0:	in	temp, PORTB	; Input Bit Pattern
	eor	temp, mask	; Toggle PB0
	out	PORTB, temp	; Output PB0
	out	TCNT0, reload	; Reload Timer/Counter0
	reti


;***** Main

RESET:	ldi	mask, $01	; Initialize Mask Byte
	ldi	reload,$06	; Initialize Reload Value
	
	sbi	DDRB,PB0	; PB0 = output

	ldi	temp, 0b00000010
	out	TCCR0, temp	; Prescaler CK/8 => 2 us
	
	ldi	temp, TOV0<<1
	out	TIMSK, temp 	; T/C0 Interrupt Enable

	sei			; Global Interrupt Enable
	
loop:	rjmp 	loop		; Repeat forever
	

