*************************************************
*						*
*     Program:	8 channel A/D Input		*
*						*
*     Name   :	ADEVBU.SRC			*
*						*
*     Date   :	28 Mar 2001			*
*						*
*     By     :	Steven J. Dombrowski		*
*						*
*						*
*     This program scans all 8 A/D channels 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.  *						*
* 						*
* Since PE0 is also used to select the Buffalo  *
* monitor or EEPROM upon reset, make sure it is *
* set for 0.  After program execution, PE0 will *
* respond normally.				*
*						*
*     Only 4 channels can be read at one time.	*
*						*
*     To execute this program type G B600 <CR>	*
*						*
*************************************************
*			      *
*  program origin and equates *
*			      *
*******************************
	 org $B600
outcrlf  equ $ffc4
outstrg0 equ $ffca
outa	 equ $ffb8
adctl	 equ $1030
adr1	 equ $1031
adr2	 equ $1032
adr3	 equ $1033
adr4	 equ $1034
admsg1	 equ $0000
admsg2	 equ $0100
	ldx #admsg1
	ldy #table1
	ldab #$29
loop1	ldaa 0,y
	staa 0,x
	inx
	iny
	decb
	cmpb #0
	bne loop1
	ldx #admsg2
	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 *
*		       *
************************
start	ldaa #$b0	* scan=1,mult=1,ch1-4
	staa adctl
	ldaa adr1	* read ch5
	ldab adr1
	jsr  lh 	* convert left nibble to ascii
	staa admsg2+13	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg2+14	* output to screen
	ldaa adr2	* read ch2
	ldab adr2
	jsr  lh 	* convert left nibble to ascii
	staa admsg1+21	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg1+22	* output to screen
	ldaa adr3	* read ch3
	ldab adr3
	jsr  lh 	* convert left nibble to ascii
	staa admsg1+29	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg1+30	* output to screen
	ldaa adr4	* read ch4
	ldab adr4
	jsr  lh 	* convert left nibble to ascii
	staa admsg1+37	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg1+38	* output to screen
	ldaa #$b4
	staa adctl
	ldaa adr1	* read ch1
	ldab adr1
	jsr  lh 	* convert left nibble to ascii
	staa admsg1+13	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg1+14	* output to screen
	ldaa adr2	* read ch6
	ldab adr2
	jsr  lh 	* convert left nibble to ascii
	staa admsg2+21	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg2+22	* output to screen
	ldaa adr3	* read ch7
	ldab adr3
	jsr  lh 	* convert left nibble to ascii
	staa admsg2+29	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg2+30	* output to screen
	ldaa adr4	* read ch8
	ldab adr4
	jsr  lh 	* convert left nibble to ascii
	staa admsg2+37	* output to screen
	tba
	jsr  rh 	* convert right nibble to ascii
	staa admsg2+38	* output to screen
	ldaa #20	* indent 20 spaces
	jsr spaces
	ldx #admsg1	* display ch1-4
	jsr outstrg0
	jsr bkspc	* update channel readings
	jsr outcrlf
	jsr outcrlf
	ldaa #20	* indent 20 spaces
	jsr spaces
	ldx #admsg2	* display ch5-8
	jsr outstrg0
	jsr bkspc	* update channel 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 left  *
*  half of binary byte in acca *
*  to an ascii character       *
*			       *
********************************
lh	lsra
	lsra
	lsra
	lsra
	anda #$0f
	adda #$30
	cmpa #$39
	ble out
	adda #$07
out	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 PE1:    PE2:    PE3:    PE4:    '
       fcb 4
table2 fcc 'reading PE5:    PE6:    PE7:    PE8:    '
       fcb 4
