* Title         : Pressure Sensor Experiment
* Filename      : PS.ASM 
* Programmer    : Donald Cheung
* Date          : July 16, 1998
* Version       : 1.0.1.2
* Description   : Uses one A/D port and outputs corresponding hex value
*                 to the display via the SCI port.
*
**************************************************************************
* Address locations of registers and user-defined constants
**************************************************************************
*
BAUD    EQU     $102B  ; Baud-rate control
SCCR1   EQU     $102C  ; Serial Communication Control Register 1
SCCR2   EQU     $102D  ; Serial Communication Control Register 2
SCSR    EQU     $102E  ; Serial Communication Status Register
SCDR    EQU     $102F  ; Serial Communication Data Register

ADCTL	EQU	$1030	;A/D Control/Status
ADR1	EQU	$1031	;A/D Results 1
ADR2	EQU	$1032	;A/D Results 2
ADR3	EQU	$1033	;A/D Results 3
ADR4	EQU	$1034	;A/D Results 4
OPTION	EQU	$1039	;A/D Power-up(BIT7)

EOS     EQU     $04    ; User-defined End Of String (EOS) character
CR      EQU     $0D    ; Carriage Return Character
LF      EQU     $0A    ; Line Feed Character
FOFE	EQU	$0C	;Form Feed Character

OUTA	EQU	$FFB8
OUTCHAR	EQU	$FFBB	;OUTCHAR
OUTCRL	EQU	$FFC4	;OUTPUT CR LF
OUTSTR	EQU	$FFCA	;OUTSTR W/O LEADING CR AND LF
*
************************************************************************
*               Define Strings for displaying messages
************************************************************************
	ORG	$0100
RESULT	FCC	@ @		;The main result is stored here

        ORG     $B600		; Store to EEPROM
        JMP     MAIN

CRLF    FCB	CR, LF		; Carriage return and line feed
        FCB     EOS		; EOS character
*
************************************************************************
*                       MAIN PROGRAM
* Description: This program calls the InitSCI routine, and prints the
*              A/D information to the screen. 
************************************************************************
*
MAIN    LDS     #$0041		;Define a stack 
        JSR     INITSCI		;Initialize SCI

	LDAA	#%10010000	;Initialize A/D
	STAA	OPTION		;continuous conversion

	LDAA	#%00110011	;Start A/D conversion
	STAA	ADCTL

L1ADM	LDAA	ADCTL		;Wait for first conversion
	ANDA	#%10000000	; to complete
	BEQ	L1ADM
	
L1M	LDAA	ADR3		;Load A/D register 3 into A
	STAA	RESULT		;Store into RESULT

	LDX	#RESULT		;Load pointer to RESULT
	JSR	OUTCHAR		;Output character with hex-ascii conv.

	LDAA	#LF		;Output Line feed
	JSR	OUTA

	BRA	L1M		;Main loop
*
************************************************************************
*                       SUBROUTINE - InitSCI         
* Description: This subroutine initializes the BAUD rate to 9600 and
*              sets up the SCI port for 1 start bit, 8 data bits and
*              1 stop bit.  It also enables the transmitter and receiver.
*              Effected registers are BAUD, SCCR1, and SCCR2.
* Input         : None.
* Output        : Initializes SCI.
* Destroys      : None.
* Calls         : None.
************************************************************************
*
INITSCI PSHA                            ; Save contents of A register 

	LDAA	#$30                    ; Set BAUD rate to 9600
	STAA	BAUD
	LDAA	#%00000000		; Set SCI Mode to 1 start bit,  
	STAA	SCCR1			; 8 data bits, and 1 stop bit.
        LDAA	#%00001100		; Enable SCI Transmitter 
        STAA	SCCR2			;     and Receiver

        PULA                            ; Restore A register
        RTS                             ; Return from subtoutine
*
************************************************************************
*                       END OF PROGRAM
************************************************************************

