Lab 7: Asynchronous Serial I/O

Similar documents
Lecture 13 Serial Interfaces

Programming the Motorola MC68HC11 Microcontroller

Using the stack and the stack pointer

; export symbols ; export 'Entry' symbol. ; include derivative specific macros PORTA EQU $0000 PORTB EQU $0001 DDRA EQU $0002 DDRB EQU $0003

Lecture 9 Subroutines

; export symbols XDEF Entry ; export 'Entry' symbol ABSENTRY Entry ; for assembly entry point

Exam 2 E2-1 Fall Name: Exam 2

EE319K Final Fall 2005 Solution C. (3) Question 1. (3) Question 2. short function(const short in){ return in+5; } const

Exam 2 E2-1 Fall Name: Exam 2

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

The Motorola 68HC11 Instruc5on Set

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

CMPEN 472 Sample EXAM II

538 Lecture Notes Week 3

Sample Problem Set #1

Module 3.F. Serial Communications Interface (SCI) Tim Rogers 2017

Module 1-G. Marcos and Structured Programming

Lecture 6 Assembly Programming: Branch & Iteration

A B C D E F 0480 FE B F5 3B FC F3 E 1A 1D 2A 2D 3A 3D 4A 4D 5A 5D 6A 6D 7A 7D

Cross Assembly and Program Development

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

COE538 Lecture Notes Week 3 (Week of Sept 17, 2012)

ME 6405 Introduction to Mechatronics

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

Coe538 Final Study Guide 2016 (Questions & Answers)

Introduction to Microcontrollers

EE4390 Microprocessors

Outline. 2.8 Stack. 2.9 Subroutines

C SC 230 Computer Architecture and Assembly Language April 2000 Exam Sample Solutions

Review for Exam 3. Write 0x05 to ATD0CTL4 to set at fastest conversion speed and 10-bit conversions

Asynchronous Data Transfer

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

CET335 Microprocessor Interfacing Lab 5: LCD Interface (Bus Attached Peripheral)

ECE 3610 MICROPROCESSING SYSTEMS

EE 3170 Microcontroller Applications

ECE 3120 Computer Systems Arithmetic Programming

538 Lecture Notes Week 3

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

Motorola HC11. Fun with Microcontrollers and Embedded Systems

538 Lecture Notes Week 2

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

Microcontrollers. 2IN60: Real-time Architectures (for automotive systems) Mike Holenderski,

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Getting Started with the HCS12 IDE

Dallas Semiconductor DS1307 Real Time Clock. The DS 1307 is a real-time clock with 56 bytes of NV (nonvolatile)

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

TEMPERATURE SENSOR. Revision Class. Instructor / Professor LICENSE

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Chapter 4: Advanced Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Module 2.F. Buffered, Interrupt-Driven Printer Design Example. Tim Rogers 2017

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

Exam I Review February 2017

0b) [2] Can you name 2 people form technical support services (stockroom)?

Microcontrollers. Microcontroller

Linking Assembly Subroutine with a C Program

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

CS 273 Machine Programming and Organization Lecture Notes

538 Lecture Notes Week 5

Most of the HC12 s instructions access data in memory There are several ways for the HC12 to determine which address to access

Timing Generation and Measurements

Microcontrollers and Embedded Systems. Fun with Motorola/Freescale HC11

Programming Book for 6809 Microprocessor Kit

Lecture 11: Advanced Arithmetic Instructions

Lecture 5 Assembly Programming: Arithmetic

Chapter 2 HCS12 Assembly Language

ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

Reading Assignment. 68HC12 Instruction Set. M68HC12 Instruction Set Categories. Some Tips. Endianness (Byte Order) Load and Store Instructions

An ability to program a microcontroller to perform various tasks

ECE/CE 3720: Embedded System Design

MCO556 Practice Test 2

MIGRATING TO THE 68HC12 IN C

Introduction to Embedded Systems and Chapter 1: Introduction to HCS12/MC9S12. EE383: Introduction to Embedded Systems University of Kentucky

538 Lecture Notes Week 5

Microcontrollers and the Freescale/Motorola HC11

EB301. Motorola Semiconductor Engineering Bulletin. Programming EEPROM on the MC68HC811E2 during Program Execution. Freescale Semiconductor, I

Disassembly of an HC12 Program It is sometimes useful to be able to convert HC12 op codes into mnemonics. For example, consider the hex code:

Exam 1 Feb. 23, 25, 27?

EE 3170 Microcontroller Applications

