ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

68
ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

Transcript of ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

Page 1: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Microcomputer Interfacing

Week #1

Introduction to Interfacing and Microcontrollers (M68HC12)

Page 2: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 2

Resources

Huang, Chapter 1 Sections 1.2 Number System Issue 1.3 Computer Hardware Organization 1.4 Memory 1.6 Program Execution 1.7 Overview of the HCS12 Microcontroller 1.8 The HCS12 CPU Registers 1.9 HCS12 Address Modes 1.11 A Sample of HCS12 Instructions

Page 3: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 3

Topics

Interfacing: Definition Microcontrollers M68HC12 Architecture

Page 4: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 4

Interfaces and Interfacing

e.g. (1) human - machine interface

(2) Digital - analogue interface

(3) Digital - digital interface

TTL - CMOS interface

Parallel - Serial interface

Definitions of “interface” from Webster’s Dictionary:

noun: the place at which independent systems meetand act or communicate with each other.

Page 5: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

5

Human-MachineInterface

Digital-Digital Interface

Digital-

InterfaceAnalogue

HumanUsers

AnalogueEnvironment

Other Digital Systems

Human-machine interface:Input devices: keyboard, mouse, microphone, cameraOutput devices: CRT, printer, light panel, audio amp.

Digital - Analogue Interface:Input devices: A/D converters, modems, sensorsOutput devices: D/A converters, modems, transducers,

Control devices: switches, multiplexers, amplifiers,

Digital - Digital Interface:Connectors: wires, ribbon cable, coax, twisted pair, PCB

I/O devices: buffers, level-shifters, synchronizers

System-Level Interfaces

attenuators

actuators, stepper motors

ENG3640 Fall 2012

Page 6: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 6

Interfaces and Interfacing

Informal DefinitionThe physical, electrical and logical means of exchanging

Information with a functional module.

The process of enabling a computer to communicatewith the external world through Software, Hardware

and Protocols.

Page 7: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 7

Why is computer interfacing important ?

1. The human-machine interface determines the ultimate success or failure of many computer based systems (Apple iPhone)

2. Digital systems exist within and must successfully interact with an analogue natural environment.

Digital-Analogue interfaces are unavoidable

3. Rather than designing digital systems from elementary components, computer engineers more typically assemble new systems from existing sub-systems.

Page 8: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 8

Typical Interfacing Activities

1. Selecting software/hardware subsystems that can (at least potentially) interact well with each other.

Appropriate D/A and A/D converters (speed, accuracy, …) Serial vs. parallel communication.

2. Determining appropriate hardware connections: Cabling, connectors, drivers, receivers, correct termination, etc.

3. Resolving any hardware incompatibilities. CMOS with TTL

4. Configuring hardware interfaces correctly using low-level software drivers.

LCD, Keypads in embedded systems.5. Interfacing software components correctly;

Selecting compatible software versions; Calling the correct procedures in the correct sequence with the correct

parameters.

Page 9: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

9

Hardware Interfaces within aPersonal Computer (PC)

CPU

DisketteController

MemoryController

DisketteDrive

HardDrive

DiscController

MainMemory

Cache

SerialPort

ControllerKeyboard

Mouse

ParallelPort

ControllerPrinter

VideoController CRT

System Bus

(greatly simplified)

Lab Board

ENG3640 Fall 2012

Page 10: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 10

What is a Microcontroller?

The Central Processing Unit (CPU)? The Microprocessor Unit? The Microcomputer System? The Microcontroller Unit (MCU)?

Page 11: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 11

Micro Computer System: 5 Basic Units The Arithmetic Logic Unit (ALU) Control Unit: directs the operation of all other parts. Memory: Store program & data Input: Allows data & info to be entered into memory Output: Transfers data from memory to outside world

Control Unit

Datapath

ArithmeticLogic Unit

Registers

Processor

Common Bus (address, data, & control)

Memory

ProgramStorage

DataStorage

OutputUnits

InputUnits

Figure 1.1 Computer Organization

Page 12: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 12

The Central Processing Unit (CPU)

CPU executes program instructions

Program counter (PC) is a special register that points to the instructions

