1 / 18

Overview

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:.

corina
Download Presentation

Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview • Intro to Project 2 - Serial I/O – RS232, USB • Assembly Language Programming • Using the LC-3 Simulator

  2. Serial Connection

  3. RS232 Connects: DTE (Data Terminal Equipment or Computer) to DCE (Data Communications Equipment). Signals: Null Modem Connections using control signals (handshaking):

  4. 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

  5. RS232 Full handshaking (again): “Faked” Loop back Connections:

  6. RS232 Minimum Connection – No handshaking:

  7. RS232 RS232 Cable and Lab Hookup:

  8. 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

  9. 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.

  10. 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(); } }

  11. 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

  12. 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

  13. Assembler Directives • Pseudo-operations • do not refer to operations executed by program • used by assembler • look like instruction, but “opcode” starts with dot

  14. Trap Codes • LC-3 assembler provides “pseudo-instructions” foreach trap code, so you don’t have to remember them.

  15. 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”

  16. Sample Program • Count the occurrences of a character in a file.Remember this?

  17. 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

  18. 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

More Related