EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Similar documents
EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Chapter 3. Information Representation

FD-011WU. 2D Barcode Reader User Guide V1.6CC

MK D Imager Barcode Scanner Configuration Guide

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

Data Representation and Binary Arithmetic. Lecture 2

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

Mounting Dimensions / Viewing 2 Mounting Options 3. Wiring Configuration 4. Quick Set up Procedure 5. Changing Intensity 6.

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

S-Series Sensor ASCII Protocol v8.1.0

Fundamentals of Programming (C)

Serial I/O. 4: Serial I/O. CET360 Microprocessor Engineering. J. Sumey

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

ASCII Code - The extended ASCII table

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

A GUIDE TO RS-232 COMMUNICATION WITH FX PLCS

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

Do not start the test until instructed to do so!

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

Universal Asynchronous Receiver Transmitter Communication

Number Representations

Lecture (09) x86 programming 8

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

Do not start the test until instructed to do so!

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

PD1100 STAND-ALONE PROGRAMMING & USER S GUIDE. use the freedom

Chapter 8. Characters and Strings

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

2D Barcode Reader User Guide V 1.2.1

The following are the data types used in the C programming language:

Number System (Different Ways To Say How Many) Fall 2016

Chapter 2 Bits, Data Types, and Operations

2D BARCODE SCANNER CA-SC-20200B

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

OOstaExcel.ir. J. Abbasi Syooki. HTML Number. Device Control 1 (oft. XON) Device Control 3 (oft. Negative Acknowledgement

ASSIGNMENT 5 TIPS AND TRICKS

Fundamentals of Programming

Chapter 2 Number System

Chemistry Hour Exam 2

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

Chapter 2 Bits, Data Types, and Operations

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

NC-1200 BARCODE SCANNER. Configuration Guide - 1 -

Characters Lesson Outline

RS-422 Code-Operated Switches

Chapter 2 Bits, Data Types, and Operations

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Xi2000-BT Series Configuration Guide

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Midterm Exam, Fall 2015 Date: October 29th, 2015

BD-6500BT Bluetooth 2D Barcode Scanner Configuration Guide

Connecting UniOP to Datalogic Barcode Readers

Menu & commands booklet FOR BAR CODE SCANNERS * *

BARCODE SCANNER. Configuration Guide - 1 -

Oberon Data Types. Matteo Corti. December 5, 2001

User s Manual. Xi3000 Scanner. Table of Contents

ADDMASTER. Addmaster Corporation. IJ-3080 Journal/Validation Printer. Specification. IJ-3080 Specification

Fundamental Data Types

QTERM-J10/N15 USER'S MANUAL REVISION 13

Addmaster Corporation

RS-232 Digital Relay I/O

2D Hand-held Barcode Scanner User Guide

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

The Binary Number System

3.1. Unit 3. Binary Representation

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

RS-232 Control of the Advantage EQ281/8, EQ282/8 and Advantage SMS200

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

J2 LCM Customer Display. Manual

Positional Number System

Serial Communications

Chapter 2 Bits, Data Types, and Operations

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Visual KeyMaker. Programming Software Instructions. Contents A B

AS-8050 CCD Scanner User Guide

PS232. RS-232 to PS/2 Keyboard Port Adapter Part # SA0009 (Version 4.0) Copyright 2003 L3 Systems, Inc. Redmond

KB232. PS/2 Keyboard RS-232 Adapter Part # SA0008 (Version 3.0) Copyright 2003 L3 Systems, Inc. Redmond

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

First Data U.S. Debit Test Card Set. Version 1.20

Do not start the test until instructed to do so!

IPDA014-2D. Embedded 2D Barcode Scan Engine. User Guide

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

APEX & ANDES Series. Printer Command Language Developer s Manual

MOBILE THERMAL PRINTER

User s Manual. Addendum to. Ranger Wedge Interface. Part No. 25-WEDGE-06A Ver. April 1999

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

D730. Remote Display Installation Manual

Hardware. ( Not so hard really )

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

Pins 2, 3 - Baud rate select - Selects the baud rate for the serial transmission.

If your CNC machine memory is full, the PocketDNC gives you more storage, enabling you to store and reload proven programs at a later date.

Under the Hood: Data Representation. Computer Science 104 Lecture 2

Transcription:

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART) Objective: Introduction To understand and apply USART command for sending and receiving data Universal Serial Asynchronous Receive Transmit (USART) a.k.a UART or RS -232, is one of the easiest communication protocols for a device to communicate with PC. It is very useful for seeing what happen inside the microcontroller, for example the reading from Analogue to Digital Converter (ADC). Even when current laptop does not have a serial port, the USB to serial converter with virtual port driver easily solve the problem. The serial port pin description is shown in Figure 8.1. Figure 8.1 The serial port and pin description on the PC Straight through Serial Cable Level Converter Figure 8.2: Connection from microcontroller to PC EEEB371 E8-1

