CS/ECE 5780/6780: Embedded System Design

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

Mark II Aiken Relay Calculator

Microcontrollers. Microcontroller

Page 1. Logistics. Introduction to Embedded Systems. My Records Indicate. Intel 4004 first single chip computer? Acronyms CS/ECE 6780/5780.

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

Exam I Review February 2017

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

68HC12 Training Lab Student Exercise Book

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

ECE372 CodeWarrior Simulator Andreou/Michaelides

CEG 411/611 Laboratory 1. Laboratory Familiarization

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Chapter 7 Central Processor Unit (S08CPUV2)

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

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

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)

17. Instruction Sets: Characteristics and Functions

A Simple MC9S12 Program

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

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

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Wed. Aug 23 Announcements

Lecture #3 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Wednesday, 20-Jan-2015

538 Lecture Notes Week 5

Introduction to Microcontroller. Systems. Embedded system. Assembler or C? Datatypes 2. Datatypes 1

538 Lecture Notes Week 5

HC11 Instruction Set Architecture

What is an Addressing Mode?

HC11 Instruction Set Architecture

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.

538 Lecture Notes Week 1

Embedded programming, AVR intro

Introduction to Programming

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

Exam 1 Feb. 23, 25, 27?

Introduction to Microcontrollers

S12CPUV2. Reference Manual HCS12. Microcontrollers. S12CPUV2/D Rev. 0 7/2003 MOTOROLA.COM/SEMICONDUCTORS

Instruction Sets: Characteristics and Functions

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

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

Chapter 1. Solutions Solution 1.1. Most RAMs are volatile, meaning the information is lost if power is removed then restored.

EE319K Final Fall 2005 Solution C. (3) Question 1. (3) Question 2. short function(const short in){ return in+5; } const

HC11 Instruction Set

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Computer Organization I. Lecture 28: Architecture of M68HC11

When an instruction is initially read from memory it goes to the Instruction register.

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

EE 3170 Microcontroller Applications

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

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

C programming for embedded microcontroller systems.

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

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

CPE300: Digital System Architecture and Design

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Introduction to Computers - Chapter 4

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

Introduction to Embedded Systems. Some Nagging

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

Instruction Set Architecture

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

MC9S12 Address Space

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

ECE2049-E17 Lecture 6 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

ECE251: Tuesday Aug. 29

HC 11 Instructions! From Alex Hollowayʼs notes with! many thanks!

Introduction to 6811 Programming

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

EE 308 Spring A software delay

Representation of Information

Bits, Bytes, and Integers Part 2

MC68HC12 Parallel I/O

EECE416 :Microcomputer Fundamentals and Design. X86 Assembly Programming Part 1. Dr. Charles Kim

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set?

CC411: Introduction To Microprocessors

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

CMPEN 472 Sample EXAM II

Using the stack and the stack pointer

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

CS 261 Fall Binary Information (convert to hex) Mike Lam, Professor

ECE 367 -Experiment #1 Fall 2012

Go Gators! Relax! May the Schwartz be with you!

MOS 6502 Architecture

COMPUTER ORGANIZATION & ARCHITECTURE

ECE331: Hardware Organization and Design

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #9: Exam Review w/ Solutions

1. Introduction to Assembly Language

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

COMP3221: Microprocessors and. and Embedded Systems. Instruction Set Architecture (ISA) What makes an ISA? #1: Memory Models. What makes an ISA?

Introduction to the MC9S12 Hardware Subsystems

Introduction to Microcontrollers II

UNIVERSITY OF MANITOBA DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING. Term Test #2 Solution ECE 3610 MICROPROCESSING SYSTEMS

Computer Organization MIPS ISA

Introduction to the 9S12 Microcontroller

Programming the Motorola MC68HC11 Microcontroller

INSTITUTE OF ENGINEERING AND MANAGEMENT, KOLKATA Microprocessor

CPU12 REFERENCE MANUAL

MOXSYN. General Description. Features. Symbol

Transcription:

CS/ECE 5780/6780: Embedded System Design John Regehr Lecture 2: 68HC12 Architecture & Lab 1 Introduction

