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

Similar documents
EXPERIMENT 8: 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

Data Representation and Binary Arithmetic. Lecture 2

MK D Imager Barcode Scanner Configuration Guide

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

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.

Fundamentals of Programming (C)

S-Series Sensor ASCII Protocol v8.1.0

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

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

Universal Asynchronous Receiver Transmitter Communication

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

Number Representations

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

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

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

ASCII Code - The extended ASCII table

Do not start the test until instructed to do so!

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

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

Lecture (09) x86 programming 8

A GUIDE TO RS-232 COMMUNICATION WITH FX PLCS

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.

2D Barcode Reader User Guide V 1.2.1

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

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

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

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

Chapter 8. Characters and Strings

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

Chapter 2 Bits, Data Types, and Operations

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

Fundamentals of Programming

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

Chapter 2 Number System

Chapter 2 Bits, Data Types, and Operations

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

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

Chapter 2 Bits, Data Types, and Operations

ASSIGNMENT 5 TIPS AND TRICKS

Characters Lesson Outline

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

Chemistry Hour Exam 2

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

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

2D BARCODE SCANNER CA-SC-20200B

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

Oberon Data Types. Matteo Corti. December 5, 2001

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

RS-232 Digital Relay I/O

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

NC-1200 BARCODE SCANNER. Configuration Guide - 1 -

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

Connecting UniOP to Datalogic Barcode Readers

RS-422 Code-Operated Switches

Chapter 2 Bits, Data Types, and Operations

Xi2000-BT Series Configuration Guide

2D Hand-held Barcode Scanner User Guide

User s Manual. Xi3000 Scanner. Table of Contents

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

BD-6500BT Bluetooth 2D Barcode Scanner Configuration Guide

BARCODE SCANNER. Configuration Guide - 1 -

Menu & commands booklet FOR BAR CODE SCANNERS * *

Fundamental Data Types

Addmaster Corporation

Positional Number System

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

3.1. Unit 3. Binary Representation

The Binary Number System

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

QTERM-J10/N15 USER'S MANUAL REVISION 13

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

Do not start the test until instructed to do so!

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

ELCT706 MicroLab Session #4 UART Usage for Bluetooth connection PC - PIC

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

Chapter 2 Bits, Data Types, and Operations

Visual KeyMaker. Programming Software Instructions. Contents A B

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

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

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

AS-8050 CCD Scanner User Guide

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

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

Hardware. ( Not so hard really )

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

J2 LCM Customer Display. Manual

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

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

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

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

MOBILE THERMAL PRINTER

ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2

Datalogic Scanning, Inc. 959 Terry Street Eugene, Oregon Telephone: (541) Fax: (541)

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

Transcription:

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART) Objective: To understand and apply USART command for sending and receiving data Introduction 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 9.1. Figure 9.1 The serial port and pin description on the PC EEEB371 E7-1

PIC18F4550 Figure 9.2: Connection from microcontroller to PC The connection is from microcontroller on required 3 wires simple if no handshaking is required. Figure 9.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 sending and receive through USART in bytes. The bytes usually are represent ASCII characters as shown in Table 9.1(a) and Table 9.1(b). EEEB371 E7-2

Table 9.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 E7-3

Table 9.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 E7-4

Library Routines UARTx_Init UARTx_Data_Ready UARTx_Tx_Idle UARTx_Read UARTx_Read_Text UARTx_Write UARTx_Write_Text to set the baudrate 1 - if data is ready for reading 0 - if there is no data in the receive register 1 - if the data has been transmitted 0 - otherwise Returns the received byte. Reads characters received via UART until the delimiter sequence is detected data to be sent Sends text via UART. Text should be zero terminated. Procedure Hello World 1. Construct the simple UART circuit below using PROTEUS. EEEB371 E7-5

2. Write the source code in MikroC Compiler, build it and download the Hex file into the microcontroller and simulate the PROTEUS program. Print out the source file and write down your observation. UART1_Write is used to send a character. //Put students ID No and Names here! void main() // Initialize USART module (8 bit, 9600 baud rate, no parity bit..) UART1_Init(9600); UART1_Write('H'); UART1_Write('e'); UART1_Write('l'); UART1_Write('l'); UART1_Write('o'); UART1_Write(' '); UART1_Write('W'); UART1_Write('o'); UART1_Write('r'); UART1_Write('l'); UART1_Write('d'); // Send data via USART // send space 3. Write the source code in MikroC Compiler, build it and download the Hex file into the microcontroller and simulate the PROTEUS program. Print out the source file and write down your observation. UART1_Write_Text is used to send a text. //Put students ID No and Names here! void main() char *output ="HELLO WORLD"; // Initialize USART module (8 bit, 9600 baud rate, no parity bit..) UART1_Init(9600); UART1_Write(13); // new line UART1_Write_Text(output); EEEB371 E7-6

Simple Send-Receive a character Program 4. Write the source code in MikroC Compiler, build it and download the Hex file into the microcontroller and simulate the PROTEUS program. Print out the source file and write down your observation. //Put students ID No and Names here! unsigned char i;// same as unsigned short i; void main() // Initialize USART module (8 bit, 9600 baud rate, no parity bit..) UART1_Init(9600); while(1) // infinite loop if (UART1_Data_Ready()==1) // If data is received i = UART1_Read(); // Read the received data UART1_Write(i); // Send data via USART UART1_Write(13); // new line 5. Click the Virtual Terminal and type any character. Observe and record the response. Try with another two different characters. Write down the result/response on the worksheet. Conversion to ASCII 6. Write the following program, build, download and run the program. //Put students ID No and Names here! 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; UART1_Write(digit[0]); UART1_Write(digit[1]); UART1_Write(digit[2]); // convert to ASCII void main() // Initialize UART1 module (8 bit, 9600 baud rate, no parity bit..) UART1_Init(9600); i=125; // 8 bit number UART1_Write(i); UART1_Write(13); // new line NumtoChar(i); EEEB371 E7-7

7. Observe and record the response on the Virtual Terminal. Identify the output for Usart_Write(i) and NumtoChar(i). 8. Based on the sample code above and flow chart given in the following page, 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 typed by the user) N1: 1 N2: 2 AN: 003 9. Write, build, download and run the program. Demonstrate the output to your instructor. 10. Printout the C program written in procedure 8. Turn off your board. EEEB371 E7-8

Flow chart for Procedure 8: 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 EEEB371 E7-9