;Name:  Derek Marston and Pete Susi
;Date:   3/25/03
;Desc:  This program will establish Hyperterminal Communication via SCI
;       and Echo characters back to HT upon Receipt via nterrupt


RAM             EQU     800h;
FLASH           EQU     8000h;
Stack           EQU     0BFFh;
SCIStatusReg    EQU     00C4h;
BaudRateReg     EQU     00C1h;
ControlReg1     EQU     00C2h;
ControlReg2     EQU     00C3h;
SCIDataReg      EQU     00C7h;
SCIvector       EQU     0FFD6h;
PortA           EQU     0000h;
DirA            EQU     0002h;

;******************************************************


     org        FLASH

main:
     lds       #Stack           ; Configure Stack Pointer

   ;  ldaa      #0FFh
   ;  staa      DirA             ; Configure Porta -> Output
   ;  clr       PortA            ; Set PortA Low

     bsr       ConfigSCI        ; Configure SCI port for HT comm.
     cli                        ; ENABLE the interrupts

loop:
     nop
     bra        loop;


;******************************************************
;Name:          ConfigSCI
;Input:         None
;Output:        None
;Destroys:      A
;Description:   Configures port for:
;               Asyncronous serial data @ 9600
;               8 bit data, no parity, 1 stop bit
;               enable transmitter, receiever, and Rx Int.

ConfigSCI:
     clr        ControlReg1;
     ldaa       #2C             ; enable Tx, Rx and RxInterrupt
     staa       ControlReg2

     ldaa       #34h            ; BR divisor for 9600 BPS
     staa       BaudRateReg

     rts;

;******************************************************
;Name:          CharOut
;Input:         A = the ASCII code to Print to screen
;Output:        None
;Destroys:      X
;Description:   Wait until the transmitter is ready (wait until the
;		TDRE bit in the Status Register is 1), then
;		send the contents of A to the Screen.

CharOut:
      ldx       #SCIStatusReg      ; get status flags
      ldab       SCIStatusReg
      andb       #10000000q        ; Check for ready
      beq        CharOut           ; Wait until ready

      staa       SCIDataReg        ; Send data
      rts;


;******************************************************
;Name:	        GetKey
;Input:		None.
;Output:	A = the Byte (ASCII code) for key recieved
;Destroys:	A, Flags
;Description:	Reads last byte from the Data register and return
;		from the subroutine with the data in Accumulator A

GetKey:
	ldaa	SCIDataReg
	rts



;******************************************************
;Name SCIRxInterrupt
;Input: none
;Output: none
;Destroys: A, Flags
;Descrition: Reads in incoming byte and echos it to HT

SCIRxInterrupt:

        ldaa    SCIStatusReg
        ldaa    SCIDataReg      ; Get incoming Byte
        staa    SCIDataReg      ; Echo it back to hyperterminal

        rti                     ; DONE!


;******************************************************
;Name:		InstallInterruptVector
;  NOT A ROUTINE
;
;InstallInterruptVector:

        org SCIvector           ; address for jump vec: FFD6h

SCIVec:  DW      SCIRxInterrupt

;******************************************************