Duff s Device void foo (int x, int *y, int *z) { switch (x % 8) { case 0: do { *y++ = *z++; case 7: *y++ = *z++;... case 1: *y++ = *z++; } while ((x -= 8) > 0); } }

Puzzle Winners Daniel Stewart Parker Alex Freshman Brian faires

Lab Times Lab times Tuesday 2:00 5:00 Friday 2:00 5:00 Monday 2:00 5:00 We ll start labs the week after next Please send a prioritized list to teach-cs5780 by Friday night

Intel 4004 4-bit BCD 92 khz

Intel 8008 (1972) 8-bit 500 khz

Intel 8080 (1974) 2 MHz Considered to be the first truly usable microprocessor

Intel 8086-8088 (1978)

Intel 286 (1982)

Intel386 TM (1985)

Intel486 TM DX CPU (1989)

Intel R Pentium R (1993)

Intel R Pentium R Pro (1995)

Intel R Pentium R II (1997)

Intel R Pentium R III (1999)

Intel R Pentium R 4 (2000)

Microcontrollers During early 1980s, microcontrollers began to be designed. While microprocessors were optimized for speed and memory size, microcontrollers were optimized for power and physical size. Intel produced the 8051 microcontroller. Motorola produced the 6805, 6808, 6811, and 6812. In 1999, Motorola shipped its 2 billionth MC68HC05 microcontroller. In 2004, Motorola spun off its microcontroller division as Freescale Semiconductor.

6812 Architecture Two separate 8-bit accumulators (A,B) or one combined 16-bit accumulator (D). Two 16-bit index registers (X,Y). 8-bit condition code register. Powerful bit-manipulation instructions. Supports 16-bit add/subtract, 32 16 unsigned/signed divide, 16 16 fractional divide, 16 16 unsigned/signed multiply, and 32 + (16 16) multiply and accumulate. Stack pointer points to the top element and grows downward.

Registers

Condition Code Register

Address Map for MC9S12C32 Address (hex) Size Device Contents $0000 to $03FF 1K I/O $3800 to $3FFF 2K RAM Variables and stack $4000 to $7FFF 16K EEPROM Program and constants $C000 to $FFFF 16K EEPROM Program and constants

External I/O Ports Port 48-pin Shared Functions Port A PA0 Address/Data Bus Port B PB4 Address/Data Bus Port E PE7, PE4, PE1, PE0 System Integration Module Port J Key wakeup Port M PM5-PM0 SPI, CAN Port P PP5 Key wakeup, PWM Port S PS1-PS0 SCI Port T PT7-PT0 Timer, PWM Port AD PAD7-PAD0 Analog-to-Digital Converter

MC9S12C32 Block Diagram

Digital Representations of Numbers Numbers are represented as a binary sequence of 0 s and 1 s. Each 8-bit byte is stored at a different address. A byte can be represented using two hexadecimal digits. %10110101 = $B5 (0xB5 in C) N = 128 b 7 + 64 b 6 + 32 b 5 + 16 b 4 + 8 b 3 + 4 b 2 + 2 b 1 + b 0 (unsigned) N = 128 b 7 + 64 b 6 + 32 b 5 + 16 b 4 + 8 b 3 + 4 b 2 + 2 b 1 + b 0 (signed) Programmer must track if a number is signed or unsigned. While addition and subtraction use same hardware, separate hardware is required for multiply, divide, and shift right. A byte can also represent a character using the 7-bit ASCII code.

16-Bit Words (Double Bytes) Endian comparison for the 16-bit number $03E8: Freescale microcontrollers use the big endian approach.

Fixed-Point Numbers In embedded systems, fixed-point is often preferred over floating point since it is simpler, more memory efficient, and often all that is required. fixed-point number I where I is a variable integer and is a fixed constant. If = 10 n, then called decimal fixed-point. If = 2 n, then called binary fixed-point. The value of cannot be changed during program execution, and it likely only appears as a comment in the code.

Precision, Resolution, and Range Precision is the total number of distinguishable values. Resolution is the smallest difference that can be represented. Range is the minimum and maximum values. Example: A 10-bit ADC with a range of 0 to +5V, has a precision of 2 10 = 1024 values, and a resolution of 5V/1024 or about 5mV. This could be accurately stored in a 16-bit fixed-point number with = 0.001V.