Instruction decoder tells the ALU what to do with the data

Control sequencer manages the transfer of instruction and data bytes along the internal data bus

Page 13: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 13

CPU vs. Microprocessor?

A Central Processing Unit (CPU) refers to the integration of an ALU and Control.

A Microprocessor refers to the implementation of the CPU functions in a single large scale integrated circuit (IC).

Page 14: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 14

The MicroComputer System

MicroComputer has 3 basic parts connected by an internal bus CPU Memory Registers

I/O registers data, control, status

I/O port is a collection of I/O pins on the chip that represents a unit of data Block diagram of a typical

microcontroller shown insingle-chip mode

Page 15: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 15

Micro Computer vs. Micro Controller?

A Micro Controller is a Micro Computer with its memory and I/O integrated into a single chip!

Page 16: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 16

The Microcontroller Unit (MCU)Example of an Input Operation

CPU

MEMORY

OR

Sensor

Input Port

Port’s Register

Data Transfer

Page 17: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 17

The Microcontroller Unit (MCU)Example of an Output Operation

CPU

InstrumentPanel

Output Port

Port’s Register

Data Transfer

Page 18: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 18

The MCU: Applications

Counter

Timer

CPUSpeed Sensor

Speed Signal Set Counter to counton ↑ edges

Program timer’sinterrupt interval

CPU readscounterat everytimeinterval

Page 19: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

19

Principle

In 1945, the mathematician Von Neumann (VN)

demonstrated in study of computation that a

computer could have a simple structure,

capable of executing any kind of program,

given a properly programmed control unit,

without the need of hardware modification

The Von Neumann Computer

ENIAC - The first electronic computer (1946)

ENG3640 Fall 2012

Page 20: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

20

Structure A memory for storing program and data.

The memory consists of the word with the same length A control unit (control path) featuring a program counter for controlling

program execution An arithmetic and logic unit (ALU) also called data path for program

execution

Datapath

Controllpath

Processor orCentral processing unit

Dataand

Instructions

Addressregister

Memory

Instructionregister PC

Data

Address

Registers

The Von Neumann Computer

ENG3640 Fall 2012

Page 21: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

21

The Von Neumann Computer

CodingA program is coded as a set of instructions to besequentially executed

Program execution Instruction Fetch (IF): The next instruction to be executed is

fetched from the memory Decode (D): Instruction is decoded (operation?) Read operand (R): Operands read from the memory Execute (EX): Operation is executed on the ALU Write result (W): Results written back to the memory Instruction execution in Cycle (IF, D, R, EX, W)

ENG3640 Fall 2012

Page 22: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 22

Embedded Systems

Any device or collection of devices that contain one of more dedicated computers, microprocessors, or micro-controllers

Combination of computer hardware and software designed to perform a specific function

Broad definition: Any computing system that is not a desktop

computer

Page 23: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 23

Embedded Systems: Examples

Page 24: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 24

Typical Microcontroller Embedded Application

The amount of air and fuel and timing of the ignition system determine the fuel efficiency and amount of exhaust emission.

Input sensors are used as feedback to correct any error.

Microcontroller uses the sensor inputs to control the ignition system to MAX fuel efficiency and MIN exhaust emissions.

Microcontroller used to control air/fuelmixture in an automotive engine

Page 25: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 25

1974 Intel produced first microprocessor 4004 1977 Intel introduced several microcontrollers 8051, 8032

1978 Motorola introduced 6801, RAM , ROM, EPROM 6805

1985 Motorola introduced the 6811 micro controller (8-bit CPU, 8K ROM, 256Byte RAM, 512Byte EEPROM)

1997 Motorola introduced the 68HC12 which is upward compatible with the 6811

History of Micro Controllers

Page 26: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

26

68HC812A4 Block

Diagram

CPU12

1-KB SRAM

4-KB EEPROM

ENG3640 Fall 2012

Page 27: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 27

Features of the 68HC12 Microcontroller

16-bit CPU

64 kB memory space

768 bytes to 4 kB of EEPROM

1 kB to 12 kB of on-chip SRAM

32 kB to 128 kB flash memory

Sophisticated timer functions that include:

