;Written by Peter Averill 9-5-99
;Test program to demonstrate reading swithes
;Port 1 needs to be connected to eight leds
;Port 3.2 needs to be connected to a switch
;Original program was tested using Dontronics boards
;DT004, DT104 and DT203
;
$mod2051                
		DSEG AT 0020H

		ORG     0020H           ; stack origin
stack:          DS      0020H           ; stack depth


		CSEG

		ORG     0000H           ; power on/reset vector
		jmp     on_reset

		ORG     0003H           ; external interrupt 0 vector
		reti                    ; undefined

		ORG     000BH           ; timer 0 overflow vector
		reti                    ; undefined

		ORG     0013H           ; external interrupt 1 vector
		reti                    ; undefined

		ORG     001BH           ; timer 1 overflow vector
		reti                    ; undefined

		ORG     0023H           ; serial I/O interrupt vector
		reti                    ; undefined

		ORG     0040H           ; begin constant data space



		ORG     00E0H           ; begin code space
		USING   0               ; register bank zero
on_reset:
		mov     IE, #0          ; deactivate all interrupts

		mov     p1, #0          ; write zeros to displays
		mov     a, #01h
		setb	p3.2
back:           
		mov     p1, a           ;
		           
		
		push    acc
		mov     a, #0ffh
back2:		jb	p3.2,back2
		call    delay_ms        
		call    delay_ms
;		call    delay_ms
		pop     acc
				
		rl      a
		jmp     back



delay_ms:

	; Delay for approximately one millisecond times the value in A.
	; All registers preserved, including flags.

		push    psw
		push    acc
		push    b

		mov     b, #0
	ddm:
		djnz    b, $            ; 512 uS @ 12 MHz
		djnz    b, $            ; 512 uS @ 12 MHz
		djnz    acc, ddm

		pop     b
		pop     acc
		pop     psw
		ret


		END

