EXERCISE 3: String Variables and ASCII Code



Similar documents
SMC 3000 Series Master Clock Programming Manual (V3) Table of Contents. Getting Started.. Page 2. Setting the Time of Day...

ET-BASE AVR ATmega64/128

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

E-Blocks Easy Internet Bundle

Memory is implemented as an array of electronic switches

ECIO40P ECIO28P ECRM40. Page 1. USB programmable microcontrollers. 0.6 DIP footprint. Supplied with a free version of Flowcode. E-blocks compatible

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

E-Blocks Easy RFID Bundle

3. Programming the STM32F4-Discovery

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

for ECM Titanium) This guide contains a complete explanation of the Driver Maker plug-in, an add-on developed for

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V]

Chapter 13. PIC Family Microcontroller

CM HOST CM CardTransporter Fuel Communication and Management Software Software version up to 3.1

RAM & ROM Based Digital Design. ECE 152A Winter 2012

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

An Introduction to MPLAB Integrated Development Environment

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

DVR GUIDE. Using your DVR/Multi-Room DVR WAVE-123 wavebroadband.com

Development of Low Cost Private Office Access Control System(OACS)

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Lab Experiment 1: The LPC 2148 Education Board

RS232 Board datasheet

Counting in base 10, 2 and 16

Programming Flash Microcontrollers through the Controller Area Network (CAN) Interface

PICmicro tm Development Board

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

SubCue Analyzer Software - Introduction

HOMEWORKS. RS-232 Protocol. Data Protocol for Communicating with Lutron's HOMEWORKS System

Management Challenge. Managing Hardware Assets. Central Processing Unit. What is a Computer System?

Homework # 2. Solutions. 4.1 What are the differences among sequential access, direct access, and random access?

Switch board datasheet EB

8051 MICROCONTROLLER COURSE

Catalog Number 2711-ND1. User Manual

ViviCam 25 Digital Camera User s Manual

4 Character 5x7 LED Matrix Display

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

Embedded Systems Design Course Applying the mbed microcontroller

Keystation Pro 88 Advanced Guide. Contents: 1 Getting Started. 2 Terminology. 3 Performance Operations of the Keystation Pro 88

Android, Bluetooth and MIAC

Getting to Know Xsight Home Screen and Everyday Use Settings PC Setup


DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

MS Access Lab 2. Topic: Tables

VMWare Workstation 11 Installation MICROSOFT WINDOWS SERVER 2008 R2 STANDARD ENTERPRISE ED.

User Manual. DG LINK Application Program This document applies to firmware version 2.00 and above.

Jianjian Song LogicWorks 4 Tutorials (5/15/03) Page 1 of 14

================================================================

Training Simulator and Demo Software

Using SQL Server Management Studio

A Computer Glossary. For the New York Farm Viability Institute Computer Training Courses

Programming Logic controllers

INGENIEURBÜRO FÜR TECHNOLOGIE TRANSFER DIPL.-ING. B. P. SCHULZ-HEISE. Getting Started with. S7 for Windows. Version 6.x

PID Control. Proportional Integral Derivative (PID) Control. Matrix Multimedia 2011 MX009 - PID Control. by Ben Rowland, April 2011

LED board datasheet EB