input capture, output compare,

pulse accumulators, real-time interrupt, and COP timer

Serial communication interfaces: SCI, SPI, CAN, BDLC

Background debug mode (BDM)

8-bit or 10-bit A/D converter

Instructions for supporting fuzzy logic function

Page 28: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 28

On-Chip Memory

1Kbyte of static RAM Re-mappable and removable

4 Kbytes of EEPROM individually byte writable (~10ms) bulk erase possible

Page 29: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 29

Registers in the CPU Model

Page 30: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 30

Accumulators

Accumulators A and B are general-purpose 8-bit accumulators that contain operands and results of arithmetic calculations or data manipulations.

Accumulator D is the concatenation of accumulators A and B. Some instructions treat the combination of these

two 8-bit accumulators as a 16-bit double accumulator.

Page 31: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 31

Index Registers Index registers X and Y are used for indexed

addressing. Indexed addressing adds the value in an index

register to a constant or to the value in an accumulator to form the effective address of the operand.

Index registers X and Y can also serve as temporary data storage locations with some combinational capability.

Page 32: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 32

Program Counter

The program counter (PC) contains the address of the next instruction to be executed.

The program counter can also serve as an index register in all indexed addressing modes except auto increment and auto decrement.

Page 33: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 33

Stack Pointer

The stack pointer (SP) contains the last stack address used.

The CPU12 supports an automatic program stack that is used to save system context during subroutine calls and interrupts.

The stack pointer can also serve as a temporary data storage location or as an index register for indexed addressing.

Page 34: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 34

Z — Zero Flag The Z flag is set when the result of an operation is

all 0s. V — Two’s Complement Overflow Flag

The V flag is set when a two’s complement overflow occurs.

C — Carry/Borrow Flag The C flag is set when an addition or subtraction

operation produces a carry or borrow.

Condition Code Register

Page 35: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 35

H — Half-Carry Flag The H flag is used only for BCD arithmetic

operations. It is set when an ABA, ADD, or ADC instruction produces a carry from bit 3 of accumulator A. The DAA instruction uses the H flag and the C flag to adjust the result to correct BCD format.

I — Interrupt Mask Bit Setting the I bit disables maskable interrupt

sources. N — Negative Flag

The N flag is set when the result of an operation is less than 0.

Page 36: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 36

S — Stop Disable Bit Setting the S bit disables the STOP instruction.

X — XIRQ Interrupt Mask Bit Setting the X bit masks interrupt requests from

the XIRQ pin.

Page 37: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 37

Memory Map

Page 38: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 38

Register Block

memory block reserved for internal registers from $00 to $F4 used; $F5 reserved up to $1FF

(512 memory locations) can be moved to any 2K boundary from initial

location of $0000 using INITRG ($11) used for controlling all CPU and

peripheral functions including status, input and output

Page 39: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 39

Memory Map on EVB

Address Range Description Location

$0000 - $01FF CPU Registers On-chip (MCU)

$0800 - $09FF User Code/Data 1K on-chip RAM (MCU)

$1000 - $1FFF User Code/Data 4K on-chip EEPROM (MCU)

$4000 - $7FFF User Code/Data 16K external RAM

$8000 - $FFFF Utilities 32K external EPROM

Page 40: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 40

1) Fetch op-code (instruction)2) Decode op-code3) Fetch operand address4) Execute instruction

Steps to Execute a Program

Examples

LDDA #$10STAA $4000

LDAB $10STAA $4000

Page 41: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 41

Base Prefix Example

binary % %10001010

octal @ @1234567

decimal 12345678

hexadecimal $ $5678

Prefixes for Number Bases A number (operand) can be represented in binary,

octal, decimal, or hexadecimal format. An appropriate prefix is added in front of the number

to indicate its base.

Page 42: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 42

Addressing Modes A 68HC12 instruction consists of one or two bytes of

opcode and zero to five bytes of operand addressing information.

Addressing Modes: determines HOW the CPU access memory locations to be acted upon.

Examples: Inherent Mode Immediate Mode Direct Mode Extended Mode Relative Mode Indexed Mode

Page 43: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 43

Inherent Mode

