Lab 1 MC9S12 Assembler and Monitor

Similar documents
Lab 1 MC9S12 Assembler and Monitor

EE 308 LAB 1 ASSEMBLER, SIMULATOR, AND MONITOR. Introduction and Objectives

Introduction to the 9S12 Microcontroller

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

MC9S12 Address Space

ECE 3120 Fall 2013 Lab 1 Code Entry, Assembly, and Execution

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

ECE 3120 Lab 1 Code Entry, Assembly, and Execution

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

Getting Started with the HCS12 IDE

Chapter 3: HCS12 Hardware and Software Development Tools. The HCS12 Microcontroller. Han-Way Huang. Minnesota State University, Mankato

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

CSE 3215 Embedded Systems Laboratory Lab1: CodeWarrior & the Dragon12

A Simple MC9S12 Program

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Lab 7: Change Calculation Engine

ECE3120: Computer Systems Hardware & Software Development Tools

Introduction to Microcontrollers

COE538 Microprocessor Systems Lab 1: Using the CodeWarrior IDE and Introduction to Assembly Programming 1

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

ECE3120: Computer Systems Hardware & Software Development Tools

Lab 8: Debugging Embedded Devices and Software

Programming the CME11E9-EVBU, Keypad, and LCD

Programming the CME11E9-EVBU, Keypad, and LCD

Lab 2 Part 3 Assembly Language Programming and 9S12 Ports

HC12 Microprocessor. D-Bug12 Functions: Stepping Through Programs & Performing I/O. Dr. Bradley J. Bazuin

Using and Installing: HCS12C128 Board, USB-to-Serial port driver, and HyperTerminal

It translates (converts) assembly language to machine code.

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.

ECE372 CodeWarrior Simulator Andreou/Michaelides

SOFTWARE RELEASE GUIDE FOR THE MOTOROLA "MCUez SDI FOR HC12" SOFTWARE APPLICATION PACKAGE

CMS-8GP32. A Motorola MC68HC908GP32 Microcontroller Board. xiom anufacturing

1. Memory Mapped Systems 2. Adding Unsigned Numbers

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

NEW CEIBO DEBUGGER. Menus and Commands

Freescale Semiconductor, Inc. Debugger. Serial Debug Interface SDI target. Copyright Metrowerks Debugger

ZFSM-201-KIT-1 Wireless UART Application User Guide

C Language Programming, Interrupts and Timer Hardware

68HC12 Training Lab Student Exercise Book

Using CodeWarrior V4.5 Assembler with Adapt9S12X and Serial Monitor

How to use CodeWarrior ASM with Adapt9S12 and Serial Monitor.doc

Reference Guide For D BugS08 Version 1.x.x

Using the stack and the stack pointer

LAB #1: The CSM12C32 Module and PBMCUSLK Project Board

Comparison of C and Assembly How to compile a C program using CodeWarrior

TRACE32 Debugger Getting Started... ICD Tutorial About the Tutorial... 2

Quick Guide to Using Code Warrior

Introduction to Microcontrollers II

Exam 1 Feb. 23, 25, 27?

Introduction to Microcontrollers II

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

HI-WAVE. Serial Debug Interface SDI target. Copyright 1997 HIWARE HI-WAVE

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

Centre for Instrumentation, Control and Automation User s Guide to the MAD 2 Microcontroller Board

Freescale Semiconductor, Inc.

Once the program is installed, a shortcut to the program will be added to your desktop. This will make starting it up easier.

Linking Assembly Subroutine with a C Program

538 Lecture Notes Week 3

History of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram

An Introduction to Komodo

Cross Assembly and Program Development

Lecture 5 Assembly Programming: Arithmetic

Avnet Zynq Mini Module Plus Embedded Design

C Language Programming, Interrupts and Timer Hardware

Using the KD30 Debugger

UNIVERSITY OF HONG KONG DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING

EECS 461 Winter 2009 Lab 1: Familiarization and Digital I/O

Input and Output Ports. How do you get data into a computer from the outside?

EE 308 Spring Lecture 28 March 30, 2012 Review for Exam 2. Introduction to the MC9S12 Expanded Mode