The connection is from microcontroller on required 3 wires simple if no handshaking is required. Figure 8.2 illustrate the connection from microcontroller to PC. The logic levels for serial port for RS 232 port where logic 1 represented by -10V and logic 0 represented by +10V. The microcontroller logic levels are based on TTL or CMOS. ( 5V for logic 1 and 0V for logic 0 ). To match the logic level, a level converter hardware ( e.g MAX232 IC) must be used. Usually data are send and receive through USART in bytes. The bytes usually are represent ASCII characters as shown in Table 8.1(a) and Table 8.1(b). Table 8.1(a) ASCII Printable Characters Dec Hex Character Dec Hex Character Dec Hex Character 32 20 64 40 @ 96 60 ` 33 21! 65 41 A 97 61 a 34 22 " 66 42 B 98 62 b 35 23 # 67 43 C 99 63 c 36 24 $ 68 44 D 100 64 d 37 25 % 69 45 E 101 65 e 38 26 & 70 46 F 102 66 f 39 27 ' 71 47 G 103 67 g 40 28 ( 72 48 H 104 68 h 41 29 ) 73 49 I 105 69 i 42 2A * 74 4A J 106 6A j 43 2B + 75 4B K 107 6B k 44 2C, 76 4C L 108 6C l 45 2D - 77 4D M 109 6D m 46 2E. 78 4E N 110 6E n 47 2F / 79 4F O 111 6F o 48 30 0 80 50 P 112 70 p 49 31 1 81 51 Q 113 71 q 50 32 2 82 52 R 114 72 r 51 33 3 83 53 S 115 73 s 52 34 4 84 54 T 116 74 t 53 35 5 85 55 U 117 75 u 54 36 6 86 56 V 118 76 v 55 37 7 87 57 W 119 77 w 56 38 8 88 58 X 120 78 x 57 39 9 89 59 Y 121 79 y 58 3A : 90 5A Z 122 7A z 59 3B ; 91 5B [ 123 7B 60 3C < 92 5C \ 124 7C 61 3D = 93 5D ] 125 7D 62 3E > 94 5E ^ 126 7E ~ 63 3F? 95 5F _ EEEB371 E8-2

Table 8.1(b) Non printable ASCII character Dec Hex Abbr Character Description 0 0 NUL \0 Null character 1 1 SOH Start of Header 2 2 STX Start of Text 3 3 ETX End of Text 4 4 EOT End of Transmission 5 5 ENQ Enquiry 6 6 ACK Acknowledgment 7 7 BEL \a Bell 8 8 BS \b Backspace[t 4][t 5] 9 9 HT \t Horizontal Tab 10 0A LF \n Line feed 11 0B VT \v Vertical Tab 12 0C FF \f Form feed 13 0D CR \r Carriage return[t 6] 14 0E SO Shift Out 15 0F SI Shift In 16 10 DLE Data Link Escape 17 11 DC1 Device Control 1 (oft. XON) 18 12 DC2 Device Control 2 Device Control 3 (oft. 19 13 DC3 XOFF) 20 14 DC4 Device Control 4 21 15 NAK Negative Acknowledgement 22 16 SYN Synchronous Idle 23 17 ETB End of Trans. Block 24 18 CAN Cancel 25 19 EM End of Medium 26 1A SUB Substitute 27 1B ESC \e Escape[t 8] 28 1C FS File Separator 29 1D GS Group Separator 30 1E RS Record Separator 31 1F US Unit Separator 127 7F DEL Delete EEEB371 E8-3

Procedure Hello World 1. Write the following program, build, download and run the program. void main() // Initialize USART module (8 bit, 9600 baud rate, no parity bit..) Usart_Init(9600); Usart_Write( H ); Usart_Write( e ); Usart_Write( l ); Usart_Write( l ); Usart_Write( o ); Usart_Write( ); Usart_Write( W ); Usart_Write( o ); Usart_Write( r ); Usart_Write( l ); Usart_Write( d ); // Send data via USART // send space 2. On the MikroC program, go to Tools>Usart Terminal. Make sure the setting is the same as your program s USART initialization. Then, click Connect. You may need to reset the microcontroller to rerun the program. After getting the response, Disconnect. Write down the result/response on the worksheet. Simple Send-Receive Program 3. Write the following program, build, download and run the program. EEEB371 E8-4

unsigned char i;// same as unsigned short i; void main() // Initialize USART module (8 bit, 9600 baud rate, no parity bit..) Usart_Init(9600); while(1) // infinite loop if (Usart_Data_Ready()) // If data is received i = Usart_Read(); // Read the received data Usart_Write(i); // Send data via USART 4. Click Connect at the Usart Terminal. Under the communication edit box, type any character and click Send. Observe and record the response. Try with another two different characters. Write down the result/response on the worksheet. After getting the response, Disconnect. Conversion to ASCII 5. Write the following program, build, download and run the program. unsigned char i // same as unsigned short i; void NumtoChar(char a) unsigned char digit[3]; digit[0]=a/100; // get the hundredth digit digit[0]+=0x30; // convert to ASCII a=a%100; // get the remainder digit[1]=a/10; // get the tenth digit digit[1]+=0x30; // convert to ASCII digit[2]=a%10; // get the remainder digit[2]+=0x30; Usart_Write(digit[0]); Usart_Write(digit[1]); Usart_Write(digit[2]); // convert to ASCII void main() // Initialize USART module (8 bit, 9600 baud rate, no parity bit..) Usart_Init(9600); i=125; Usart_Write(i); Usart_Write('\n'); NumtoChar(i); // 8 bit number // new line EEEB371 E8-5

6. Observe and record the response on the USART Terminal. Identify the output for Usart_Write(i) and NumtoChar(i). 7. Based on the sample code above and flow char given, write a program to receive two single digit numbers, add the two numbers and display the results. The response should be as follows: (Bold - send by controller, Italic - is type by user) N1: 1 N2: 2 AN: 003 EEEB371 E8-6

Flow chart: Send character N, 1, : Serial data ready? no yes Receive first character Convert ASCII character to number 0x0F) (AND with Send character \n, N, 2, : Serial data ready? no yes Receive second number/character Convert ASCII character to number 0x0F) (AND with Add first and second number Send character \n, A, n, : Call function NumtoChar to display the addition value 8. Write, build, download and run the program. Demonstrate the output to your instructor. 9. Printout the C program written in procedure 8. Turn off your board. EEEB371 E8-7