ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics Instructor: Professor Charles Ume Lecture #11 George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 MON12 Utility Subroutines George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 MON12 Utility Subroutines MON12 Utility Subroutines • Subroutines are available for performing I/O tasks. • Jump table has been set up in EEPROM beneath interrupt vectors. • To use these jump subroutines, execute jump to subroutine (JSR) command to appropriate entry in jump table. George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 UPCASE Subroutine Listing If character in accumulator A is lower case alpha, convert to upper case. WCHEK Test character in accumulator A and return with Z bit set if character is whitespace (space, comma, tab). DCHEK Test character in accumulator A and return with Z bit set if character is delimiter (carriage return or whitespace). ONSCIO Initialize I/O device. INPUT Read I/O device. OUTPUT Write I/O device. OUTLHLF Convert left nibble of accumulator A contents to ASCII and output to terminal port. OUTRHLF Convert right nibble of accumulator A contents to ASCII and output to terminal port. George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 OUTA OUT1BYT Subroutine Listing Cont’d Output accumulator A ASCII character. Convert binary byte at address in index register X to two ASCII characters and output. Return address in index register X pointing to next byte. OUT1BSP Convert binary byte at address in index register X to two ASCII characters and output followed by a space. Returns address in index register. OUT2BSP Convert two consecutive binary bytes starting at address in index X to four ASCII characters and output followed by a space. Returns address in index register X pointing to next byte. OUTCCRLF Output ASCII carriage return followed by a line feed. OUTSTRG Output string of ASCII bytes pointed to by address in index register X until character is an end of transmission ($04). OUTSTRGO Same as OUTSTRG except leading carriage return and line feed is skipped. INCHAR Waits for you to type an ASCII character from the keyboard, and stores the corresponding ASCII number in accumulator George W. Woodruff School of Mechanical Engineering, Georgia TechA, and then outputs the ASCII character to the screen. ME4447/6405 To use an I/O subroutine, Jump Sub Routine (JSR) to the specified address listed below. ADDRESS SUBROUTINE FUNCTION • • • • • • • • • • • $FF37 $FF3A $FF3D $FF40 $FF43 $FF46 $FF49 $FF4C $FF4F $FF52 $FF55 UPCASE WCHEK DCHEK ONSCIO INPUT OUTPUT OUTLHLF OUTRHLF OUTA OUTlBYT OUT1BSP • $FF58 OUT2BSP • • • $FF5B $FF5E $FF61 OUTCRLF OUTSTRG OUTSTRGO • $FF64 Convert character to uppercase Test character for whitespace Check character for delimiter Initialize I/O device Read I/O device Write I/O device Convert left nibble to ASCII and output Convert right nibble to ASCII and output Output ASCII character Convert binary byte to 2 ASCII characters and output Convert binary byte to 2 ASCII characters and output followed by space Convert 2 consecutive binary bytes to 4 ASCII characters and output followed by space. Output ASCII carriage return followed by line feed Output ASCII string until end of transmission ($04) Same as OUTSTRG except leading carriage return and line feed is skipped Input ASCII character and echo back INCHAR George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Utility Subroutines Examples Example: OUTA ORG $1000 LDAA #$41 *Load acc. A with ASCII code for the *character A. JSR $FF4F *JSR to the subroutine OUTA SWI END Result A is written to the screen. George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Utility Subroutines Examples Example: OUTSTRG (Output ASCII Character String until EOT, $04, is encountered) STR1 EQU $2100 OUTSTRG EQU $FF5E ORG STR1 FCC “ABCDEFG” FCB #$04 ORG $1000 LDX #STR1 JSR OUTSTRG *Go to OUTSTRG routine which *outputs ASCII characters contained in each *address starting from $2100 until *an EOT character is found. SWI END ResultABCDEFG written to the screen on a new line. (Note: ASCII end of transmission (EOT) character must be used with the OUTSTRG subroutine let it of know when to Engineering, stop readingGeorgia from Tech George W. Woodruff to School Mechanical memory. EOT ASCII = #$04) ME4447/6405 Difference Between the Utility Subroutines OUTSTRG and OUTSTRG0 Assume you want to print the following to the screen: MEMORY LOCATION $_____CONTAINS _____ IN DECIMAL. Use subroutine OUTSTRG to print “MEMORY LOCATION $” to screen on a new line (It always starts printing on a new line, because it outputs carriage return with line feed). Use subroutine OUTSTRG0 to print “CONTAINS” to screen on same line as “MEMORY LOCATION $” (Because it does not output carriage return with line feed) Use subroutine OUTSTRG0 to print “IN DECIMAL.” to screen on the same line (Note: Refer to Lab website for example program to print decimal numbers to the screen.) George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Utility Subroutines Examples Example: OUTLHLF (Out Left Half) and OUTRHLF (Out Right Half) ORG $1000 LDAA #$AF JSR $FF49 LDAA #$AF JSR $FF4C *Puts hex number $AF in acc. A *Goes to subroutine OUTLHLF which converts left *nibble, #$A, to ASCII number, $41, and then outputs *its ASCII character, ‘A, to the screen. *Reload Acc. A since OUTLHLF modifies the contents of *Acc. A *Goes to subroutine OUTRHLF which converts right *nibble, #$F, to ASCII number, $46, and then outputs *its ASCII character, ‘F, to the screen. SWI END Result AF is written to the screen. George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Utility Subroutines Examples Example: OUT1BYT (Out 1 Byte) and OUT1BSP (Out 1 Byte with Space) Assume that memory contains the following: 2100 FA FB Now execute the following code: ORG $1000 LDX #$2100 JSR $FF52 *Goes to subroutine OUT1BYT which converts the *content of the address pointed to by the X register to *two ASCII equivalents and outputs their characters to *the screen, and increments X register by #$1. JSR $FF55 *Goes to subroutine OUT1BSP which converts the *content of the address pointed to by the X register to *two ASCII equivalents and outputs their characters to the *screen followed by a space. SWI END Result FAFB_ sent to screen (Note: last character is a space) George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Utility Subroutines Examples Example: OUT2BSP (Out 2 Bytes with Space) Assume that memory contains the following: 2100 FA FB Now execute the following code. ORG $1000 LDX #$2100 JSR $FF58 *JSR to subroutine OUT2BSP which converts two *consecutive binary bytes to their 4 ASCII numbers *and outputs their ASCII characters to the screen followed by a *space. SWI END ResultFAFB_ sent to screen (last character is a space). George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Utility Subroutines Examples Example: OUTCRLF (Output Carriage Return with Line Feed) ORG $1000 JSR $FF5B *Go to subroutine OUTCRLF *which outputs ASCII carriage return *followed by a line feed. SWI END Result New line on screen (Note:Equivalent to pressing Enter in your computer) George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Utility Subroutines Examples Example: INCHAR (Input Character) ORG $1000 JSR $FF64 *Goes to subroutine INCHAR. Waits for you to *type an ASCII character from the keyboard, *and stores the corresponding ASCII number in *accumulator A SWI END Result-> If you type 9 on the keyboard, ASCII number $39 is stored in accumulator A George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 Example Write an assembly language program to output a string of characters to the screen. Solution: This particular solution will print “Hello” to the screen using the OUTA subroutine OUTA Loop Quit EQU $FF4F ORG FCC FCB $2000 “HELLO” #$04 ORG LDX LDAA CMPA BEQ JSR INX BRA SWI END $1000 #$2000 $00,X #$04 Quit OUTA FCC is used to store a string of characters FCB is used to store End Of Transmission (EOT) (Note 1: EOT in ASCII is $04) (Note 2: In this particular example any non-printing character can be used) Loop George W. Woodruff School of Mechanical Engineering, Georgia Tech Program Skip Ahead Initialization Until Last Loop ME4447/6405 CPU Registers Used in Program: #$48 #$6F #$04 #$65 Accum A: #$2002 #$2001 #$2000 Index X: #$2005 CCR Bit Z: 0 1 OUTA EQU $FF4F ORG FCC CCRZ Zis is 1 since FCB CCR 0 since AccumA A equals Accum does not equal $04 $04 ORG $2000 “Hello” #$04 Loop Memory Locations Used in Program: $2000 $48 $2001 $65 $2002 $6C $2003 $6C $2004 LDX LDAA CMPA BEQ JSR INX BRA SWI END $1000 #$2000 $00,X #$04 Quit OUTA Loop Does notsince Branch branch CCR Z is 1 because CCR Always Z is 0 Branches Quit Ascii Equivalent of “Hello” Computer Screen: He llo $6F $2005 $04Woodruff School of Mechanical Engineering, Georgia Tech George W. ME4447/6405 Solution 2: This particular solution will print “Hello” to the screen using the OUTSTRG subroutine OUTSTRG EQU $FF5E ORG FCC FCB $2000 “HELLO” #$04 ORG LDX JSR SWI END $1000 #$2000 OUTSTRG (Note: EOT must be used because the OUTSTRG Subroutine uses EOT as the end of the string) OUTSTRG: Output ASCII string until end of transmission ($04) George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 QUESTIONS??? George W. Woodruff School of Mechanical Engineering, Georgia Tech