Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Overview Intro to Project 2 - Serial I/O – RS232, USB Assembly Language Programming Using the LC-3 Simulator."— 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 Signals: Null Modem Connections using control signals (handshaking): Connects: DTE (Data Terminal Equipment or Computer) to DCE (Data Communications Equipment).

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 “Faked” Loop back Connections: Full handshaking (again):

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 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(); } Java Program to transmit Character stream

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 optionalmandatory

12 An Assembly Language Program ; ; Program to multiply a number by the constant 6 ;.ORIGx3050 LDR1, SIX LDR2, NUMBER ANDR3, R3, #0; Clear R3. It will ; contain the product. ; The inner loop ; AGAINADDR3, R3, R2 ADDR1, R1, #-1; R1 keeps track of BRpAGAIN; the iteration. ; HALT ; NUMBER.BLKW1 SIX.FILLx0006 ;.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 OpcodeOperandMeaning.ORIG addressstarting address of program.END end of program.BLKW nallocate n words of storage.FILL nallocate one word, initialize with value n.STRINGZ n-character string allocate n+1 locations, initialize w/characters and null terminator

14 Trap Codes LC-3 assembler provides “pseudo-instructions” for each trap code, so you don’t have to remember them. CodeEquivalentDescription HALTTRAP x25 Halt execution and print message to console. INTRAP x23 Print prompt on console, read (and echo) one character from keybd. Character stored in R0[7:0]. OUTTRAP x21 Write one character (in R0[7:0]) to console. GETCTRAP x20 Read one character from keyboard. Character stored in R0[7:0]. PUTSTRAP x22 Write null-terminated string to console. Address of string is in R0.

15 LC-3 Editor / Simulator Go to Authors Web page (http://www.mhhe.com/patt2 )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 ;.ORIGx3000 ANDR2, R2, #0; R2 is counter, initially 0 LDR3, PTR; R3 is pointer to character file GETC; R0 gets input character LDRR1, R3, #0; R1 gets first character from file ; ; Test character for end of file ; TESTADDR4, R1, #-4; Test for EOT (ASCII x04) BRzOUTPUT; If done, prepare the output ; ; Test character for match. If a match, increment count. ; NOTR1, R1 ADDR1, R1, R0; If match, R1 = xFFFF NOTR1, R1; If match, R1 = x0000 BRnpGETCHAR; If no match, do not increment ADDR2, R2, #1 ; ; Get next character from file. ; GETCHARADDR3, R3, #1; Point to next character. LDRR1, R3, #0; R1 gets next char to test BRnzpTEST

18 Count the occurrences of a character in a file (2 of 2). ; ; Output the count. ; OUTPUTLDR0, ASCII; Load the ASCII template ADDR0, R0, R2; Covert binary count to ASCII OUT; ASCII code in R0 is displayed. HALT; Halt machine ; ; Storage for pointer and ASCII template ; ASCII.FILLx0030; ASCII offset PTR.FILLx4000; PTR to character file.END


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

Similar presentations


Ads by Google