Product Brief M68340EVS EVALUATION SYSTEM

HCS12 Microcontroller and Embedded Systems: Using Assembly and C with CodeWarrior 1 st Edition

Comparison of C and Assembly How to compile a C program using CodeWarrior

UNIVERSITY OF HONG KONG DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING. Principles of Computer Operation

Sample Problem Set #1

ECE 3610 MICROPROCESSING SYSTEMS

Using MSI Logic To Build An Output Port

Required Setup for 32-bit Applications

Lecture #4 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Monday, 25-Jan-2016

EE 308 Spring Lab on IIC Bus

Introduction to the MC9S12 Hardware Subsystems

538 Lecture Notes Week 5

Lecture 6 Assembly Programming: Branch & Iteration

538 Lecture Notes Week 5

XC866 Getting Started on EasyKit & Toolkits

Tutorial for PICMON18 Debug Monitor

Debugging in AVR32 Studio

Trace Getting Started V8.02

Serial Communication Control Interface User s Manual

The 9S12 in Expanded Mode - Using MSI logic to build ports Huang Chapter 14

ZAP Cross Debuggers for Motorola Microcontrollers

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

Using the MC9S12 in Expanded Mode External Ports S12CPUV2 Reference Manual Multiplexed External Bus Interface (MEBI) Module V3 Block User Guide

Updating Reader Firmware

Pre-Lab due: at 3 p.m. Post-Lab due: at 5 p.m. Name:... Forename:... Initials:...

Embedded Development Platform Getting Started Guide for Microchip PIM Carrier Module

HC11 Instruction Set Architecture

Introduction to the M16C Development Environment

_ V Renesas R8C In-Circuit Emulation. Contents. Technical Notes

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

Transcription:

Lab 1 MC9S12 Assembler and Monitor Introduction and Objectives The purpose of this lab is to help you become familiar with your Dragon12-Plus Evaluation Board (EVB), and some of the software tools which you will use to write programs for this course. This laboratory introduces you to the following MC9S12 assembly language programming tools: Freescale CodeWarrior. The D-Bug12 monitor that runs on the MC9S12. An assembler takes assembly language code in a form that a human can reasonably read and write (with a little practice), translates it to machine code which a microprocessor can understand, and stores the machine code in a file which can be uploaded to the microprocessor (Motorola uses a format called S19 for its machine code files). In this lab we will use the Freescale CodeWarrior, which is on the PCs in the Digital/Microcontrollers lab. The assembler of the CodeWarrior produces an output file with an.s19 extension which can be loaded into and run on the MC9S12. The D-Bug12 monitor, running from MC9S12 Flash memory, loads S19 records into the MC9S12 and provides some tools for debugging loaded programs. 1. Prelab You should read this entire lab and answer all of the questions in the pre-lab section before coming to lab. The D-Bug12 monitor allows you to interact with the MC9S12 microcontroller. You can use it to load programs, to find out what is in the MC9S12s registers and memory, to change the contents of the registers and memory, and many other things. The D-Bug12 commands of interest for this lab are: ASM, BF, BR, NOBR, G, HELP, LOAD, MD, MDW, MM, MMW, RM, RD, and T. Read the descriptions of these commands in Chapter 5 of the D-Bug12 Reference Guide, or in Sections 3.5 and 3.6 of Huang.

1.1 Questions to Answer Before Lab 1. What is the difference between the MM and MMW commands? 2. How would you change the value of the X accumulator to 0x55AA? (There are several ways to do this; you only need to find one way.) 3. The Dragon12-Plus has a two-line LCD display, and there is a way for you to identify your board by putting your name (up to 16 characters) on the first line of the display. You can do this by converting your name into ASCII, and putting these ASCII data into a region of the EEPROM on your board. (If your name has less than 16 characters, pad your name at the beginning and/or end with spaces.) Convert you name to ASCII. For example, Jane Smith would become 0x4A 0x61 0x6E 0x65 0x20 0x53 0x6D 0x69 0x74 0x68 0x20 0x20 0x20 0x20 0x20 0x20. You will enter these ASCII characters into you board in lab in Step 7 of Section 2.1. 4. What will be the contents of the A register after each instruction of the program shown in Program 1 executes? Program 1 An assembly language program used to get started with HyperTerminal and D-Bug12. ; MC9S12 demo program ; EE 308 ; This is a program to add four numbers in memory from $1000 through $1003, ; divide the sum by four, and store the result in address $1004 prog: equ $2000 ; Starting address from program data: equ $1000 ; Starting address for data org prog ; Set initial program counter value ldaa input1 ; Load first number into ACCA adda input2 ; add second number adda input3 ; add third number adda input4 ; add fourth number lsra ; divide by 2 lsra ; divide by 2 staa average ; save result in memory