Introduction to Embedded Microcomputer Systems Lecture 10.1

ECE 372 Microcontroller Design Assembly Programming. ECE 372 Microcontroller Design Assembly Programming

BRANCH IF REGISTER IS HIGHER/GREATHER/ THAN OPERAND e.g. CMPA #$D0

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

CS/ECE 5780/6780: Embedded System Design

ECET Chapter 2, Part 2 of 3

Introduction to Microcontrollers II

SECTION 6 CENTRAL PROCESSING UNIT

Module 1-D. Control Structure Applications. Tim Rogers 2017 [1.D]-1

EE 3170 Microcontroller Applications

ECE/CS 5780/6780: Embedded System Design

Serial Communication Through an Asynchronous FIFO Buffer

CE-320 Microcomputers I Winter 2010 LAB 1: MINIIDE GROUP #: NAME: PARTNER: Lab 1 Page 1

1. Memory Mapped Systems 2. Adding Unsigned Numbers

HC11 Instruction Set

68HC11 Opera,ng Modes

Introduction to Microcontrollers II

CHAPTER 8. Solutions for Exercises

Transcription:

CpE 390 Microprocessor Systems Lab 7: Asynchronous Serial I/O 1. Introduction Serial communications is the transfer of data, one bit at a time, over a communications channel. Serial communications can either be synchronous or asynchronous. In synchronous communications, we send an explicit clock signal with the data. In asynchronous communications, we format the serial data in such a way that the clock in implicitly embedded in the serial data signal. The 68HC12 microcontroller contains on-chip support for both synchronous (e.g. SPI, I 2 C) and asynchronous (RS-232) serial communications. In this lab, we will be using the asynchronous RS-232 communications link (a link that has already been established to allow the MiniIDE software on the PC to communicate with the EVB board. The figure above illustrates the signals produced when data is transmitted across an RS-232 serial connection. When no data is being transmitted, the line is said to be idle. In this state, it is held high. When data is transferred, a START bit (which is always low ) precedes the data to signal to the receiver that a data byte is following. The data is sent LS Bit first. The last (MS Bit) may be a parity bit to allow error detection at the receiving end. After the parity bit, a STOP bit (which is always high ) returns the line to its idle state, ready to transmit the next byte. Serial I/O on the 68HC12 is performed by the Serial Communication Interface (SCI) module. The SCI is controlled, through software, by a number of registers. These registers are special memory locations that transfer data to and from hardware. There are three types of registers used in a peripheral interface: (i) control registers for determining the operation of the peripheral (ii) status registers which tell us the current state of the peripheral and (iii) data registers through which you can send and receive data. There are two separate serial communication po on the 68HC12: SCI0 and SCI1. We will be using SCI0. The registers associated with SCI0 are: SCI0BDH EQU $00C8 ; high byte of SCI0 baud rate control register SCI0BDL EQU $00C9 ; low byte of SCI0 baud rate control register

SCI0CR1 EQU $00CA ; SCI0 Control Register 1 SCI0CR2 EQU $00CB ; SCI0 Control Register 2 SCI0SR1 EQU $00CC ; SCI0 Status Register 1 SCI0SR2 EQU $00CD ; SCI0 Status Register 2 SCI0DRH EQU $00CE ; high byte of SCI0 data register SCI0DRL EQU $00CF ; low byte of SCI0 data register SCI0DRH is only needed when sending or receiving 9-bit data (9 data bits plus parity). When using 8-bit data (7 data bits plus parity), only the SCI0DRL data register is used. The baud rate and control registers of the SCI0 port have already been set up by the DBUG12 monitor to allow communication with the MiniIDE software on the PC. You will not need to modify these registers in order to use the SCI0 to perform simple serial I/O. 2. Procedure (a) Use the monitor program to examine the contents of the SCI0 baud rate and control registers. You can find a detailed description of the meaning of the various fields of these registers in your lecture notes and/or text-book. Explain the settings that have already been programmed into these registers by the DBUG12 monitor. (b) Write a program to be run on your demo board. You may use the input-output routines that were given as part of the lecture notes. They are also reproduced in Appendix A. The program and the user should interact as follows: 1. The program outputs the message Please enter your name: and waits for the user to enter his or her name followed by a CR (ENTER). 2. The program then outputs the message Please enter your age: and waits for the user to enter his or her age followed by a CR (ENTER). 3. The program outputs the message Please enter your height in inches: and waits for the user to enter his or her height followed by a CR (ENTER). The program then prints out the following message on the terminal screen and exits: Your name is www You are xxx years old You are yyy inches tall 4. In Appendix B, you will find two more routines:

The first asctobin conve a decimal ASCII string into an unsigned 8-bit integer. The address of the ASCII string is passed in register X. The routine returns the binary value of the integer in accumulator B. The second bintoasc does the opposite it conve an unsigned 8-bit integer into a 3 digit decimal ASCII string. You pass the binary value of the integer in accumulator B and the address of where you want the routine to place the ASCII string in register X. Modify your program so that before it prints out your name, age and height, it first uses the asctobin routine to convert your height into a binary value and stores it in a named 8-bit memory location. You should then use the bintoasc routine to convert this binary value back to ASCII and use the converted string when you output the person s height. This will, of course, give the same answer. This is just to check that you are using these routines correctly. 5. Now that we have your height in inches as a binary value, you can perform arithmetic on this value. Modify your program to convert your height in inches to centimeters and your print-out sequence to look like: Your name is www You are xxx years old You are zzz cms tall 6. Show your working program to the TA

Appendix A SCI0SR1: EQU $00CC ;serial communications status register SCI0DRL: EQU $00CF ;serial communications data register CR: EQU $0D ; carriage return (ENTER) code LF: EQU $0A ; line-feed code BS: EQU $08 ; back-space code WS: EQU $20 ; (white) space code ; Output the character passed in Accumulator A to the SCI0 putcsci0: brclr SCI0SR1, $80, * ; wait for TDRE to be set staa SCI0DRL ; output the character ; Read a character from the SCI0 and return it in Accumulator A getcsci0: brclr SCI0SR1, $20, * ; wait for RDRF to be set ldaa SCI0DRL ; output the character ; Output a null terminated string to the SCI0. A pointer to the string is passed in register X putssci0: ldaa 1, x+ ; get a character and increment pointer beq done ; end of string? bra putssci0 ; go to next character done: ; Read a CR terminated string from the SCIO and save it as a null terminated string at the ; location pointed to by register X. Echo all input characters and use the backspace character ; to erase previously input characters getssci0: jsr getcsci0 ; get a character from SCIO cmpa #CR ; is it carriage return? beq stend staa 0,x ; save the character ; echo the character cmpa #BS ; is it a backspace character? bne nc ; no, continue dex ; decrement buffer pointer ldaa #WS ; output space character (to erase previous) ldaa #BS ; backspace over space character bra getssci0 ; go get next character nc: inx ; increment pointer bra getssci0 stend: ldaa #LF ; echo LF for CR

clr 0,x ;terminate string with NULL Appendix B ; This routine conve a decimal ASCII string into an unsigned 8-bit integer. ; A pointer to the ASCC string is passed in X. The result in returned in B asctobin: psha ; save A pshy ; save Y ldy #0 ; initialize value to zero abloop: ldaa 1,X+ ; get next ascii char cmpa #$30 ; check for numeric character blo abdone ; if char<'0', then go to next char cmpa #$39 bhi abdone ; if char>'9', then go to next char suba #$30 ; convert from ascii to binary psha ; temp save value on stack tfr Y, B ; mov accum value to B ldaa #10 mul ; mult accum value in B by 10 tfr D, Y ; and store back in Y pulb ; restore value of new char aby ; and add to accum value in Y bra abloop ; go to next character abdone: tfr Y, B ; move result into B puly ; restore registers pula ; and return ; This routine conve an 8-bit unsigned integer into a decimal ASCII string ; The 8-bit value is passed in B. ; A pointer to where the routine should form the string should be passed in X. bintoasc: psha ; save A pshy ; save Y tfr X, Y ; use Y as pointer register ldaa #0 ; clear MSByte of D ldx #10 idiv ; divide by 10 addb #$30 ; convert remainder to ascii stab 2, Y ; store ones Digit tfr X, D ; move quotient to D

ldx #10 idiv ; divide by 10 addb #$30 ; convert remainder to ascii stab 1,Y ; store tens digit tfr X, D ; move quotient to D addb #$30 ; convert to ascii stab 0, Y ; store hundreds digit clr 3, Y ; place NULL at end of string cmpb #$30 ; suppress leading zeros bne baexit movb #WS, 0,Y ; if hundreds digit='0', replace by space ldab 1,Y cmpb #$30 bne baexit movb #WS, 1,Y ; if tens digit='0', replace by space baexit: puly ; restore Y pula ; restore A