Overflow and Drop-Out Overflow is when the result of calculation is outside the range. Drop-out is when an intermediate result cannot be represented. Example: M = (53 N)/100 versus M = 53 (N/100) Promotion to higher precision avoids overflow. Dividing last avoids drop-out.

Fixed-Point Arithmetic Let x = I, y = J, z = K. z = x + y K = I + J (addition) z = x y K = I J (subtraction) z = x y K = (I J)/ (multiplication) z = x/y K = (I )/J (division) If is different, then must first convert one of the two numbers to use the of the other. If is different, binary fixed-point is more convenient as conversion can be done with shifting rather than multiplication/division.

Notation w is 8-bit signed (-128 to +127) or unsigned (0 to 255) n is 8-bit signed (-128 to +127) u is 8-bit unsigned (0 to 255) W is 16-bit signed (-32787 to +32767) or unsigned (0 to 65535) N is 16-bit signed (-32787 to +32767) U is 16-bit unsigned (0 to 65535) = [addr] specifies an 8-bit read from address = {addr} specifies a 16-bit read from address (big endian) =< addr > specifies a 32-bit read from address (big endian) [addr] = specifies an 8-bit write to address {addr} = specifies a 16-bit write to address (big endian) < addr >= specifies a 32-bit write to address (big endian)

Assembly Language Assembly language instructions have four fields: Label Opcode Operand(s) Comment here ldaa $0000 RegA = [$0000] staa $3800 [$3800] = RegA ldx $3802 RegX = {$3802} stx $3804 {$3804} = RegX Assembly instructions are translated into machine code: Object code Instruction Comment $96 $00 ldaa $0000 RegA = [$0000]

Addressing Modes An addressing mode is a way for an instruction to locate its operand(s) About 80% of understanding assembly language is understanding the addressing modes Some simple addressing modes: Inherent addressing mode (INH) Immediate addressing mode (IMM) Direct page addressing mode (DIR) Extended addressing mode (EXT) PC relative addressing mode (REL)

Inherent Addressing Mode Uses no operand field. Obj code Op Comment $3F swi Software interrupt $87 clra RegA = 0 $32 pula RegA = [RegSP]; RegSP=RegSP+1

Immediate Addressing Mode Uses a fixed constant. Data is included in the machine code. Obj code Op Operand Comment $8624 ldaa #36 RegA = 36 What is the difference between ldaa #36 and ldaa #$24?

Direct Page Addressing Mode Uses an 8-bit address to access from addresses $0000 to $00FF. Obj code Op Operand Comment $9624 ldaa 36 RegA = [$0024] What is the difference between ldaa #36 and ldaa 36?

Extended Addressing Mode Uses a 16-bit address to access all memory and I/O devices. Obj code Op Operand Comment $B60801 ldaa $0801 RegA = [$0801]

PC Relative Addressing Mode Used for branch and branch-to-subroutine instructions. Stores 8-bit signed relative offset from current PC rather than absolute address to branch to. rr = (destination address) (location of branch) (size of the branch) Assume branch located at $F880. Obj code Op Operand Comment $20BE bra $F840 $F840 $F880 2 = $42 = $BE $2046 bra $F8C8 $F8C8 $F880 2 = $46

Lab1Example.c requirements SW1 and PB2 light up LED1 (MCU board) and LED1 and LED2 (project board) when pressed. SW2 and PB1 light up LED2 (MCU board) and LED3 and LED4 (project board) when pressed.

MCU board switches and LEDs Application Module Student Learning Kit Users Guide (APS12C32SLKUG.pdf) contains the necessary information. User jumpers table states that jumpers User1-4 must be on to enable the switches and LEDs (pg. 11). Switches are active low (pg. 11). SW1 and SW2 provide input on PORTE0 (PE0) and PORTP5 (PP5) respectively (pg. 11). LEDs are active low (pg. 12). LED1 and LED2 are driven by PORTA0 (PA0) and PORTB4 (PB4) respectively (pg. 12).