swi org data ; Put data starting at this location input1: dc.b $32 ; First number input2: dc.b $45 ; Second number input3: dc.b $3c ; Third number input4: dc.b $2f ; Fourth number average: ds.b 1 ; Reserve one byte for results 2. The Lab We will use D-Bug12 to explore the memory of the MC9S12 on your evaluation board. The memory map for your MC9S12 is shown on page 24 of the MC9S12DP256B Device Users Guide (zip file). (Look for the figure labeled Normal Single Chip.) Some of the memory is used by the D-Bug12 monitor. For this class you can use RAM from 0x1000 to 0x3BFF, and EEPROM from 0x0400 to 0x0EFF. Normally, you should use the RAM from 0x2000 through 0x3BFF for programs, and from 0x1000 through 0x1FFF for data. In later labs, you will load programs into the EEPROM so the programs will remain on you board after cycling the power. Do not use RAM from 0x3C00 through 0x3FFF or EEPROM from 0x0F00 through 0x0FFF. On your account on the EE network, create a directory for this course (say, U:\EE308). Create a project using the following steps: 1. Start CodeWarrior. 2. Start a new project. 3. Under Device and Connection: Select the appropriate device which is HCS12D Family:MC9S12DP256B. Under connections select Full Chip Simulation. 4. Under Project Parameters: Choose an appropriate name for the project and place it in U:\EE308\LAB01). unselect C and select Absolute assembly. 5. Click Finish.

6. Under Edit/Standard Settings/Target/Assembler for HC12: Click on options and select Generate a listing file. 7. In the left-hand panel will be a tree of the project with a file called main.asm. Doubleclick on main.asm, and edit the file to match Program 1. (You can edit the file at home, and replace the main.asm file in the Sources subdirectory with that file). 8. Save and assemble the file. (To assemble the file, click on the Project drop-down menu, and select Make.) This will generate a Project.abs.s19 file that you can download onto your Dragon12 board and a Project.abs.lst which is a listing of your program after making the project. The two files are in the bin subdirectory. 9. Edit the Project.abs.s19 file, remove the first line then save it. 2.1 Answer the Following During Lab Here are some questions on the output of the assembler. Be sure to answer these questions in you lab book. 1. Look at the lab01.lst file. Where in memory will the machine code for the instruction staa average be stored? 2. What machine code is generated for the staa average mnemonic? Is this what you expected? (Look up the STAA instruction in MC9S12 CPU12 Core Users Guide, to determine what code this instruction should generate.) 3. At what address will the variable average be located in the MC9S12 memory? Connect your Dragon12-Plus board to your computer using the included serial cable. To connect to Dragon12 we can use two methods: HyperTerminal and Putty. Connection to Dragon12 with HyperTerminal a. Make sure HyperTerminal is running with the following setting and then power up the Dragon12-Plus board. (Note: In the Digital Lab, the built-in USB-to-Serial adapter on the Dragon12-Plus board will appear as com4. b. If you conned the adapter to your personal computer, it may appear with a different number. If you do not have HyperTerminal on your personal computer, you can use a different program, such AsmIDE and MiniIDE as discussed in the text.) c. Set the correct serial communication parameters:

Serial port COM4 9600 Baud N81 (no-parity - 8bits data - 1 stop bit). Xon/Xoff flow control Connection to Dragon12 with Putty a. Press windows+r to open the run dialog and type cmd to open Command Prompt b. Use the command chgport to show the com devices c. Plug the microcontroller in and use chgport to see the port for the new device. d. Open Putty. Choose Serial as the connection type. *To enable backspace, select keyboard in the menu on the left and change the backspace key to Control-H e. In the Left Menu go to Connections and select Serial f. Set the Serial line to the COM Port that was found in Step 3, e.g. COM3 g. Set the correct parameters: Speed (baud) - 9600 Data Bits 8 Stop Bits 1 Parity None Flow Control XON/XOFF h. Click open to start the connection

Loading a Program a. Locate the.s19 file in the Project Folder > bin. b. Open the file and copy everything except the first line. Note: The first line is a header containing unimportant information that can take up space that might be otherwise needed. c. Go to the Putty Session and type load and right-click in the window to load your program.

Can t Write Target Memory is a warning caused by leaving out the first line of the.s19 file but does not prevent the program from working. Sending Output to a Text File a. Open Putty and go to Logging in the menu on the left side. b. Under Session Logging: select Printable output c. Click on browse to choose where the output file is located and named. d. Start Putty normally Changing Baud Rate (to be used in another lab) a. Open the Putty Session normally b. Set the baud rate on the board using the command baud [rate]. The possible baud rates for the Dragon-Light are 9600, 38400, 57600, and 115200.

c. Restart putty and set the new baud rate in Putty and start the session. Note: Resetting the board will reset the baud rate. You can use the Abort button to terminate a program instead. 4. Use the MM command to put 0x55 into memory location 0x2000 and 0xAA into memory location 0x2001. Use the MD command to verify that this was done. To exit this mode, type a period before hitting ENTER. 5. Use the MMW command to put 0x55 into memory location 0x2100 and 0xAA into memory location 0x2101. Use the MD command to verify that this was done. 6. Use the BF command to load 0x55 into memory locations 0x2800 to 0x2FFF. Use the MD command to verify that it worked. 7. Use the MM command to put the ASCII value of W into address 0xFDE and the ASCII value of C into address 0xFDF. Then put the ASCII representation for your name into addresses 0xFE0 through 0xFEF. Use the MD command to verify these addresses hold the correct values. Push the Reset button. Your name should now be in the first line of the LCD display. 8. Use the ASM 2000 command to enter the following simple program at address 0x2000. (What does this program do?) ldaa #$1C adda #$A5 clrb decb staa $1000 stab $1001 swi 9. You can trace (execute your program one step at a time) through your program by setting the PC (Program Counter) to the address of the first instruction of your program, and then use the T (Trace) command. Use the RM command to change the value of the Program Counter to 0x2000, the address of the first instruction of the simple program. Trace through your program and observe what is happening to the registers and memory. (Use the MD command to display memory.) Verify that the values in A and B are what you expect after each instruction. 10. Use the G 2000 command to run your entire program.

11. Load your program lab01.s19 into the EVB. To do this, type LOAD into the terminal window, then use the Transfer:Send Text File...menu option to send the program to the EVB. 12. In the Terminal window type ASM 2000 followed by the ENTER key. You should see the first instruction of your program, along with its address and machine code. Each time you hit ENTER you should see the next instruction in the program. To exit this mode, type a period before hitting ENTER. 13. Trace through your program. How do the contents of the A register compare to what you predicted in the Pre-lab after the execution of each instruction? 14. When you are done tracing through your program, reload it and run the entire program by giving the command: G 2000. Verify that the program worked correctly. 15. When debugging a long program, it is impractical to step through the entire program to get to the section of code which is giving problems. A breakpoint is a way to run a program up to the point in the code you want to debug, and stop there. After stopping at the breakpoint, you can then trace through your code to try to resolve the problem. You can set a breakpoint with the BR command. The format is BR xxxx, where xxxx is the address you want to break at. Find the address of the first lsra instruction, and set a breakpoint there. Give the command G 2000, and your program should run until it is ready to execute the first lsra instruction. You can trace through your program after that to see what the instructions do. Do this. When done, use the NOBR command to remove the breakpoint. 16. Change the two lsra instructions to asra instructions. Rerun your program. Does it give a different result? Why?