180 likes | 365 Views
Overview. Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator. Serial Connection. RS232. Connects: DTE (Data Terminal Equipment or Computer) to DCE (Data Communications Equipment). Signals:.
E N D
Overview • Intro to Project 2 - Serial I/O – RS232, USB • Assembly Language Programming • Using the LC-3 Simulator
RS232 Connects: DTE (Data Terminal Equipment or Computer) to DCE (Data Communications Equipment). Signals: Null Modem Connections using control signals (handshaking):
RS232 Signals: Carrier Detect (CD) Incoming signal from a modem Data Set Ready (DSR) Incoming handshaking signal controlled by DCE Received Data (RD) Incoming Data (from a DCE to a DTE) Request To Send (RTS) Outgoing flow control signal controlled by DTE Transmitted Data (TD) Outgoing Data (from a DTE to a DCE) Clear To Send (CTS) Incoming flow control signal controlled by DCE Data Terminal Ready (DTR) Outgoing handshaking signal controlled by DTE Ring Indicator (RI) Incoming signal from a modem Signal Ground Common reference voltage
RS232 Full handshaking (again): “Faked” Loop back Connections:
RS232 Minimum Connection – No handshaking:
RS232 RS232 Cable and Lab Hookup:
RS232 Serial Bit Transmission: Baud rate: Max speed of transmission of bits: Typically 110, 300, 1200, 2400, 4800, 9600, 19200 bits/sec Start bit: A first bit always of the same polarity for equipment to sync on Data Bits: The useful data follows the start bit: Typically 5, 6, 7, or 8 bits Parity Bit: Even Parity, Odd Parity, Mark parity, No Parity Stop Bits: The trailing bits after the data and parity to ensure time to “catch” data Typically 1, 1.5, or 2 bits
RS232 • For Project 2 you will: • Create a stream of ASCII characters, • Observe the transmission of the pulse stream, • Change the parameters of the transmission, and • Explain all aspects of the transmission.
RS232 Java Program to transmit Character stream import java.io.*; import javax.comm.*; public class SimpleWrite { public static void main(String[] args) throws Exception { OutputStream outputStream; outputStream = get_the_serial_port(); byte[] data = {'a'}; for (int i = 0; i < 1000; i++) { outputStream.write(data); System.out.println ("i = " + i); Thread.sleep(1000); // milliseconds } } public static OutputStream get_the_serial_port() throws Exception { CommPortIdentifier portId; portId = CommPortIdentifier.getPortIdentifier("COM1"); SerialPort serialPort; serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000); serialPort.setSerialPortParams(9600, // change baud rate here. SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); return serialPort.getOutputStream(); } }
LC-3 Assembly Language Syntax • Each line of a program is one of the following: • an instruction • an assember directive (or pseudo-op) • a comment • Whitespace (between symbols) and case are ignored. • Comments (beginning with “;”) are also ignored. • An instruction has the following format: LABEL OPCODE OPERANDS ;COMMENTS optional mandatory
An Assembly Language Program ; ; Program to multiply a number by the constant 6 ; .ORIG x3050 LD R1, SIX LD R2, NUMBER AND R3, R3, #0 ; Clear R3. It will ; contain the product. ; The inner loop ; AGAIN ADD R3, R3, R2 ADD R1, R1, #-1 ; R1 keeps track of BRp AGAIN ; the iteration. ; HALT ; NUMBER .BLKW 1 SIX .FILL x0006 ; .END
Assembler Directives • Pseudo-operations • do not refer to operations executed by program • used by assembler • look like instruction, but “opcode” starts with dot
Trap Codes • LC-3 assembler provides “pseudo-instructions” foreach trap code, so you don’t have to remember them.
LC-3 Editor / Simulator • Go to Authors Web page (http://www.mhhe.com/patt2 ) • Download LC-3 (LC301.exe) • LC-3 Edit • LC-3 Simulate • Review “Guide to Using the Windows Version of the LC-3 Simulator and LC-3 Edit”
Sample Program • Count the occurrences of a character in a file.Remember this?
Count the occurrences of a character in a file (1 0f 2). ; ; Program to count occurrences of a character in a file. ; Character to be input from the keyboard. ; Result to be displayed on the monitor. ; Program only works if no more than 9 occurrences are found. ; ; ; Initialization ; .ORIG x3000 AND R2, R2, #0 ; R2 is counter, initially 0 LD R3, PTR ; R3 is pointer to character file GETC ; R0 gets input character LDR R1, R3, #0 ; R1 gets first character from file ; ; Test character for end of file ; TEST ADD R4, R1, #-4 ; Test for EOT (ASCII x04) BRz OUTPUT ; If done, prepare the output ; ; Test character for match. If a match, increment count. ; NOT R1, R1 ADD R1, R1, R0 ; If match, R1 = xFFFF NOT R1, R1 ; If match, R1 = x0000 BRnp GETCHAR ; If no match, do not increment ADD R2, R2, #1 ; ; Get next character from file. ; GETCHAR ADD R3, R3, #1 ; Point to next character. LDR R1, R3, #0 ; R1 gets next char to test BRnzp TEST
Count the occurrences of a character in a file (2 of 2). ; ; Output the count. ; OUTPUT LD R0, ASCII ; Load the ASCII template ADD R0, R0, R2 ; Covert binary count to ASCII OUT ; ASCII code in R0 is displayed. HALT ; Halt machine ; ; Storage for pointer and ASCII template ; ASCII .FILL x0030 ; ASCII offset PTR .FILL x4000 ; PTR to character file .END