DOC PREVIEW
NMT EE 308 - EE 308 Lecture 2

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 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 18 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 18 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 18 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 18 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 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2012Lecture 2January 20, 2012Introduction to the MC9S12 Microcontroller• Harvard and Princeton architectures• Memory map for a Princeton architecture microcontroller• MC9S12 Address Space• MC9S12 ALU• MC9S12 Programming Model• Some MC9S12 instructions needed for Lab 1• A Simple Assembly Language Program• Assembling an Assembly Language Program using Codewarrior1EE 308 Spring 2012STATUSALU CONTROLMEMORYINSTRUCTIONMEMORYDATADATAINSTRUCTION& ADDRCONTROLHARVARD ARCHITECTUREMICROPROCESSORCLOCKOUTINCONTROL2EE 308 Spring 2012MICROPROCESSORMEMORYPRINCETON (VON NEUMAN) ARCHITECTURESTATUSOUTINCONTROLCLOCKCONTROLALUDATAINSTRUCTION& ADDRCONTROL3EE 308 Spring 2012DATAPROGRAMMEMORY MAP(Princeton Architecture)Function of memorydetermined by programmerMC9S12 Address Space• MC9S12 has 16 address lines• MC9S12 can address 216distinct locations• For MC9S12, each location holds one byte (eight bits)• MC9S12 can address 216bytes• 216= 65536• 216= 26× 210= 64 × 1024 = 64 KB• (1K = 210= 1024)4EE 308 Spring 2012• MC9S12 can address 64 KBAddress and Data BusADDRESS (16)DATA (8)CONTROLCPU(ALUandControlLogic)Simplified MC9S125EE 308 Spring 2012MC9S12 Address Space• Lowest address: 00000000000000002= 000016= 010• Highest address: 11111111111111112= FFFF16= 6553510• Three ways to represent hexadecimal numbers:– FFFF16– 0xFFFF– $FFFF0x00000xFFFF65535 02 − 1166EE 308 Spring 2012MEMORY TYPESRAM: Random Access Memory (can read and write)ROM: Read Only Memory (programmed at factory)PROM: Programmable Read Only Memory(Program 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 RAM4 KB EEPROM (Normally can only access 3 KB)256 KB Flash EEPROM (Can access 16 KB at a time)7EE 308 Spring 2012MC9S12 Address Space of EEPROM)FlashBanked1 K Byte(Covers 1 K ByteEEPROM0x00000x03FFRAMD−Bug 12User RAM1 K Bytes11 K Bytes0x0FFF0x0400EEPROMUser3 K Bytes0x10000x3FFF0x3C000x3BFF0x40000x7FFF0x800016k Bytes16k BytesFlashFixedEEPROM16k BytesFlashEEPROMFixed0xFFFF0xC0000xBFFF(D−Bug 12)Registers(Hardware)8EE 308 Spring 2012MC9S12 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. Theseregisters are called A and B.• For example, the MC9S12 can add the 8-bit number stored in Bto the eight-bit number stored in A using the instruction ABA(add B to A):COMBINATIONALBLOCKA BCLOCK(ADD B TO A)CONTROL(0x1806 = ABA)When the control unit sees the sixteen-bit number 0x1806, it tellsthe ALU to add B to A, and store the result into A.9EE 308 Spring 2012MC9S12 Programming Model• A Programming Model details the registers in the ALU and con-trol unit which a programmer needs to know about to programa microprocessor.• Registers A and B are part of the programming model. Someinstructions treat A and B as a sixteen-bit register called D forsuch things as adding two sixteen-bit numbers. Note that D isthe same as A and B — if you change A, you change the uppereight bits of D.0B0A7 7D015• The MC9S12 can work with 8-bit numbers (bytes) and 16-bitnumbers (words).• The size of word the MC9S12 uses depends on the instruction.For example, the instruction LDAA (Load Accumulator A) putsa byte into A, and LDD (Load Double Accumulator) puts a wordinto D.10EE 308 Spring 2012MC9S12 Programming Model• The MC9S12 has a sixteen-bit register which tells the controlunit which instruction to execute. This is called the ProgramCounter (PC). The number in PC is the address of the nextinstruction the MC9S12 will execute.• The MC9S12 has an eight-bit register which tells the MC9S12about the state of the ALU. This register is called the ConditionCode Register (CCR). For e xample, one bit (C) tells the MC9S12whether the last instruction executed generated a carry. Anotherbit (Z) tells the MC9S12 whether the result of the last instructionwas zero. The N bit tells whether the last instruction executedgenerated a negative res ult.• There are three other 16-bit registers – X, Y, SP – which we willdiscuss later.0150150150150BDXYSPPCCCR0015A7 7NIHXS Z V C11EE 308 Spring 2012Some MC9S12 Instructions Needed for Lab 1LDAA address Load the byte contained in memory at address into ASTAA address Store the byte contained in A into memory at addressSTAB address Store the byte contained in B into memory at addressADDA address Add the byte contained in memory at address to A,save the result in ACLRB Clear B (0 -> B)INCA Increment AAdd 1 to A ((A) + 1 -> A)DECB Decrement BSubtract 1 from B ((B) - 1 -> B)LSRA Shift A right by one bit (put 0 into MSB)This divides an unsigned byte by 2ASRA Shift A right by one bit (keep the MSB the same)This divides a signed byte by 2SWI Software Interrupt (Used to end all our MC9S12 programs)12EE 308 Spring 2012A Simple MC9S12 Program• All programs and data must be placed in memory between ad-dress 0x1000 and 0x3BFF. For our programs we will put the firstinstruction at 0x2000, and the first data byte at 0x1000• Consider the following program:ldaa $1000 ; Put contents of memory at 0x1000 into Ainca ; Add one to Astaa $1001 ; Store the result into memory at 0x1001swi ; End program• If the first instruction is at address 0x2000, the following bytesin memory will te ll the MC9S12 to execute the above program:Address Value Instruction0x2000 B6 ldaa $10000x2001 100x2002 000x2003 42 inca0x2004 7A staa $10010x2005 100x2006 010x2007 3F swi• If the contents of address 0x1000 were 0xA2, the program wouldput an 0xA3 into address 0x1001.13EE 308 Spring 2012A Simple Assembly Language Program.• It is difficult for humans to remember the numbers (op codes) forcomputer instructions. It is also hard for us to keep track of theaddresses of numerous data values. Instead we use words calledmnemonics to represent instructions, and labels to represent ad-dresses, and let a computer programmer called an assembler toconvert our program to binary numbers (machine code).• Here is an assembly language program to implement the pre viousprogram:prog equ $2000 ; Start program at 0x2000data equ $1000 ; Data value at 0x1000org progldaa inputincastaa resultswiorg datainput: dc.b $A2result: ds.b 1• We would put this


View Full Document

NMT EE 308 - EE 308 Lecture 2

Documents in this Course
Load more
Download EE 308 Lecture 2
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 EE 308 Lecture 2 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 EE 308 Lecture 2 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?