;
; Ex1.asm  ---- Example program 1 for the MiniDRAGON (c)2002, EVBplus.com
;		Written by Wayne Chu
;
;     Function:	Reads 2-position DIP switch and 2 pushbutton switches
;		via analog port ATD0 and displays the results on the 7-segment
;               LED at port H
;		The LED is normally off.
;		When the sw1 is down the segment a is lit
;		When the sw2 is down the segment g is lit
;		When the sw3 is short the segment e is lit
;		When the sw4 is short the segment c is lit
;
; The switches are not software de-bounced for simplicity. The switches are
; software de-bounced in the TEST.ASM for better reliability.

SW1:	equ	$10		; AN4	
SW2:	equ	$08		; AN3	
SW3:	equ	$20		; AN5	
SW4:	equ	$40		; AN6	
;
#include        reg9s12.h
REGBLK:	equ	$0000
STACK:	equ	$2000

        org     $2000		; program code starts here
start:
	lds	#STACK
	ldx	#REGBLK
	clr	pth,x
	ldaa	#$ff
	staa	ddrh,x		; make port H an output port
	ldaa	#$ff		; enable the digital input buffer
	staa	atd0dien,x	; ATD0 port.
back:
	ldaa	portad0,x	; get AD0 value
	tab
	anda	#SW1		; test Sw1
	beq	sw1_down
	bclr	pth,x,$1	; clear segment a, bit 0 of port H
	tba			; get AD0 value.
	anda	#SW2		; test Sw2
	beq	sw2_down
	bclr	pth,x,$40	; clear segment g, bit 6 of port H
	tba			; get AD0 value.
	anda	#SW3		; test Sw3
	beq	sw3_down
	bclr	pth,x,$10	; clear segment e, bit 4 of port H
	tba			; get AD0 value.
	anda	#SW4		; test Sw4
	beq	sw4_down
	bclr	pth,x,$4	; clear segment c, bit 2 of port H
	jmp	back
;
sw1_down:			; turn on segment a, if sw1 is down
	bset	pth,x,$1	; bit 0
	jmp	back
	
sw2_down:			; turn on segment g, if sw2 is down
	bset	pth,x,$40	; bit 6
	jmp	back
	
sw3_down:			; turn on segment e, if sw3 is down
	bset	pth,x,$10	; bit 4
	jmp	back
	
sw4_down:			; turn on segment c, if sw4 is down
	bset	pth,x,$4	; bit 2
	jmp	back
  	end


