12
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics Instructor: Professor Charles Ume Lecture #8

George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

Embed Size (px)

Citation preview

Page 1: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

ME 4447/6405

Microprocessor Control of Manufacturing Systemsand

Introduction to Mechatronics

Instructor: Professor Charles Ume

Lecture #8

Page 2: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

Page 3: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

Covered in Lecture 5:• Quick Introduction to

Microcontroller Subsystems

• Microcontroller Registers

• Microcontroller Modes (Single chip, Extended, etc..)

• EVBU Memory Maps

Covered in this section:HCS12 CPU(Note: the Central Processing Unit (CPU) is the “core” of the microcontroller where instructions are executed)

MC9S12C Microcontroller

Page 4: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

(Note: HCS12 CPU registers are an integral part of the CPU and are not addressed as if they were memory locations)

The HCS12 CPU contains:•Circuits to process instructions•CPU Registers

Page 5: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

Accumulators A, B, and D•A & B are:

– 8-bit registers– Can be used for 8-bit math operations ( Note: This is why A & B are

called “Accumulators”)– Can also be used for 8-bit binary logic, comparisons, memory

transfers, etc…– Can be used for accumulator offsets in indexed addressing

•D is:– 16-bit register– Cannot be used when A or B is in use– Can be used for 16-bit math in conjunction with Index X & Y– Can be used for 16-bit memory transfers, comparisons, etc..– Can be used for accumulator offsets in indexed addressing

Index Registers X & Y•Can be used for 16-bit math with Accumulator D•Mainly used for addressing memory in Indexed mode (Note: Indexed addressing mode will be covered in a later section)

Program Counter (PC)•Contains the address of the next instruction to be executed•Can be used as index register in indexed addressing

Stack Pointer (SP)•Contains the address of the last stack location used (1 greater than the currently available location)•Can be used as index register in indexed addressing

Page 6: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

The Stack is a region of RAM which may be used for temporary data storage. Upon reset, the stack pointer must be initialized. MON12 loads the stack pointer with $0E5F and has reserved memory locations $0E5E-$0E00 for the stack, creating 95 bytes of storage.

When MON12 is not in use, the user must load the stack pointer with the appropriate address using the LDS instruction:

LDS $0E5F

Note: The user must determine stack location and ensure that it does not conflict with other resources.

HCS12 CPU STACK AND STACK POINTER

Page 7: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

An interrupt can be recognized at any time after it is enabled by its local mask, if any, and by the global mask bit in the CCR. Once an interrupt source is recognized, the CPU responds at the completion of the instruction being executed.

Interrupt latency varies according to the number of cycles required to complete the current instruction. When the CPU begins to service an interrupt, the contents of the CPU registers are pushed onto the stack in the order shown above (see also p. 2 of the CPU12 reference guide). After the CCR value is stacked, the I bit and the X bit, if XIRQ is pending, are set to inhibit further interrupts. The interrupt vector for the highest priority pending source is fetched and execution continues at the address specified by the vector. At the end of the interrupt service routine, the return-from-interrupt instruction is executed and the saved registers are pulled from the stack in reverse order so that normal program execution can resume.

HCS12 CPU STACK POINTER

Page 8: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

LEGEND:

RTN = ADDRESS OF NEXT INSTRUCTION IN MAIN ROGRAM TO BE EXECUTED UPON RETURN FROM SUBROUTINE

RTNHI = MOST SIGNIFICANT BYTE OF RETURN ADDRESS

RTNLO = LEAST SIGNIFICANT BYTE OF RETURN ADDRESS

X,YHI = MOST SIGNIFICANT BYTE OF X OR Y INDEX REGISTER

X,YLO = LEAST SIGNIFICANT BYTE OF X OR Y INDEX REGISTER

RTI:

At the end of an interrupt service routine, the user writes a Return from Interrupt (RTI) instruction. This causes the CPU registers and the return address to be pulled from the stack, permitting main program execution to continue where it left off with the same values in the CPU registers as before the interrupt occured.

Page 9: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

LEGEND:

RTN = ADDRESS OF NEXT INSTRUCTION IN MAIN ROGRAM TO BE EXECUTED UPON RETURN FROM SUBROUTINE

RTNHI = MOST SIGNIFICANT BYTE OF RETURN ADDRESS

RTNLO = LEAST SIGNIFICANT BYTE OF RETURN ADDRESS

RTS:

JSR or BSR:

Execution of Jump To Subroutine (JSR) and Branch To Subroutine (BSR) instructions causes the contents of the program counter to be pushed onto the stack. At the end of the subroutine, the user writes a Return from Subroutine (RTS) instruction. This causes the return address to be pulled from the stack, permitting execution to continue after the JSR or BSR instruction

Page 10: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405 MC9S12C CONDITION CODE REGISTER

MASKING BITSS – Disables STOP instruction when set.

X – Masks XIRQ Request when set. set by hardware reset, cleared by softwareset by unmasked XIRQ

See page 116 of Technical Data

I – Masks interrupt request from all IRQ level sources (both external and internal) when set.

set by unmasked I level request or unmasked XIRQ

See page 116 of Technical Data

ARITHMETIC BITSReflect results of instruction execution

C – Carry/Borrow from MSB unsigned arithmetic

V – 2’s complement overflow indication signed arithmetic

Z – Zero result

N – Negative (follows MSB of result)

H – Half Carry from bit 3 to bit 4 ADD operations only 7 0

01001111+00001000 01010111H will be set to 1

S X H I N Z V C

Page 11: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405Example 3 from Lecture 4:

- 8510 - 9010=-17510

8510 = 5516 = 0101 01012

1010 1010 = 1’s comp. of 5516

1010 1011 = 2’s comp. of 5516

9010 = 5A16 = 0101 10102

1010 0101 = 1’s comp. of 5A16

1010 0110 = 2’s comp. of 5A16

1010 1011 = (2’s comp. of 5516)

1010 0110 = (2’s comp. of 5A16)

-------------1 0101 0001 = +5116 = +8110

V bit will be set.C bit will be set.

Page 12: George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction

George W. Woodruff School of Mechanical Engineering, Georgia TechGeorge W. Woodruff School of Mechanical Engineering, Georgia Tech

ME4447/6405ME4447/6405

QUESTIONS???