Introduction to the 9S12 Microcontroller

Similar documents
MC9S12 Address Space

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

A Simple MC9S12 Program

Lab 1 MC9S12 Assembler and Monitor

Lab 1 MC9S12 Assembler and Monitor

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)

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

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.

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

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

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

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

Exam I Review February 2017

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

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

1. Memory Mapped Systems 2. Adding Unsigned Numbers

ECE 3120 Lab 1 Code Entry, Assembly, and Execution

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

Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...


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

Lecture 5 Assembly Programming: Arithmetic

Mark II Aiken Relay Calculator

It translates (converts) assembly language to machine code.

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

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

EE 3170 Microcontroller Applications

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

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

CHAPTER 8. Solutions for Exercises

Microcontrollers. Microcontroller

Programming the Motorola MC68HC11 Microcontroller

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

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

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

Lecture 11: Advanced Arithmetic Instructions

Microcontrollers and the Freescale/Motorola HC11

Lecture 7 Assembly Programming: Shift & Logical

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

Cross Assembly and Program Development

538 Lecture Notes Week 2

Exam 1 Feb. 23, 25, 27?

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

Introduction to 6811 Programming

ELEG3924 Microprocessor

Introduction to Computers - Chapter 4

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

538 Lecture Notes Week 3

Lecture 6 Assembly Programming: Branch & Iteration

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

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

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

ECE 4510/5530 Microcontroller Applications Chapter 1

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

Computer Organization I. Lecture 28: Architecture of M68HC11

8051 Microcontrollers

ECE 3120 Computer Systems Arithmetic Programming

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Introduction to Microcontrollers

Homework 12 Solutions

HC11 Instruction Set

Getting Started with the HCS12 IDE

Lab 2 Part 3 Assembly Language Programming and 9S12 Ports

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

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Immediate vs. Extended mode: Immediate values are marked with a # symbol. They also are different instructions when assembled.

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

Lab 5: Arithmetic Logic Unit (ALU)

EE 308: Microcontrollers

Chapter 7 Central Processor Unit (S08CPUV2)

Using the stack and the stack pointer

ECE 367 -Experiment #1 Fall 2012

Sample Problem Set #1

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

EMCH 367 Fundamentals of Microcontrollers Example7 EXAMPLE 7

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3

ECE 3610 MICROPROCESSING SYSTEMS

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

538 Lecture Notes Week 5

538 Lecture Notes Week 5

Total: EEL 3701 Digital Logic & Computer Systems Final Exam Fall Semester 2007 COVER SHEET: Re-Grade Information: 1 (10) 2 (10) 3 (10) 4 (14) 5 (14)

Chapter 2 HCS12 Assembly Language

Introduction to CPU architecture using the M6800 microprocessor

Linking Assembly Subroutine with a C Program

EEL 4744C: Microprocessor Applications. Lecture 7. Part 2. M68HC12 Interrupt. Dr. Tao Li 1

Lab 4: Arithmetic Logic Unit (ALU)

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

Microprocessors/Microcontrollers

68HC12 Training Lab Student Exercise Book

ECET Chapter 2, Part 3 of 3

CS/ECE 5780/6780: Embedded System Design

Lecture Objectives. Introduction to Computing Chapter 0. Topics. Numbering Systems 04/09/2017

Microcomputer Architecture and Programming

the SAP-2 I. Intro cmpt-150-arc Sections 8-8, 8-9, 9-4, 9-5, 9.6, We ll do this in bits and pieces, doing the beginning of each section first.

Lecture 9 Subroutines

Ryerson Polytechnic University Department of Electrical Engineering COE328 Digital Systems. (2 Weeks) FORMAL REPORT - 30 Marks Due Date: Week 13

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

Introduction to the MC9S12 Hardware Subsystems

Transcription:

Introduction to the 9S12 Microcontroller o Harvard architecture and Princeton architecture o Memory map for a Princeton architecture microprocessor o 68HC12 Address Space o 68HC12 ALU o 68HC12 Programming Model o Some 9S12 Instructions Needed for Lab 1 o A Simple Assembly Language Program o Assembling an Assembly Language Program

