*************************************************
*						*
*     Program:	Port C Switch Inputs		*
*						*
*     Name   :	pcievbu.src			*
*						*
*     Date   :	28 Mar 2001			*
*						*
*     By     :	Steven J. Dombrowski		*
*						*
*						*
*     This program reads all 8 switches on	*
* the M68HC11EVBU and continuously updates all	*
* readings.  Program loads in EEPROM at B600.   *
* Swmsgs load into onboard RAM.  To download    *
* into EEPROM, set $102b to 35 (300baud).  Wait *
* until done prompt.  Reset EVBU back to 9600.  *
*     						*
*						*
*     To execute this program type G B600 <CR>	*
*						*
*************************************************
*			      *
*  program origin and equates *
*			      *
*******************************
	 org $B600
outcrlf  equ $ffc4
outstrg0 equ $ffca
outa	 equ $ffb8
portc    equ $1003
ddrc     equ $1007
swmsg1	 equ $0000
swmsg2	 equ $0100
	ldx #swmsg1
	ldy #table1
	ldab #$29
loop1	ldaa 0,y
	staa 0,x
	inx
	iny
	decb
	cmpb #0
	bne loop1
	ldx #swmsg2
	ldy #table2
	ldab #$29
loop2	ldaa 0,y
	staa 0,x
	inx
	iny
	decb
	cmpb #0
	bne loop2
************************
*		       *
* Introductory message *
*		       *
************************
	ldaa #$1a		* clear screen
	jsr outa
************************
*		       *
* Main part of program *
*		       *
************************
	ldaa #$00		*set bits 0-7 of
	staa ddrc		*portc as input
start	ldaa portc
	anda #1
	jsr  rh 	
	staa swmsg1+13	* output to screen
	ldaa portc
	anda #2
	lsra
	jsr  rh 	
	staa swmsg1+21	* output to screen
	ldaa portc
	anda #4
	lsra
	lsra
	jsr rh
	staa swmsg1+29	* output to screen
	ldaa portc
	anda #8
	lsra
	lsra
	lsra
	jsr  rh 	
	staa swmsg1+37	* output to screen
	ldaa portc
	anda #$10
	lsra
	lsra
	lsra
	lsra
	jsr rh
	staa swmsg2+13	* output to screen
	ldaa portc
	anda #$20
	lsra
	lsra
	lsra
	lsra
	lsra
	jsr  rh 	* convert right nibble to ascii
	staa swmsg2+21	* output to screen
	ldaa portc
	anda #$40
	lsra
	lsra
	lsra
	lsra
	lsra
	lsra
	jsr rh
	staa swmsg2+29	* output to screen
	ldaa portc
	anda #$80
	lsra
	lsra
	lsra
	lsra
	lsra
	lsra
	lsra
	jsr  rh 	* convert right nibble to ascii
	staa swmsg2+37	* output to screen
	ldaa #20	* indent 20 spaces
	jsr spaces
	ldx #swmsg1	* display sw1-4
	jsr outstrg0
	jsr bkspc	* update switch readings
	jsr outcrlf
	jsr outcrlf
	ldaa #20	* indent 20 spaces
	jsr spaces
	ldx #swmsg2	* display sw5-8
	jsr outstrg0
	jsr bkspc	* update switch readings
	ldaa #$0b	* go up 2 lines to ch1-4
	jsr outa
	jsr outa
	jmp start	* continue program
***********************************
*				  *
*  Subroutine to backspace cursor *
*				  *
***********************************
bkspc	ldy #$40
bkspc1 ldaa #$08
	jsr outa
	dey
	cpy #0
	bne bkspc1
	rts
*******************************
*			      *
* Subroutine to convert right *
* half of binary byte in acca *
* to an ascii character       *
*			      *
*******************************
rh	asla
	asla
	asla
	asla
	lsra
	lsra
	lsra
	lsra
	anda #$0f
	adda #$30
	cmpa #$39
	ble out1
	adda #$07
out1	rts
******************************************
*					 *
* Subroutine to skip lines on the screen *
*					 *
******************************************
lines	  jsr outcrlf
	  decb
	  cmpb #0
	  bne lines
	  rts
*******************************************
*					  *
* Subroutine to skip spaces on the screen *
*					  *
*******************************************
spaces	  tab
	  ldaa #$20
spaces2   jsr outa
	  decb
	  cmpb #0
	  bne spaces2
	  rts
******************************************************
*						     *
*		   Screen messages		     *
*						     *
******************************************************
table1 fcc 'reading PC0:    PC1:    PC2:    PC3:    '
       fcb 4
table2 fcc 'reading PC4:    PC5:    PC6:    PC7:    '
       fcb 4