Project board switches and LEDs MCU Project Board Student Learning Kit User Guide (PBMCUSLKUG.pdf) contains the necessary information. Push button switches are active low (pg. 17). PB1 and PB2 are connected to the MCU via ports 9 and 11 respectively (pg. 20). Push buttons are enabled by a 0 on port 36 (pg. 21). LEDs are active high (pg. 18). LED1-LED4 are connected to the MCU via ports 33, 35, 37, and 39 respectively (pg. 20). LEDs are enabled by a 0 on port 34 (pg. 21).

MCU port mappings Board port MCU Port Function 9 PP5 PB1 11 PE0 PB2 33 PAD4 LED1 35 PAD5 LED2 37 PAD6 LED3 39 PAD7 LED4 34 PT4 LED EN 36 PT5 PB EN Mapping found in Application Module Student Learning Kit Users Guide (APS12C32SLKUG.pdf) (pg. 11).

MCU Port configurations MCU Port Direction Config Register Value Function PORTE0 Input DDRE0 (pg. 140) 0 SW1 PORTP5 Input DDRP5 (pg. 94) 0 SW2 PORTA0 Output DDRA0 (pg. 136) 1 LED1 PORTB4 Output DDRB0 (pg. 137) 1 LED2 PORTP5 Input DDRP5 (pg. 94) 0 PB1 PORTE0 Input DDRE0 (pg. 140) 0 PB2 PORTAD4 Output DDRAD4 (pg. 102) 1 LED1 PORTAD5 Output DDRAD5 (pg. 102) 1 LED2 PORTAD6 Output DDRAD6 (pg. 102) 1 LED3 PORTAD7 Output DDRAD7 (pg. 102) 1 LED4 PORTT4 Output DDRT4 (pg. 82) 1 LED EN PORTT5 Output DDRT5 (pg. 82) 1 PB EN Reference: MC9S12C Family Reference Manual (MC9S12C128V1.pdf).

Lab1Example.c code void main(void) { //Set the direction of ports A,B,E, and P. DDRA = 0xFF; DDRB = 0xFF; DDRE = 0x00; DDRP = 0x00; //Set the direction of ports T and AD DDRT = PTT_PTT4_MASK PTT_PTT5_MASK; DDRAD = PTAD_PTAD7_MASK PTAD_PTAD6_MASK PTAD_PTAD5_MASK PTAD_PTAD4_MASK; //Enable project board push buttons and LEDs PTT = ~(PTT_PTT4_MASK PTT_PTT5_MASK); } Macro definitions are found in mc9s12c32.h.

Lab1Example.c code Alternatively... void main(void) { //Set the direction of ports A,B,T,AD,E, and P. DDRA = 0xFF; DDRB = 0xFF; DDRE = 0x00; DDRP = 0x00; DDRT = 0xFF; DDRAD = 0xFF; //Enable project board push buttons and LEDs PTT = 0x00; }

Lab1Example.c code Or maybe... void main(void) { //Set the direction of ports A,B,T,AD,E, and P. DDRA = 0xFF; DDRB = 0xFF; DDRE = 0x00; DDRP = 0x00; DDRT = 0x30; DDRAD = 0xF0; //Enable project board push buttons and LEDs PTT = 0xCF; }

Lab1Example.c code void main(void) {... for(;;) { //Checks the current status of SW1. if((porte & PORTE_BIT0_MASK) == 0) { //Turns on the LEDs PORTA = ~PORTA_BIT0_MASK; \\MCU PTAD = PTAD (PTAD_PTAD5_MASK PTAD_PTAD4_MASK); \\PB } else { //Turn off the LEDs. PORTA = PORTA_BIT0_MASK; \\MCU PTAD = PTAD&~(PTAD_PTAD5_MASK PTAD_PTAD4_MASK); \\PB } }

MCU Programming Summary Basic MCU programming: Extremely simple (or no) data structures Simple control structures Lots of bit-twiddling These basics are almost exactly the same in C or assembly Key skills: Debugging with very little feedback Getting the details right Putting together pieces of information that are scattered across hundreds or thousands of pages of documentation

MC9S12C32 Block Diagram