Parallax Serial LCD 2 rows x 16 characters Non-backlit (#27976) 2 rows x 16 characters Backlit (#27977) 4 rows x 20 characters Backlit (#27979)

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

13-1. This chapter explains how to use different objects.

Getting Started on the Computer With Mouseaerobics! Windows XP

Automated Inventory System

Packs Infotel Limited M30. ULTIMATE Operating Instructions. Version: Copyright Packs Infotel Limited 2015, all rights reserved.

Controller for AD9850 DDS Modules Andy Talbot G4JNT

winhex Disk Editor, RAM Editor PRESENTED BY: OMAR ZYADAT and LOAI HATTAR

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

Upgrading from Windows XP to Windows 7

2.0 Command and Data Handling Subsystem

1. SAFETY INFORMATION

Operating Systems. and Windows

If you are having a problem or technical issue regarding your IP Telephone, please call the UAA IT Call Center at

EPIC 950 THERMAL TICKET PRINTER

Step by step guide how to password protect your USB flash drive

Base Conversion written by Cathy Saxton

Connecting your Omega/BetaPAT PLUS to a PC via a USB

Training Document for Comprehensive Automation Solutions Totally Integrated Automation (T I A) MODULE A5 Programming the CPU 314C-2DP

Serial Communications

CHAPTER 11: Flip Flops

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

The goal is to program the PLC and HMI to count with the following behaviors:

4511 MODBUS RTU. Configuration Manual. HART transparent driver. No. 9107MCM100(1328)

Deposit Direct. Getting Started Guide

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

SP8 Programmers 硕 飞 科 技. User's Guide. TEL: FAX: WEB:

Downloading <Jumping PRO> from Page 2

Introduction to Microcontrollers

User Guide. Aastra 6753i

LEN s.r.l. Via S. Andrea di Rovereto 33 c.s CHIAVARI (GE) Tel Fax mailto: len@len.it url: http//

CGS 1550 File Transfer Project Revised 3/10/2005

This Skill Builder demonstrates how to define and place sketched symbols in drawings.

Keil C51 Cross Compiler

Basic Computer Skills for Beginners. Mesa Regional Family History Center

GSM Autodialer Professional GJD700 Speech & Text Autodialer

User Manual. AS-Interface Programmer

Evolution USB Keyboards. 249/361 USB MIDI Controller Keyboard

c0003 A Simple PIC Application CHAPTER 3

Candidate FAQs & User Guide for the ALSG Learning Site

UM0853 User manual. 1 Introduction. M24LRxx application software user guide

Device Installer User Guide

Transcription:

EXERCISE 3: String Variables and ASCII Code EXERCISE OBJECTIVE When you have completed this exercise, you will be able to describe the use of string variable and ASCII code. You will use Flowcode and the FACET board to store sequences using the Keypad. EXERCISE DISCUSSION Using String Variables Strings are collections of Byte variables. A string can be used to store a sequence of numbers or a sequence of letters. When you declare a string of a certain length, you actually declare an array of Byte variables where the number of bytes corresponds to the string length. Every character of the string you declare is stored as an 8 bit value in a separate byte in the RAM memory. For example, if you declare this: text[4], then the text in the string variable 'text' can be 4 characters long. In fact, this string variable could be used to store the word 'JOHN' in. If you don't declare a size next to the name of your string variable, Flowcode will set it to the default size of 20. Be aware of the maximum of 368 8-bit variables that can be stored in the PIC16F877A. Arrays You may have come across Array variables before. In Flowcode 3 Strings and Arrays are equivalent. Arrays are 2 or more variables with the same name and a different 'member number' between square braces. For example, if you declare a string as: MY_ARRAY[8], then 8 different 8-bit variables are declared at once. They can all be addressed separately by adding the correct member number between square braces: in this case MY_ARRAY[0] to MY_ARRAY[7]. Strings / Arrays are used in cases where a number of similar variables are needed. 200 FACET by Lab-Volt

Decisions, Macros, and String Variables ASCII Where strings are used to store a sequence of letters they will be represented in 'ASCII' format. ASCII stands for American Standard Code for Information Interchange and it is an internationally recognized standard for using numbers to represent letters. Although each letter in the string is represented by an 8 bit byte, in fact only 7 of the bits are used with the spare bit left as 0. You can look up the corresponding numbers for each character in an ASCII table below. The following tableshows the ASCII characters or symbols and their binary, decimal and Hex equivalents. FACET by Lab-Volt 201

EEPROM This is a convenient point to introduce another facility that the PICmicro can offer you: Electrically Erasable Programmable Read Only Memory, or EEPROM. All PICmicro devices have Read Only Memory (ROM), Random Access Memory(RAM), and Electrically Erasable Programmable Read Only Memory (EEPROM). ROM is where your program is stored and can not be altered while the program runs. RAM is where your variables are stored and this can be written to and read from as your program runs, but the contents are lost as soon as the power is removed from the chip. EEPROM can be written to and read from as your program runs, but the contents are preserved when the power is removed. This means that the contents are available again the next time you use the device. EEPROM is useful in many situations where the settings a user makes need to be preserved for the next time the system is used. For example, remembering the frequency a television channel is tuned to. EXERCISE QUESTIONS Collections of Byte variables that can be used to store a sequence of numbers or letters are a. ASCII code. b. Arrays. c. Strings. Two or more variables with the same name and a different "member number" between square braces are a. ASCII code. b. Arrays. c. Strings. In Flowcode, Strings and Arrays are equivalent. a. True b. False EXERCISE PROCEDURE Set up the equipment The following is the equipment you will need for this exercise: Multiprogrammer Hardware: Setting: PICmicro Device Toggle Switch (Fast/Slow) Toggle Switch (RC/XTAL) XTAL PORTA PORTB PORTC PORTD PORTE 16F877A N/A XTAL 19,660,800 Hz N/A LCD Block N/A Keypad N/A 202 FACET by Lab-Volt

Decisions, Macros, and String Variables Exploring the keypad In this section we will take a look at how the keypad works. Using the keypad to enter only a single digit is easy enough, but using it to enter numbers larger than 10 introduces some complexities. First the basics though: 1. Start a new flowchart using a 16F877A device. 2. Onto your flowchart put a keypad component and an LCD display. Connect the keypad to port D and the display to port B. 3. Select EDIT...VARIABLES from the menu and assign a new Byte variable 'key'. 4. Assemble the following flowchart: FACET by Lab-Volt 203

In top to bottom icon order this is explained as follows: start the LCD display, an endless loop, using the Cursor 0.0 macro set the LCD cursor to 0,0 (top left), call the GetKeypadNumber macro and put the result in the variable 'key'. 204 FACET by Lab-Volt

Decisions, Macros, and String Variables Last display variable 'key' on the LCD using the LCD PrintNumber macro. 5. Add comments to each Icon as shown in the graphic of the program. 6. Run this program in the simulator, then save it as Ex 3 Keypad with your initials to your folder before running it on the FACET Board. When you run the program you will see that, to start with, the LCD displays the number 255. This is what the keypad returns when there is no button pressed. When you press a key, the display will print the number of the key pressed. However, you will notice that it does not erase all of the old number. To modify the program, enter a new LCD Component macro with the function Clear after the cursor 0,0 macro and you will see only the number pressed. FACET by Lab-Volt 205

On the keypad there are the numbers 0 to 9 as well as # and * keys. These are allocated the numbers 10 and 11. You can use the and * keys as control characters to allow humans to indicate that the number is complete a bit like the Enter key on your computer keyboard. 7. Save this program as Ex 3.1 Keypad with your initials to your folder. Run this program first in the simulator, then on the FACET Board. NOTE: When you run this program using the simulator, the numbers will be flashing. This is due to the refresh rate of the monitor, the clock speed, and the program size as the program clears the numbers through each loop. This effect will not be as bad when you download the program to the FACET Board. Seeing ASCII 1. In your previous program, alter the Keypad Component macro to use the GetKeypadASCII macro rather than the GetKeypadNumber macro. This will put an ASCII number into the variable 'key'. Save this as Ex 3.2 Keypad with your initials. 2. Run your program again. You will notice that the ASCII for the key '1' is decimal 49, '2' is 50 etc. No key pressed still returns value 255. 3. In the LCD Component macro, alter the macro PrintNumber to PrintASCII. Save this as Ex 3.3 Keypad with your initials. 4. Run the program again. You will see that the display once again displays the numbers '1' to '9', '*' and '#'. The no key pressed displays a 'y' with an umlaut - the LCD characters set includes many characters other than just ASCII. So the interesting thing here is that the ASCII system allows you to store numbers as the ASCII equivalent and then display them as the number equivalent. Here is a standard we can use for storing both numbers and letters at the same time. What we need to do next is implement a system that allows us to gather a string of numbers from the keypad. Getting the phone number One good example of gathering long numbers is getting a multiple digit number. This could be a phone number, a password, or a number between 0 and 1023. 1. Start a new program and save it as Ex3 Getting the Phone Number with your initials. 2. Create the program shown next. 206 FACET by Lab-Volt

Decisions, Macros, and String Variables Page1 FACET by Lab-Volt 207

Page2 208 FACET by Lab-Volt

Decisions, Macros, and String Variables Page3 3. The following is an explanation of this program: The first 4 Component macros set up the LCD display. Then there is a Calculation icon which sets up the variables used in the program. The variable 'KEY' is used to store the key pressed in ASCII. The string PHONE_NO is used to store the numbers - a maximum of 11 digits. Next there is a Connection point A, followed by the Keypad macro that assigns the variable 'KEY' to the keypad input. The first decision box detects the condition that no key is pressed. This goes to a point at the end of the program where the variable 'OLD_KEY' is assigned to the input. 'OLD_KEY' is used as a flag to allow us to monitor whether the input has changed. This helps de-bounce the input so that we do not get, say, 6 digit 1's when we press the '1' key. The next decision box detects if the new input is the same as the old input (KEY=OLD_KEY), and returns the program to the point A if the keypad number is the same. FACET by Lab-Volt 209

The next decision box looks for ASCII 42 - the '*' key. This is used to denote a cancel operation. If the '*' key is pressed the first byte of the array is set to 0 and the macro is sent to the end point. The next decision box looks for ASCII 35 - the '########' key. This is used to denote an Enter operation. If the '' key is pressed the last byte of the array is set to 0 and the program is routed to the end point. During the program we use the variable PTR to allow us to track which digit in the string is being entered. The string has 10 characters: 0 to 9. The variable PTR must be increased each time a digit is entered allowing each digit to be stored in a separate character of the string. The next decision box tests whether this is the first character or not. If it is the first character then the display is cleared. Next a Calculation icon declares: PHONE_NO = KEY. This assigns the current character of the string to be the value entered on the keypad. The next icon in the main loop then displays the key pressed on the LCD so that the user has visual confirmation that the system has detected the key press. This is followed by a Calculation icon where the value PTR is increased by 1. This means that the next character entered on the keypad will be stored in the subsequent character of the array. At the end of the main loop we store the key pressed in OLD_KEY as described above, then wait 100ms, and then loop back to the beginning of the macro. Try this program in simulation, then on the FACET Board. If your program does not work, see your instructor for a copy of a working program to compare. EEPROM With reference to the previous example: 1. Add an EEPROM component to the workspace. 2. Add a new Component macro to your program just after the LCD is updated with the key the user presses. In this Component macro use the EEPROM WriteEEPROM macro using the variables PTR as the memory location, and KEY as the data. You can see the window shown here. 210 FACET by Lab-Volt

Decisions, Macros, and String Variables 3. Simulate your program. If you watch the EEPROM Flowcode component then you should see that as you enter numbers they are stored in the EEPROM memory. 4. Save this new program and try it first in simulation, then on the Microcontroller System Development FACET Board. Reading data back from the EEPROM is very similar to writing data from it: you simply specify a variable where you want to place the data, specify the address you want to read it from. EXERCISE QUESTIONS 1. When no number on the keypad was pressed, the LCD displayed a. nothing. b. 000 c. 255 2. Without Strings and ASCII, the largest number you could display was a. 10 b. 11 c. 100 3. Using NUMARRAY[10] you can store a maximum of a. 11 digits b. 10 digits. c. 10 decimal places. 4. The Get a Phone Number program relies on a number of jump points and subroutines to provide the end result. a. True b. False FACET by Lab-Volt 211

EXERCISE CONCLUSION Strings are collections of Byte variables. A string can be used to store a sequence of numbers or a sequence of letters. Every character of the string is stored as an 8 bit value in a separate byte in the RAM memory. Where strings are used to store a sequence of letters, the letters will be represented in ASCII format. EEPROM memory is useful where settings need to be preserved for the next time a system is used. REVIEW QUESTIONS 1. Strings are: a. collections of Byte variables. b. different from an array in Flowcode. c. used to store only sequences of numbers. d. All of the above are correct. 2. There is a limit to the number of 8-bit variables that can be stored in the PIC16F877A. a. True b. False 3. Where strings are used to store a sequence of letters, they are represented in format. a. ASCE b. ASCI c. ASCII d. None of the above is correct. 4. can be written to and read from as the program runs, and the contents are preserved when the power is removed. a. RAM b. ROM c. EPROM d. EEPROM 5. To read data back from the EEPROM, a. specify a variable where you want to place the data. b. specify the address you want to read from. c. it is not possible to read data back from the EEPROM. d. Both a and b are required. CMS AVAILABLE FAULTS AVAILABLE 212 FACET by Lab-Volt