MC9S12 Address Space MC9S12 has 16 address lines MC9S12 can address 2 16 distinct locations For MC9S12, each location holds one byte (eight bits) MC9S12 can address 2 16 bytes 2 16 = 65536 2 16 = 2 6 2 10 = 64 1024 = 64 KB (1K = 2 10 = 1024) MC9S12 can address 64 KB Lowest address: 0000000000000000 2 = 0000 16 = 0 10 Highest address: 1111111111111111 2 = FFFF 16 = 65535 10

MEMORY TYPES RAM: Random Access Memory (can read and write) ROM: Read Only Memory (programmed at factory) PROM: Programmable Read Only Memory (Programmed once at site) EPROM: Erasable Programmable Read Only Memory (Program at site, can erase using UV light and reprogram) EEPROM: Electrically Erasable Programmable Read Only Memory (Program and erase using voltage rather than UV light)

MC9S12 has: 12 KB RAM 4 KB EEPROM (Normally can only access 3 KB) 256 KB Flash EEPROM (Can access 16 KB at a time)

MC9S12 ALU Arithmetic Logic Unit (ALU) is where instructions are executed. Examples of instructions are arithmetic (add, subtract), logical (bitwise AND, bitwise OR), and comparison. MC9S12 has two 8-bit registers for executing instructions. These registers are called A and B. For example, the MC9S12 can add the 8-bit number stored in B to the eight-bit number stored in A using the instruction ABA (add B to A): When the control unit sees the sixteen-bit number 0x1806, it tells the ALU to add B to A, and store the result into A.

MC9S12 Programming Model A Programming Model details the registers in the ALU and control unit which a programmer needs to know about to program a microprocessor. Registers A and B are part of the programming model. Some instructions treat A and B as a sixteen-bit register called D for such things as adding two sixteen-bit numbers. Note that D is the same as A and B. The MC9S12 can work with 8-bit numbers (bytes) and 16-bit numbers (words). The size of word the MC9S12 uses depends on the instruction. For example, the instruction LDAA (Load Accumulator A) puts a byte into A, and LDD (Load Double Accumulator) puts a word into D.

MC9S12 Programming Model The MC9S12 has a sixteen-bit register which tells the control unit which instruction to execute. This is called the Program Counter (PC). The number in PC is the address of the next instruction the MC9S12 will execute. The MC9S12 has an eight-bit register which tells the MC9S12 about the state of the ALU. This register is called the Condition Code Register (CCR). For example, one bit (C) tells the MC9S12 whether the last instruction executed generated a carry. Another bit (Z) tells the MC9S12 whether the result of the last instruction was zero. The N bit tells whether the last instruction executed generated a negative result. There are three other 16-bit registers X, Y, SP which we will discuss later.

Some MC9S12 Instructions Needed for Lab 1 LDAA address puts the byte contained in memory at address into A STAA address puts the byte contained in A into memory at address STAB address puts the byte contained in B into memory at address ADDA address adds the byte in memory address to A, and save result in A CLRB clears B (0 B) INCA adds 1 to A ((A) + 1 A) DECB decrements B by 1 ((B) - 1 B) LSRA ASRA SWI shifts A right by one bit (puts 0 into MSB) This divides an unsigned byte by 2 shifts A right by one bit (keep MSB the same) This divides a signed byte by 2 Software Interrupt (Used to end all our MC9S12 programs)

A Simple MC9S12 Program All programs and data must be placed in memory between address 0x1000 and 0x3BFF. For our short programs we will put the first instruction at 0x2000, and the first data byte at 0x1000. Consider the following program: ldaa $1000 ; Put contents of memory at 0x1000 into A inca ; Add one to A staa $1001 ; Store the result into memory at 0x1001 swi ; End program If the first instruction is at address 0x2000, the following bytes in memory will tell the MC9S12 to execute the above program: If the contents of address 0x1000 were 0xA2, the program would put a 0xA3 into address 0x1001.

