Embedded Systems and Software

Similar documents
Embedded Systems and Software. LCD Displays

ECED 3204 Microprocessor Midterm Reference Solution

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

APPENDIX D FLOWCHARTS AND PSEUDOCODE OVERVIEW

By: Dr. Hamed Saghaei

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

Number Systems & Encoding

AVR ISA & AVR Programming (I)

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

DESIGN NOTE #032. AVR Boot Loader. Introduction. Overview AUTHOR: MARIANO BARRÓN RUIZ KEYWORDS: BOOT LOADER, SPM, SELF-PROGRAMMING

;Compiler Options.NOLIST.INCLUDE "C:\Program Files (x86)\atmel\avr Tools\AvrAssembler2\Appnotes\m8515def.inc"

Logic Instructions and Programs READING

BINARY SYSTEM. Binary system is used in digital systems because it is:

Chapter 2 Number Systems and Codes Dr. Xu

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Assembly AVR Boot loader

COMP2121: Microprocessors and Interfacing

Octal & Hexadecimal Number Systems. Digital Electronics

Embedded Systems and Software

Embedded Systems and Software

Chapter 4: Computer Codes. In this chapter you will learn about:

MACHINE LEVEL REPRESENTATION OF DATA

CN310 Microprocessor Systems Design

Final Labs and Tutors

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now)

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Chapter Overview. Welcome to Assembly Language

EE 308: Microcontrollers

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

TOPICS. Other Number Systems. Other Number Systems 9/9/2017. Octal Hexadecimal Number conversion

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

CHW 261: Logic Design

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

COMP2121: Microprocessors and Interfacing. I/O Devices (II)

ENE 334 Microprocessors

Dec Hex Bin ORG ; ZERO. Introduction To Computing

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Digital Fundamentals

Microprocessor Fundamentals. Topic 7 Timing: the Timer/Counter

COMP2121: Microprocessors and Interfacing. Number Systems

CS 261 Fall Binary Information (convert to hex) Mike Lam, Professor

umber Systems bit nibble byte word binary decimal

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

COMP2121: Microprocessors and Interfacing

Speed and Size-Optimized Implementations of the PRESENT Cipher for Tiny AVR Devices

Introduction to Assembly language

AVR Subroutine Basics

Objectives. Connecting with Computer Science 2

EE 308: Microcontrollers

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

Digital Logic Lecture 2 Number Systems

[TUT] Newbie's Guide to AVR Interrupts

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

The type of all data used in a C++ program must be specified

ECE 375: Computer Organization and Assembly Language Programming

COMP2121 Introductory Experiment

Number representations

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

Level ISA3: Information Representation

CHAPTER 2 (b) : AND CODES

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Register-Level Programming

Extending Encoder Button Functionality on your DDS Development Kit

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

The type of all data used in a C (or C++) program must be specified

Numbering systems. Dr Abu Arqoub

COMP3221: Microprocessors and Embedded Systems

Internal Data Representation

IAS0430 MICROPROCESSOR SYSTEMS

CMPS 10 Introduction to Computer Science Lecture Notes

Lab Objectives. 2. Preparations. 3. Signing in. 4. Examining the Host Environment. 5. Part A: Introduction to AVR Studio. 5.

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Module 2: Computer Arithmetic

Chapter 2 Number System

Addressing Modes Part II AVR Addressing Indirect READING

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Chapter 4. Address. data. Input / Output Programming. Simplified Z80 System Architecture. Memory. program. data. Z80 I/O Programming

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CC411: Introduction To Microprocessors

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Introduction to Informatics

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD

Integer Multiplication and Division

WINTER 14 EXAMINATION Subject Code: Model Answer Page No: 1/ 26

ECE 3120 Computer Systems Arithmetic Programming

Principle and Interface Techniques of Microcontroller

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

Octal and Hexadecimal Integers

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Printing this Slide Show

General issues. Format MACROS. Example 1: Extract MS nibble of register A as Lsnibble of Reg. B 7/11/2014

General issues MACROS

COMP Overview of Tutorial #2

8051 Overview and Instruction Set

Number Systems Base r

Data Representation and Binary Arithmetic. Lecture 2

Transcription:

Embedded Systems and Software Lab 4 Considerations Formatting for LCD Slide 1

Lab 4 Issues Displaying the Frequency and Duty Cycle on the LCD Formatting for LCD Slide 2

F = 2 5 H z D C = 7 5. 6 % Formatting for LCD Slide 3

Constant string. Need three F = 2 5 H z D C = 7 5. 6 % Formatting for LCD Slide 4

