DOC PREVIEW
NMT EE 308 - Introduction to the 9S12 Microcontroller

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2011 • 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 ProgramEE 308 Spring 2011EE 308 Spring 2011 MC9S12 Address Space • MC9S12 has 16 address lines • MC9S12 can address 216 distinct locations • For MC9S12, each location holds one byte (eight bits) • MC9S12 can address 216 bytes • 216 = 65536 • 216 = 26 × 210 = 64 × 1024 = 64 KB • (1K = 210 = 1024) • MC9S12 can address 64 KB • Lowest address: 00000000000000002 = 000016 = 010 • Highest address: 11111111111111112 = FFFF16 = 6553510EE 308 Spring 2011 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)EE 308 Spring 2011EE 308 Spring 2011 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.EE 308 Spring 2011 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. • 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.EE 308 Spring 2011 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 shifts A right by one bit (puts 0 into MSB) This divides an unsigned byte by 2 ASRA shifts A right by one bit (keep MSB the same) This divides a signed byte by 2 SWI 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 programEE 308 Spring 2011 • 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 ; Start of data input: dc.b $A2 result: ds.b 1EE 308 Spring 2011 • 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. •How to use CodeWarrior is discussed in Lab 1 and in Huang (3.8 Using CodeWarrior). • The assembler will produce a file called main.lst, which shows the machine code generated. Freescale HC12-Assembler (c) Copyright Freescale 1987-2009


View Full Document

NMT EE 308 - Introduction to the 9S12 Microcontroller

Documents in this Course
Load more
Download Introduction to the 9S12 Microcontroller
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to the 9S12 Microcontroller and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to the 9S12 Microcontroller 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?