A Simple Assembly Language Program It is difficult for humans to remember the numbers (op codes) for computer instructions. It is also hard for us to keep track of the addresses of numerous data values. Instead we use words called mnemonics to represent instructions, and labels to represent addresses, and let a computer programmer called an assembler to convert our program to binary numbers (machine code). Here is an assembly language program to implement the previous program: prog: equ $2000 ; Start program at 0x2000 data: equ $1000 ; Data value at 0x1000 org prog ldaa input inca staa result swi org data input: dc.b $A2 result: ds.b 1 ; Start of data

We would put this code into a file and give it a name, such as main.asm (assembly language programs usually have the extension.s or.asm). Note that equ, org, dc.b and ds.b (define constant byte and define storage byte) are not instructions for the MC9S12 but are directives to the assembler which makes it possible for us to write assembly language programs. They are called assembler directives or psuedo-ops. For example the psuedo-op org tells the assembler that the starting address (origin) of our program should be 0x2000.

Assembling an Assembly Language Program A computer program called an assembler can convert an assembly language program into machine code. The assembler we use in class is a commercial compiler from Freescale called CodeWarrior (with Eclipse IDE). How to use CodeWarrior is discussed in Lab 1 and in Huang (Section 3.8). The assembler will produce a file called main.lst, which shows the machine code generated. Freescale HC12-Assembler (c) Copyright Freescale 1987-2009 Abs. Rel. Loc Obj. code Source line ---- ---- ------ --------- ----------- 1 1 2 2 0000 2000 prog equ $2000 ; Start program at 0x2000 3 3 0000 1000 data equ $1000 ; Data value at 0x1000 4 4 5 5 org prog 6 6 7 7 a002000 B610 00 ldaa input 8 8 a002003 42 inca 9 9 a002004 7A10 01 staa result 10 10 a002007 3F swi 11 11 12 12 org data 13 13 a001000 A2 input: dc.b $A2 14 14 a001001 result: ds.b 1

This will produce a file called Project.abs.s19 which we can load into the MC9S12. S06B0000433A5C446F63756D656E747320616E642053657474696E6773 S1051000A20048 S10B2000B61000427A10013F02 S9030000FC The first line of the S19 file starts with a S0: the S0 indicates that it is the first line. - This first line is just for information; it does not contain code which is loaded into the MC9S12 - The S0 line generated by CodeWarrior is so long that it confuses the MC9S12 Dbug-12 monitor. You will need to delete it before loading the S19 file into the MC9S12. The last line of the S19 file starts with a S9: the S9 indicates that it is the last line. The other lines begin with a S1: the S1 indicates these lines are data to be loaded into the MC9S12 memory. Here is the second line (with some spaces added): S1 0B 2000 B6 1000 42 7A 1001 3F 02 On the second line, the S1 if followed by a 0B. This tells the loader that there this line has 11 (0x0B) bytes of data follow. The count 0B is followed by 2000. This tells the loader that the data (program) should be put into memory starting with address 0x2000.

The next 16 hex numbers B61000427A10013F are the 8 bytes to be loaded into memory. You should be able to find these bytes in the main.lst file. The last two hex numbers, 0x02, is a one byte checksum, which the loader can use to make sure the data was loaded correctly.

What will this program do? Freescale HC12-Assembler (c) Copyright Freescale 1987-2009 Abs. Rel. Loc Obj. code Source line ---- ---- ------ --------- ----------- 1 1 2 2 0000 2000 prog equ $2000 ; Start program at 0x2000 3 3 0000 1000 data equ $1000 ; Data value at 0x1000 4 4 5 5 org prog 6 6 7 7 a002000 B610 00 ldaa input 8 8 a002003 42 inca 9 9 a002004 7A10 01 staa result 10 10 a002007 3F swi 11 11 12 12 org data 13 13 a001000 A2 input: dc.b $A2 14 14 a001001 result: ds.b 1 ldaa input : inca: staa result : Load contents of 0x1000 into A (0xA2 into A) Increment A (0xA2 + 1 = 0xA3 A) Store contents of A to address 0x1001 (0xA3 adress 0x1001)