Displaying Constant Strings sf25:.db "F = 25 Hz" ; Create a static string in program memory..db 0 rcall displaycstring displaycstring: ldi r24,10 ; r24 <-- length of the string ldi r30,low(2*msg) ; Load Z register low ldi r31,2*high(msg) ; Load Z register high L20: lpm ; r0 <-- first byte swap r0 ; Upper nibble in place out PORTC,r0 ; Send upper nibble out rcall LCDStrobe ; Latch nibble rcall _delay_100u ; Wait swap r0 ; Lower nibble in place out PORTC,r0 ; Send lower nibble out rcall LCDStrobe ; Latch nibble rcall _delay_100u ; Wait adiw zl,1 ; Increment Z pointer dec r24 ; Repeat until brne L20 ; all characters are out ret Formatting for LCD Slide 5

F = 2 5 H z D C = 7 5. 6 % Constant strings Formatting for LCD Slide 6

F = 2 5 H z D C = 7 5. 6 % Variable string Formatting for LCD Slide 7

F = 2 5 H z D C = 7 5. 6 % Variable String how do we generate this? Formatting for LCD Slide 8

Formatting for LCD Problem Given a 16 bit (two byte) variable DC_HI:DC_LO which contains a (binary) duty cycle value in the range 0 thru 999, generate the proper display string to show this value on the LCD in the form: xy.z Formatting for LCD Slide 9

ASCII The American Standard Code for Information Interchange (acronym: ASCII) is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text. Most modern character-encoding schemes are based on ASCII, though they support many more characters than do plain ASCII. See http://en.wikipedia.org/wiki/ascii The LCD display uses ASCII character codes. To display, for example, the digit 5, one sends 5 s ASCII code to the display. Formatting for LCD Slide 10

Formatting for LCD Slide 11

Formatting for LCD Slide 12

Formatting for LCD Slide 13

Formatting for LCD Slide 14

HD44780 Character Codes Upper nibble Lower nibble Question: what is the character code for 5 Formatting for LCD Slide 15

HD44780 Character Codes Upper nibble Lower nibble Question: what is the character code for 5? Answer: 00110101 Answer: 0x35 Formatting for LCD Slide 16

Some ASCII Tricks of the Trade The decimal digits 0-9 are represented by the ASCII codes 0x30-0x39 respectively. Dec Hex Oct Html Char So simply add 0x30 to convert the number to its ASCII code: 5 + 0x30 = 0x35 Formatting for LCD Slide 17

Some ASCII Trick of the Trade The letters A-Z are represented by the ASCII codes 65-90 respectively, while the lowercase letters a-z are represented by the ASCII codes 97-122 respectively. Thus, to convert from letters from upper- to lower case, add 33. Formatting for LCD Slide 18

