include "8X931HX.inc" include "SWITCH.INC" public init_serial, putc_ser, putret_ser, puts_ser, putc_hex_ser DEFINE SERIAL_IO_DEBUG_CODE_SEGMENT, SPACE=CODE SEGMENT SERIAL_IO_DEBUG_CODE_SEGMENT ;###################################################################### ;# SUBROUTINE: init_serial ;# PURPOSE: This subroutine initializes serial I/O system and is ;# REQUIRED to do any I/O routines to display text or ;# messages to a terminal connected to the serial port of ;# the 82930XX. ;# The BAUD RATE is set for 19200 ;# TERMINAL SETUP: ;# BAUD RATE: 19.2 K BAUD ;# DATA BITS: 8 STOP BITS: 1 ;# PARITY: NONE FLOW CONTROL: XON/XOFF ;# CONNECTION: connect standard 9-pin serial cable from PC to SERIAL ;# connector (SERIAL I/O - J1) on 82930 USB Eval Board ;# RISM INTERACTION: ;# RISM and PLC can still be utilized with these routines. The serial ;# connection for PLC should still be connected to the UART J2 connection ;# on the eval board. The DEBUGGER configuration can be set to use ;# either TIMER 2 (default) OR TIMER 1 and this setup and the serial ;# routines will still function properly ;# 82930 SETUP: ;# These routines ONLY work in FULL SPEED mode where ;# PLLSEL [2:0] == [1 1 0] ;# USES: Timer 2 for Baud Rate Generation ;# REFERENCES: For details on how this works, please refer to pages 12-12 ;# to 12-14 of the 82930 Ax USB uCntrl User's Manual ;# CALLED BY: main ;# REGS USED: A (R11) ;# RETURNS: None ;# ASSUMES: Nothing ;# This routine will determine the present selected clock mode ;# for the CPU and set the timer overflow value appropriately to ;# ensure the baud rate of 19.2 k. ;###################################################################### init_serial: push ACC orl T2CON, #00110000b ; Timer 2 as Baud Rate Generator ; for both Receiver & Transmitter mov RCAP2H, #0FFh ; Setup reload timer 2 values mov RCAP2L, #0ECh ; 19200 baud T2_SETUP: orl T2CON, #34h ; Start Timer 2 orl SCON, #40h ; Serial Mode 1 ; Enable Serial Reception clr RI ; Clear Receive Int Flag Bit clr TI pop ACC ret ;###################################################################### ;###################################################################### ;# SUBROUTINE: putc_ser ;# PURPOSE: This subroutine puts a single character out to serial ;# i/o by placing the byte in Acc A to SBUF and waiting for ;# the transmit to complete and then clearing the transmit ;# interrupt flag ;# CALLED BY: anywhere (lcall putc_ser) ;# REGS USED: ACC A (R11) : contains byte to transmit ;# the value of A is not affected by this routine after the ;# transmit ;# RETURNS: None ;# ASSUMES: Nothing ;###################################################################### putc_ser: ; EXPECT to see byte to transmit in A mov SBUF, A ; Place character in serial buffer jnb TI,$ ; Wait for transmit to complete clr TI ; Now clear the transmit interrupt bit ret ;###################################################################### ;###################################################################### ;# SUBROUTINE: putret_ser ;# PURPOSE: This subroutine puts a CR and LF to the serial I/O output. ;# CALLED BY: anywhere (lcall putc_ser) ;# REGS USED: ACC A (R11) - values saved and restored ;# RETURNS: None ;# ASSUMES: Nothing ;###################################################################### putret_ser: push ACC mov A, #0DH ; carriage return lcall putc_ser ; serial putc mov A, #0AH ; line feed lcall putc_ser ; serial putc pop ACC ret ;###################################################################### ;###################################################################### ;# SUBROUTINE: puts_ser ;# PURPOSE: This subroutine prints a NUL terminated string to ;# serial I/O using standard putc_ser routine. ;# CALLED BY: anywhere ;# USED: DPTR: Expects starting address value of string to ;# display to be in DPTR ;# ACC A (R11) is used to display each character to ser i/o ;# RETURNS: None ;# ASSUMES: Nothing ;# NOTE : This routine does not inherantly print out a carriage ;# return and linefeed. ;# Example Usage: ... ;# mov DPTR, #MSG_2_DISPLAY ;# lcall puts_ser ;# ... ;# MSG_2_DISPLAY: DB "This will be displayed !",LF,NUL ;###################################################################### puts_ser: push ACC push DPH push DPL GETNXTn: mov A, #00H movc A,@A+DPTR cjne A, #00H, SNDCHn ; IF PRESENT CHARACTER IS NOT EQUAL TO END ; OF STRING CHARACTER THEN PRINT IT OUT AND SETUP ; TO GET NEXT CHARACTER POINTED TO BY DPTR sjmp DONEPS SNDCHn: lcall putc_ser ; PUT OUT SINGLE CHARACTER TO TERMINAL inc DPTR ; INCREMENT POINTER TO STRING sjmp GETNXTn DONEPS: pop DPL pop DPH pop ACC ret ;###################################################################### ;###################################################################### ;# SUBROUTINE: putc_hex_ser ;# PURPOSE: This subroutine converts a hex value to its ascii value ;# and prints it out to serial I/O. A return is not printed ;# afterwards. ;# CALLED BY: anywhere ;# USED: The accumulator (ACC) has the hex value you wish to display ;# R6 used for temp storage, it's pushed and popped ;# RETURNS: None ;# ASSUMES: Nothing ;# NOTE: This routine does not inherantly print out a carriage ;# return and linefeed. ;# CALLS: This calls both putc_ser and convert ;###################################################################### putc_hex_ser: push ACC push 00h ; R0 in Bank 0. mov R0, A ; save ACC value for later use. rr A ; get the high nibble first rr A rr A rr A anl A, #0FH lcall cnv2ascii lcall putc_ser ; print out the high nibble mov A, R0 anl A, #0FH ; get the low nibble lcall cnv2ascii lcall putc_ser ; print out the low nibble pop 00h ; R0 in Bank 0. pop ACC ret ;###################################################################### ;###################################################################### ;# SUBROUTINE: cnv2ascii (Re-written by JRP) ;# PURPOSE: This subroutine converts a hex value to its ascii value ;# CALLED BY: putc_hex_ser ;# USED: ;# The accumulator (ACC) has the hex value you wish to convert ;# RETURNS: None ;# MODIFIES: ACC ;# ASSUMES: Nothing ;###################################################################### cnv2ascii: jnb ACC.3, cnv2ascii_add30h ; if ACC.3 not set, add 30h cnv2ascii_check_8: cjne A, #08h, cnv2ascii_check_9 ljmp cnv2ascii_add30h ; if 8, then add 30h cnv2ascii_check_9: cjne A, #09h, cnv2ascii_add37h ; if not 8 or 9, must be A-F cnv2ascii_add30h: add A, #30h ; if 0-9, add 30h sjmp cnv2ascii_done cnv2ascii_add37h: add A, #37h ; if A-F, add 37h cnv2ascii_done: ret ;###################################################################### ;###################################################################### ;# SUBROUTINE: getc_ser ;# PURPOSE: This subroutine gets a single character from serial ;# and places the byte in Acc A. ;# CALLED BY: anywhere (lcall putc_ser) ;# REGS USED: ACC A (R11) : see RETURNS ;# RETURNS: Character read is returned in ACCUM A (R11) ;# ASSUMES: Nothing ;###################################################################### getc_ser: clr RI jnb RI, $ clr RI mov A, SBUF ; get the character ret ;###################################################################### ;###################################################################### ;# SUBROUTINE: getche_ser ;# PURPOSE: This subroutine gets a single character from serial ;# and places the byte in Acc A & also echos the character ;# back on the serial line. This routine is helpful for ;# reading characters typed at the keyboard when in a terminal ;# program over a serial connection, because it will display ;# what you typed on the screen. ;# CALLED BY: anywhere (lcall putc_ser) ;# REGS USED: ACC A (R11) : see RETURNS ;# RETURNS: Character read is returned in ACCUM A (R11) ;# ASSUMES: Nothing ;###################################################################### getche_ser: lcall getc_ser ; get the character lcall putc_ser ; display the character ret ;######################################################################