Instructions that use this addressing mode either have no operands or all operands are in internal CPU registers

In either case the CPU does not need to access any memory location to complete the instruction.

Examples: NOP No Operation DECA Decrement Accumulator A ( A = A – 1) INX Increment Index Register ( X = X + 1)

Page 44: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 44

Immediate Mode

Operands for immediate mode instructions are included in the instruction stream.

The CPU does not access memory when this type of instruction is executed.

An immediate value is preceded by a # character in the assembly instruction.

Examples: LDAA #$55 ; A $55 ; place the value $55 in ACC A LDX #$2000 ; X $2000 ; place the value $2000 in Index Reg X

Page 45: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 45

Direct Mode

This addressing mode is used to access operands in the address space range of $0000 - $00FF.

Since these addresses begin with $00, only the eight low-order bits of the address need to be included in the instruction which saves program space and execution time.

Examples: LDAA $55 ; A m[$55] ; fetches the contents of the memory location ; at $0055 and puts it in ACC A

Page 46: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 46

Instruction Set

The instruction set of the 68HC12 contains different types of instructions: Load & Store Instructions Transfer & Exchange Instructions Move Instructions Add & Subtract Instructions Multiply & Divide Instructions

Page 47: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 47

Table 1.4 Load and store instructions

Mnemonic

LDAALDABLDDLDSLDXLDYLEASLEAXLEAY

STAASTABSTDSTSSTXSTY

Store Instructions

Mnemonic

Function

Load ALoad BLoad DLoad SPLoad index register XLoad index register YLoad effective address into SPLoad effective address into XLoad efective address into Y

Operation

(M) A(M) B(M:M+1) (A:B)(M:M+1) SP(M:M+1) X(M:M+1) XEffective address SPEffective address XEffective address Y

Function Operation

Store AStore BStore DStore SPStore XStore Y

(A) M(B) M(A) M, (B) M+1(SP) M, M+1(X) M:M+1(Y) M:M+1

Load & Store Instructions

Page 48: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 48

Transfer & Exchange Instructions

Transfer instructions copy the contents of a register or accumulator into another register or accumulator.

Examples: TAB ; Transfer A to B (A) B TBA ; Transfer B to A (B) A NOTE: Source contents not changed by the operation.

Exchange instructions exchange the contents of pairs of registers or accumulators

Example: EXG A,B ; Exchanges contents of A and B

Page 49: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 49

Add & Subtract Instructions

Add Instructions

Table 1.7 Add and subtract instructions

Mnemonic

ABAABXABY

ADCAADCBADDAADDBADDD

Function

Add B to AAdd B to XAdd B to YAdd with carry to AAdd with carry to BAdd without carry to AAdd without carry to BAdd without carry to D

Operation

(A) + (B) A(B) + (X) X(B) + (Y) Y(A) + (M) + C A(B) + (M) + C B(A) + (M) A(B) + (M) B(A:B) + (M:M+1) A:B

Subtract Instructions

Mnemonic Function

SBASBCASBCBSUBASUBBSUBD

Subtract B from ASubtract with borrow from ASubtract with borrow from BSubtract memory from ASubtract memory from BSubtract memory from D

(A) - (B) A(A) - (M) - C A(B) - (M) - C B(A) - (M) A(B) - (M) B(D) - (M:M+1) D

Operation

Page 50: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 50

Move Instructions

These instructions move data bytes or words from a source (M1) to a destination (M2) in memory.

Example: MOVB $1000, $2000 ; copies the contents of the

; memory loc $1000 to loc $2000

Transfer Instructions

Table 1.6 Move instructions

Mnemonic

MOVBMOVW

Function

Move byte (8-bit)Move word (16-bit)

Operation

(M1) M2(M:M+11) M:M+12

Page 51: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 51

Assembly Language Structure

4 fields Label Operation Operand Comment

start ldaa #$03 ;load a reg

Page 52: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 52

Assembly Language Structure

Label Used to mark a certain part of the code Useful when doing branches / jumps Can use them almost like a GOTO You make them up, so can be any word you want Labels are optional, use where needed

start ldaa #$03 ;load A reg

Page 53: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 53

