EGRE 643

Homework 09

Due Monday 3/2/09

Get the files in HW09.zip and using the Keil uVision3. In comio_V2.A51 complete the following subroutines: PUTCY, P_HEX, and P_BI. When the header description specifies subroutines that are called you are expected to call these in your implementation. There is an error in the HEX2ASC subroutine. Find and fix this error.

$MOD51

$TITLE(X_COMIO - TEST COM ROUTINES)

$SYMBOLS ;INCLUDE SYMBOLS IN LISTING

CR equ 0DH ; carriage return

LF equ 0AH ; line feed

EXTRN CODE (PUTCHAR, GETCHAR, CRLF, INITCOM) ;IN COMIO.A51

EXTRN CODE (P_HEX, P_BI) ;IN COMIO.A51

EXTRN CODE (PUTSTR, SPACE) ;IN COMIO.A51

PROG SEGMENT CODE ; SEGMENT FOR PROGRAM IN ROM

CONST SEGMENT CODE ; SEGMENT FOR CONSTANTS IN ROM

DVAR SEGMENT DATA ; SEGMENT FOR VARIABLES IN RAM

;BVAR SEGMENT BIT ; SEGMENT FOR BIT VARIABLES

STACK SEGMENT IDATA ; SEGMENT FOR STACK IN INTERNAL DATA RAM

RSEG STACK

DS 20H ; Reserve 32 Bytes for Stack

RSEG DVAR ; SWITCH TO DATA SEGMENT

BYTES: DS 4 ; Example of reserving 4 BYTES IN DATA RAM

RSEG CONST

; CONSTANTS.

MSG: DB 'Hex and binary of pressed key is output to terminal screen.'

DB CR,LF

DB 0

; START OF

CSEG AT 0 ; absolute Segment at Address 0

RESET: LJMP MAIN ; reset location (jump to start OF PROGRAM)

;START OF PROGRAM

RSEG PROG ; SWITCH TO CODE SEGMENT

USING 0 ; TELL ASEMBLER TO USE REGISTER BANK 0

MAIN: MOV SP,#STACK-1 ; Initialize stack pointer

CALL INITCOM ;INITILIZE COM PORT

MOV DPTR, #MSG ;POINT TO SIGNON MESSAGE

CALL PUTSTR ;OUTPUT TO CONSOLE

AGAIN: CALL CRLF ;GOTO NEW LINE

CALL GETCHAR ;READ COM PORT

CALL P_HEX ;OUTPUT HEX OF PRESSED KEY

CALL SPACE ;OUTPUT SPACE

CALL p_BI ;OUTPUT BINARY OF PRESSED KEY

JMP AGAIN ;GET NEXT CHAR

END

;****************************************************************

;FUNCTION: PUTCY - OUTPUT TO CONSOLE VALUE OF CY BIT

; IF CY = 1 THEN OUTPUT ASCII 1 = 31H

; IF CY = 0 THEN OUTPUT ASCII 0 = 30H

; INPUTS: CY - BIT VALUE TO OUTPUT TO CONSOLE

; OUTPUTS: NONE

; CALLS: PUTCHAR

;DESTROYS: NONE - ACTUALLY T1, SBUF

;****************************************************************

;

PUTCY:

RET

;***************************************************************

; FUNCTION: P_HEX - PRINT ACC IN HEX TO COM PORT

; INPUTS: ACC

; OUTPUTS: COM PORT

; CALLS: HEX2ASCII, PUTCHR

; DESTROYS: NONE

;***************************************************************

P_HEX:

RET ;RETURN

;****************************************************************

;FUNCTION: P_BI - OUTPUT IN BINARY THE CONTENTS OF ACC

; TO COMM PORT

; INPUTS: ACC - BYTE TO OUTPUT IN HEX

; OUTPUTS: COM PORT

; CALLS: PUTCY

;DESTROYS: NONE

;****************************************************************

P_BI:

USING 0 ;NECESSARY FOR PUSH AR0

PUSH PSW ;SAVE PSW

PUSH ACC ;SAVE ACC

PUSH AR0 ;SAVE R0

POP AR0 ;RESTORE R0

POP ACC ;RESTORE ACC

POP PSW ;RESTORE PSW

RET