Isolating Digits of the Duty Cycle Consider : DC_HI:DC_LO = 765 Step 1. Divide DC_HI:DC_LO by 10: 765/10 = 76 with a remainder of 5. Thus 5 is the rightmost digit. Step 2. Determine the ASCII code for 5. The digits 0-9 are represented by the ASCII codes 0x30-0x39 respectively. So simply add 0x30: 5 + 0x30 = 0x35 Step 3. Place a decimal point (0x2e) to the left of the rightmost ASCII character Step 4. Now divide the quotient from step 1) by 10: 76/10 = 7 with a remainder of 6. So the next digit (to the left of the decimal point is 6 and the corresponding ASCII code is 6 + 0x30 = 0x36 Step 5. The quotient from Step 4 is the leftmost digit of the duty cycle string: 7 + 0x30 = 0 x37 So the display String is: 0x37, 0x36, 0x2e, 0x35 Formatting for LCD Slide 19

Isolating Digits of the Duty Cycle How do we do the division by 10? AVR instruction set does not include a divide instruction There is no obvious way to isolate the digits of the duty cycle without doing a division operation A lookup table would be very expensive Would require 1000 entries. Formatting for LCD Slide 20

Isolating Digits of the Duty Cycle You can make use of a library of prewritten math subroutines. These are on the Atmel website. See Application Note AVR200: Multiply and Divide Routines. The following sample code uses the routine div16u for unsigned, 16-bit division. It uses these registers.def drem16ul = r14.def drem16uh = r15.def dres16ul = r16.def dres16uh = r17.def dd16ul = r16.def dd16uh = r17.def dv16ul = r18.def dv16uh = r19 Usage is very simple. Load the number you want to divide (say 567), into dd16uh:dd16ul and the number you want to divide by (say 10) into dv16h:dv16l and then call div16u. The result is placed in "dres16uh:dres16ul" and the remainder in "drem16uh:drem16ul". ; Divide (unsigned) 567 by 10 ldi dd16ul,low(567) ; Dividend ldi dd16uh,high(567) ; Dividend ldi dv16ul,low(10) ; Divisor ldi dv16uh,high(10) ; Divisor rcall div16u ; Result (56)in dres16uh:dres16ul ; Remainder (7) in drem16uh:drem16ul Formatting for LCD Slide 21

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc Driver for sample code LCD write code Create static strings in flash memory, but make sure we don t start executing the strings Note how we terminate the strings with nulls this signals the end of the string for the display routine. Also, the number of bytes must be even (why?) other the assembler will complain and pad the string. ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring Formatting for LCD Slide 22

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start Driver for sample code LCD write code ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit Initialize the LCD properly ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring Formatting for LCD Slide 23

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start Driver for sample code LCD write code ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc The displaycstring routine, described later, expects the Z-pointer register to point to the start of the string. This is the standard AVR idiom for loading Z with a string in flash ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring Formatting for LCD Slide 24

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start Driver for sample code LCD write code ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring Call displaycstring routine, which will send the string msg1 out, up to the terminating null byte. The LCD shows DC = Formatting for LCD Slide 25

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start Driver for sample code LCD write code ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring The user changes the duty cycle, so this part of the LCD display must be created dynamically. Assume the user has selected a duty cycle of 56.9%. Formatting for LCD Slide 26

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start Driver for sample code LCD write code ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring The displaydc routine expects the duty cycle in the R26:R25 (MSG:LSB) register pair. In the driver, we hardcode the 569 which represents 56.9% In Lab 4 code the 569 will be a variable, perhaps a register pair. Formatting for LCD Slide 27

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start Driver for sample code LCD write code ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring Display the duty cycle. The LCD shows: DC = 56.9 Formatting for LCD Slide 28

.include "m88padef.inc".cseg.org 0x00 ; PC points here after reset rjmp start Driver for sample code LCD write code ; Create static strings in program memory. msg1:.db "DC = ",0x00 msg2:.db "(%)",0x00 start: ; Intialize the LCD: set to 4-bit mode, proper ; cursor advance, clear screen. rcall LCDInit ; Display the string: "DC = " ldi r30,low(2*msg1) ; Load Z register low ldi r31,2*high(msg1) ; Load Z register high rcall displaycstring ; Display the duty cycle. ldi r25,low(569) ldi r26,high(569) rcall displaydc ; Display the string " (%)" ldi r30,low(2*msg2) ; Load Z register low ldi r31,2*high(msg2) ; Load Z register high rcall displaycstring Display the second static string: (%). The LCD shows: DC = 56.9 (%) Formatting for LCD Slide 29

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM Code to create a string in data memory (RAM). This code formats a 3-digit number as a floating point number. For example 569 56.9 It peels of the digits by successively dividing by 10 and storing results in reverse order (why?). Another routine will then send out these bytes to the LCD. ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 30

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display Create 6 bytes in RAM to hold the string. Note the use of the.dseg assembler directive. ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 31

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display Note the use of the.cseg assembler directive. The following lines are code and not data. ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 32

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) Copy the number we want to display from R25:R26 (that the caller set up) to the registers the 16-bit unsigned divide routine uses ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 33

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) The algorithm successively divide by 10 set this up ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 34

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM Store the terminating null. Notice how we use the assembler to calculate the address for us when it assembles the code ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 35

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM Perform the 16-bit division by 10 ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 36

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM Add 0x30 to the remainder to convert to the digits ASCII code ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Formatting for LCD Slide 37

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Store it in RAM. Note that we put this at the back of the string. Formatting for LCD Slide 38

displaydc:.dseg dtxt:.db 0x00,0x00,0x00,0x00,0x00,0x00.cseg mov dd16ul,r25 ; LSB of number to display mov dd16uh,r26 ; MSB of number to display ldi ldi dv16ul,low(10) dv16uh,high(10) ; Store terminating for the string. ldi r20,0x00 ; Terminating NULL sts dtxt+4,r20 ; Store in RAM ; Divide the number by 10 and format remainder. rcall div16u ; Result: r17:r16, rem: r15:r14 ldi r20,0x30 add r14,r20 ; Convert to ASCII sts dtxt+3,r14 ; Store in RAM ; Generate decimal point. ldi r20,0x2e ; ASCII code for. sts dtxt+2,r20 ; Store in RAM Place decimal point Continue until the whole string is in place Formatting for LCD Slide 39

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Displays a dynamic character string, stored ;; in data (RAM), on the LCD. The string ;; is assumed to be null-terminated. ;; ;; Call: ;; ;; ldi r30,low(dtxt) ; Load Z register low ;; ldi r31,high(dtxt) ; Load Z register high ;; rcall displaydstring ;; ;; displaydstring: ld r0,z+ tst r0 ; Reached end of message? breq done_dsd ; Yes => quit swap r0 ; Upper nibble in place out PORTC,r0 ; Send upper nibble out rcall LCDStrobe ; Latch nibble swap r0 ; Lower nibble in place out PORTC,r0 ; Send lower nibble out rcall LCDStrobe ; Latch nibble rjmp displaydstring done_dsd: ret Code to write a string in data memory (RAM) to the LCD. Formatting for LCD Slide 40

Formatting for LCD Slide 41