Assembly Language Structure

Operation Describes the operation you want to do Many operations available because CISC Ex. Add, subtract, or, load, store, branch

start ldaa #$03 ;load A reg

Page 54: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 54

Assembly Language Structure

Operand Describes what you want to do the operation to Manual will tell you what operands you need with what

operations #$03 = immediate, $03 = direct $=hex, %=binary, nothing = decimal

start ldaa #$03 ;load A reg

Page 55: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 55

Assembly Language Structure

Comment Start with a semi-colon for comment to end of line Very helpful in assembly code because it can be

hard to understand

start ldaa #$03 ;load A reg

Page 56: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 56

Assembly Instructions - load

LDAA, LDAB, LDD, LDX, LDY Load a register with a value Syntax: (label) LDAA value LDAA #$30 = load register A with the value $30 LDAA $30 = load register A with the value held in

memory location $30

Page 57: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 57

Assembly Instructions - SWI

SWI stands for software interrupt Use it to end your programs and to get back

out to the D-Bug12 prompt No operand

Page 58: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 58

Compiler Directives

Compiler directives give instructions to the compiler (NOT INSTRUCTIONS!)

Reserve space, set memory locations etc. Not actually executed like an instruction

Page 59: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 59

Compiler Directives - org

Org is used to tell the compiler where to put the program in memory

Unlike high level languages, where the program gets put anywhere it fits, in assembly you have to tell the compiler where to start putting the program

You can have multiple orgs in a program, ex to separate space for data and for the program (try not to have too many though)

Page 60: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 60

Compiler Directives - EQU

EQU = equate Like C #define Compiler will go through and substitute before

the code is compiled Requires a label to use label EQU $30

Page 61: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 61

Example

org $800

val0 RMB 1

three EQU $03

org $4000

start LDAA #three

STAA val0

SWI

Page 62: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 62

Micro computer interfacing is an important topic since it is used extensively in computer architecture and embedded systems.

Micro controllers are used in appliances, telephones, vehicles, TVs, e.t.c

To learn the assembly language programming of micro controllers we have to know the internal architecture (CPU, registers, memory map, timers, I/O ports, ….).

It is not sufficient to know the instruction set of a micro controller but also the addressing modes (i.e., how data is accessed)

Summary

Page 63: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 63

Page 64: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 64

The I/O control and data registers control and monitor the microcontroller I/O process

Microcontrollers have internal timers The microcontroller uses other external pins

for power and control and, if necessary, data and address lines

RESET is a control line that is used to bring the microcontroller to an initial state

CLOCK is also a control line

The Microcontroller Unit (MCU)

Page 65: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 65

Sometimes, a microcontroller requires more memory or I/O ports than are available in the chip mode need external data and

address line connections some pins can be used

either as I/O ports or as external data and address lines

set microcontroller’s mode of operation

Block diagram of a typicalmicrocontroller shown in expanded multiplexed mode

The MCU: Expanded Mode

Page 66: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 66

Typical Mechanisms at Interfaces

2) Synchronization, handshaking-- compensates for asynchronous clocks, clock skewaffecting synchronous signals, devices with

different response times-- bit stuffing to equalize bit rates (telecom technique)

-- framing, packet assembly and disassembly3) Digital processing

-- error detection and error correction-- data compression (e.g. using Huffman codes)

-- encoding, decoding, code conversion-- data communication protocols

1) Data buffering and flow control-- helps compensate for short-term mismatches in

data generation and consumption rates-- groups data into larger, more efficient chunks

4) Analogue signal conversion and conditioning-- restore correct voltage and current levels-- restore correct signal rise and fall times

-- take precautions to reduce noise and reflections-- carrier modulation and demodulation

-- pulse-shaping and channel equalization

Page 67: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 67

Addressing Modes

Page 68: ENG3640 Microcomputer Interfacing Week #1 Introduction to Interfacing and Microcontrollers (M68HC12)

ENG3640 Fall 2012 68

The Microcontroller System

Support components for the MCU Buffers and converters Bus – signals

data: instructions and values

address: location where data is stored

control: coordinate microcontroller operation with associated chips

Clock circuitry Power circuit