Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:



Similar documents
Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

M6800. Assembly Language Programming

Introduction to Microcontrollers

HC12 Assembly Language Programming

The stack and the stack pointer

Programmer s Model = model of µc useful to view hardware during execution of software instructions

MICROPROCESSOR AND MICROCOMPUTER BASICS

Programming the Motorola MC68HC11 Microcontroller

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

CHAPTER 7: The CPU and Memory

How To Write A Microsoft Microsoft 8D (Droid) (Program) (Powerbook) (I386) (Microsoft) (Donga) (Opera) And (Dungeo) (Dugeo

Microprocessor & Assembly Language

PART B QUESTIONS AND ANSWERS UNIT I

MACHINE ARCHITECTURE & LANGUAGE

Microprocessor/Microcontroller. Introduction

CHAPTER 6: Computer System Organisation 1. The Computer System's Primary Functions

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

6800 Basics. By Ruben Gonzalez

Microprocessor or Microcontroller?

How To Understand All Instructions In The Power12 Program

Microcontrollers A Brief History of Microprocessors

Z80 Instruction Set. Z80 Assembly Language

Chapter 13. PIC Family Microcontroller

Lecture N -1- PHYS Microcontrollers

1 Classical Universal Computer 3

Section 44. CPU with Extended Data Space (EDS)

MICROPROCESSOR BCA IV Sem MULTIPLE CHOICE QUESTIONS

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

Microprocessor and Microcontroller Architecture

Microcontrollers and the Freescale/Motorola HC11

Management Challenge. Managing Hardware Assets. Central Processing Unit. What is a Computer System?

Call Subroutine (PC<15:0>) TOS, (W15)+2 W15 (PC<23:16>) TOS, Process data. Write to PC NOP NOP NOP NOP

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

U:\montages\dominique\servo\moteur_AV_AR\program\moteur_AV_AR.asm jeudi 28 avril :32

Computer Organization and Architecture

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

8085 INSTRUCTION SET

8051 hardware summary

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

An Overview of Stack Architecture and the PSC 1000 Microprocessor

EMBEDDED SYSTEM BASICS AND APPLICATION

Z80 Microprocessors Z80 CPU. User Manual UM Copyright 2014 Zilog, Inc. All rights reserved.

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

The string of digits in the binary number system represents the quantity

Chapter 2 Logic Gates and Introduction to Computer Architecture

Instruction Set Design

Chapter 5, The Instruction Set Architecture Level

Central Processing Unit (CPU)

LABORATORY MANUAL EE0310 MICROPROCESSOR & MICROCONTROLLER LAB

PROBLEMS (Cap. 4 - Istruzioni macchina)

CHAPTER 4 MARIE: An Introduction to a Simple Computer

CPU Organization and Assembly Language

================================================================

(Refer Slide Time: 00:01:16 min)

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

An Introduction to the ARM 7 Architecture

MACHINE INSTRUCTIONS AND PROGRAMS

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

2011, The McGraw-Hill Companies, Inc. Chapter 3

Instruction Set Architecture

M68HC05 Family. Understanding Small Microcontrollers. Freescale Semiconductor, I. For More Information On This Product, Go to:

Microcontrollers in Practice

Introduction to Microcontrollers

1 Computer hardware. Peripheral Bus device "B" Peripheral device. controller. Memory. Central Processing Unit (CPU)

Logical Operations. Control Unit. Contents. Arithmetic Operations. Objectives. The Central Processing Unit: Arithmetic / Logic Unit.

Keil Debugger Tutorial

Computer organization

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

CSE2102 Digital Design II - Topics CSE Digital Design II

The Central Processing Unit:

Timer A (0 and 1) and PWM EE3376

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Chapter 6. Inside the System Unit. What You Will Learn... Computers Are Your Future. What You Will Learn... Describing Hardware Performance

Computer Performance. Topic 3. Contents. Prerequisite knowledge Before studying this topic you should be able to:

İSTANBUL AYDIN UNIVERSITY

Embedded Software Development: Spottbillige Hardware + OSS = Zum Spielen zu Schade!

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Keil C51 Cross Compiler

SECTION C [short essay] [Not to exceed 120 words, Answer any SIX questions. Each question carries FOUR marks] 6 x 4=24 marks

Open Architecture Design for GPS Applications Yves Théroux, BAE Systems Canada

Chapter 02: Computer Organization. Lesson 04: Functional units and components in a computer organization Part 3 Bus Structures

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

AN2183. Using FLASH as EEPROM on the MC68HC908GP32. Introduction. Semiconductor Products Sector Application Note

CPU Organisation and Operation

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

OVERVIEW OF MICROPROCESSORS

Faculty of Engineering Student Number:

Chapter 2: Elements of Java

ELEG3924 Microprocessor Ch.7 Programming In C

1 The Java Virtual Machine

2.0 Command and Data Handling Subsystem

M68HC05. Microcontrollers MC68HC705J1A MC68HRC705J1A MC68HSC705J1A MC68HSR705J1A. Technical Data

Transcription:

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes: An 8 or 16 bit microprocessor (CPU). A small amount of RAM. Programmable ROM and/or flash memory. Parallel and/or serial I/O. Timers and signal generators. Analog to Digital (A/D) and/or Digital to Analog (D/A) conversion. Often used to run dedicated code that controls one or more tasks in the operation of a device or a system. Also called embedded controllers, because the microcontroller and support circuits are often built into, or embedded in, the devices they control. Devices that utilize microcontrollers include car engines, consumer electronics (VCRs, microwaves, cameras, pagers, cell phones.. ), computer peripherals (keyboards, printers, modems.. ), test/measurement equipment (signal generators, multimeters, oscilloscopes ). Microcontrollers usually must have low-power requirements (~. 05-1 W as opposed to ~10-50 W for general purpose desktop CPUs) since many devices they control are battery-operated. #1 Lec # 20 Winter99 2-9-2000

Microcontroller Components From sensors To actuators Displays, keyboard etc. Single Chip RAM, EPROM, EEPROM, flash Examples: Motorola s 68HC11, 68HC12, AMD 29K, Zilog s Z8, Z80, Intel s 8052, Microchip s PIC Low-power, embedded versions of desktop CPUs: e.g Intel s 80486 #2 Lec # 20 Winter99 2-9-2000

A Typical Microcontroller Application: Speed Measurement Car Cruise Control #3 Lec # 20 Winter99 2-9-2000

The Motorola 68HC12 Microcontroller A Typical 68HC12 has the following components on the chip: A 16-bit central processing unit (CPU12): 20-Bit ALU. Instruction Queue. Enhanced Indexed Addressing. Fuzzy Logic Instructions. 32-Kbyte Flash EEPROM with 2-Kbyte Erase-Protected Boot Block. 768-Byte EEPROM. 1-Kbyte RAM with Single-Cycle Access for Aligned or Misaligned Read/Write. 8-Channel, 8-Bit Analog-to-Digital (A/D) Converter. 8-Channel Timer. 16-Bit Pulse Accumulator: External Event Counting, Gated Time Accumulation. Pulse-Width Modulator: 8-Bit, 4-Channel or 16-Bit, 2-Channel Separate Control for Each Pulse Width and Duty Cycle #4 Lec # 20 Winter99 2-9-2000

A Typical 68HC12 Chip Pin-Out MC68HC912B32 #5 Lec # 20 Winter99 2-9-2000

M68EVB912B32 Evaluation Board Layout #6 Lec # 20 Winter99 2-9-2000

Motorola 68HC12 16-bit Memory Address Space 0x0800 0x08FF 0x0900 0x09FF User Program Memory: 256 bytes User Data Memory: 256 bytes #7 Lec # 20 Winter99 2-9-2000

68HC12 Programming Model: Registers #8 Lec # 20 Winter99 2-9-2000

68HC12 Registers A 8-bit Accumulator A B 8-bit Accumulator B D 16-bit Double accumulator D (A : B) X 16-bit Index register X Y 16-bit Index register Y SP 16-bit Stack pointer PC 16-bit Program Counter CCR Condition code register: S STOP instruction control bit X Non-maskable interrupt control bit H Half-carry status bit I Maskable interrupt control bit N Negative status bit Z Zero status bit V Two s complement overflow status bit C Carry/Borrow status bit #9 Lec # 20 Winter99 2-9-2000

68HC12 Data Types The HC12 uses the following types of data: Bits. 5-bit signed integers. 8-bit signed and unsigned integers. 8-bit, 2-digit binary coded decimal (BCD) numbers. 9-bit signed integers. 16-bit signed and unsigned integers. 16-bit effective addresses. 32-bit signed and unsigned integers. 5-bit and 9-bit signed integers are used only as offsets for indexed addressing modes. 16-bit effective addresses are formed during addressing mode computations. 32-bit integer dividends are used by extended division instructions. Extended multiply and extended multiply-and-accumulate instructions produce 32-bit products. #10 Lec # 20 Winter99 2-9-2000

68HC12 Addressing Modes Inherent Addressing Mode (INH). Immediate Addressing Mode (IMM). Direct Addressing Mode (DIR). Extended Addressing Mode (EXT). Indexed Addressing Modes: 5-Bit Constant Offset Indexed Addressing (IDX). Auto Pre/Post Decrement/Increment Indexed Addressing (IDX) Accumulator Offset Indexed Addressing (IDX). 9-Bit Constant Offset Indexed Addressing (IDX1). 16-Bit Constant Offset Indexed Addressing (IDX2). Indirect Indexed Addressing: 16-Bit Constant Offset Indexed Addressing [IDX2]. Accumulator D Indirect Indexed Addressing [D, IDX]. #11 Lec # 20 Winter99 2-9-2000

68HC12 Addressing Modes Inherent Addressing Mode (INH): Instructions that use this addressing mode either have no operands or all operands are in internal CPU registers. Examples: NOP CLRA ABA ASRA ; this instruction has no operands ; clear A ; add A to B result in A ; arithmetic shift right A Immediate Addressing Mode (IMM): Examples: LDAA #$55 ; load A with the 8-bit value $55 LDX #$1234 ; load index register X with 16-bit address $1234 LDY #$67 ; load index register Y with 16-bit address $0067 ADDA #$17 ; add the value $17 to register A, result in A #12 Lec # 20 Winter99 2-9-2000

68HC12 Addressing Modes Direct Addressing Mode (DIR): Used to access operands in the memory address range $0000 through $00FF Examples: LDAA $55 ; load register A with 8-bit value in memory address $0055 LDX $20 ; load index register X with 16-bit value in $0020, $0021 STY $50 ; store value of Y to memory addresses $0050, $0051 Extended Addressing Mode (EXT): Used to access operands in the full 16-bit address of the memory. Examples: LDAA $F03B ; load register A with 8-bit value from address $F03B LDX $0900 ; load index register X with 16-bit value in $0900, $0901 #13 Lec # 20 Winter99 2-9-2000

68HC12 Indexed Addressing Modes 5-Bit Constant Offset Indexed Addressing (IDX): Uses an 5-bit signed offset (range -16 to 15) which is added to the base index register (X, Y, SP, or PC) to form the effective address: Examples: LDAA 12,X ; load A with the byte at memory address (X) + 12 STAB 8,Y ; store the byte in B at address (Y) - 8 ADDA 5,X ; add A to the byte at (X) + 5, result in A 9-Bit Constant Offset Indexed Addressing (IDX1): Uses an 9-bit signed offset (range -256 to 255) which is added to the base index register (X, Y, SP, or PC) to form the effective address: Examples: LDAA $FF,X ; load A with the byte at memory address (X) + $FF STAB 20,Y ; store the byte in B at address (Y) - 20 16-Bit Constant Offset Indexed Addressing (IDX2): Uses an 16-bit offset which is added to the base index register (X, Y, SP, or PC) to form the effective address. This allows access to any address in the 64-Kbyte address space. #14 Lec # 20 Winter99 2-9-2000

Auto Pre/Post Decrement/Increment Indexed Addressing (IDX) Predecrement and preincrement versions of the addressing mode adjust the value of the index register before accessing the memory location affected by the instruction: STAA 1, SP STX 2, SP ;equivalent to PSHA ;equivalent to PSHX Post-decrement and postincrement versions of the addressing mode use the initial value in the index register to access the memory location affected by the instruction, then change the value of the index register. LDX 2,SP+ LDAA 1,SP+ ;equivalent to PULX ;equivalent to PULA #15 Lec # 20 Winter99 2-9-2000

Indexed Addressing Modes Accumulator Offset Indexed Addressing (IDX): In this indexed addressing mode, the effective address is the sum of the values in the base index register (X, Y, SP, or PC) and an unsigned offset in one of the accumulators (8bit A, B or 16-bit D). Example: LDAA B,X This instruction internally adds B to X to form the address from which A will be loaded. #16 Lec # 20 Winter99 2-9-2000

Indirect Indexed Addressing 16-Bit Constant Offset Indexed Addressing [IDX] : Adds a 16-bit instruction-supplied offset to the base index register to form the address of a memory location that contains a pointer to the memory location affected by the instruction. Example: LDAA [10,X] In this example, X holds the base address of a table of pointers. Assume that X has an initial value of $1000, and that the value $2000 is stored at addresses $100A and $100B. The instruction first adds the value 10 to the value in X to form the address $100A. Next, an address pointer ($2000) is fetched from memory at $100A. Then, the byte value stored in location $2000 is read and loaded into the A accumulator. #17 Lec # 20 Winter99 2-9-2000

Indirect Indexed Addressing Accumulator D Indirect Indexed Addressing [D,IDX]: Adds the value in the D accumulator to the value in the base index register to form the address of a memory location that contains a pointer to the memory location affected by the instruction. The square brackets distinguish this addressing mode from D accumulator offset indexing. Example: JMP GO1 DC.W GO2 DC.W GO3 DC.W [D,PC] PLACE1 PLACE2 PLACE3 Assume that the value in D is $0002. The JMP instruction adds the values in D and PC to form the address of GO2. Next the CPU reads the address PLACE2 from memory at GO2 and jumps to PLACE2. #18 Lec # 20 Winter99 2-9-2000

68HC12 Load & Store Instructions #19 Lec # 20 Winter99 2-9-2000

68HC12 Transfer & Exchange Instructions #20 Lec # 20 Winter99 2-9-2000

68HC12 Move Instructions #21 Lec # 20 Winter99 2-9-2000

68HC12 Addition & Subtraction Instructions #22 Lec # 20 Winter99 2-9-2000

68HC12 BCD Instructions #23 Lec # 20 Winter99 2-9-2000

HC12 Increment & Decrement Instructions #24 Lec # 20 Winter99 2-9-2000

HC12 Compare & Test Instructions #25 Lec # 20 Winter99 2-9-2000

HC12 Logic Instructions #26 Lec # 20 Winter99 2-9-2000

HC12 Clear, Complement & Negate Instructions #27 Lec # 20 Winter99 2-9-2000

HC12 Multiplication & Division Instructions #28 Lec # 20 Winter99 2-9-2000

Multiply and Accumulate Instruction EMACS The EMACS instruction multiplies two 16-bit operands stored in memory and accumulates the 32-bit result in a third memory location. Often used to implement simple digital filters. #29 Lec # 20 Winter99 2-9-2000

HC12 Bit Test & Manipulation Instructions #30 Lec # 20 Winter99 2-9-2000

HC12 Logical Shifts Instructions #31 Lec # 20 Winter99 2-9-2000

HC12 Arithmetic Shifts Instructions #32 Lec # 20 Winter99 2-9-2000

HC12 Rotate Instructions #33 Lec # 20 Winter99 2-9-2000

HC12 Short Branch Instructions The numeric range of short branch offset values is $80 ( 128) to $7F (127) #34 Lec # 20 Winter99 2-9-2000

HC12 Short Branch Instructions The numeric range of short branch offset values is $80 ( 128) to $7F (127) #35 Lec # 20 Winter99 2-9-2000

HC12 Long Branch Instructions The numeric range of long branch offset values is $8000 ( 32,768) to $7FFF (32,767) #36 Lec # 20 Winter99 2-9-2000

HC12 Long Branch Instructions The numeric range of long branch offset values is $8000 ( 32,768) to $7FFF (32,767) #37 Lec # 20 Winter99 2-9-2000

HC12 Decrement/Branch Instructions #38 Lec # 20 Winter99 2-9-2000

HC12 Jump & Subroutine Instructions #39 Lec # 20 Winter99 2-9-2000

HC12 Interrupt Instructions #40 Lec # 20 Winter99 2-9-2000

HC12 Stack Related Instructions #41 Lec # 20 Winter99 2-9-2000

HC12 Stack Related Instructions #42 Lec # 20 Winter99 2-9-2000

HC12 Condition Codes Instructions #43 Lec # 20 Winter99 2-9-2000

HC12 Example: Addition of Two Values USER_STACKTOP equ $0a00 org $0800 Main lds #USER_STACKTOP ;load stacktop ldaa #FIRST ;load first byte in A adda #SECOND ;add second value to A result in A staa ANSWER ;store result in answer End bra End ;done with program org $0900 FIRST dc.b #$01 ;first value to add SECOND dc.b #$02 ;second value to add ANSWER dc.b #$00 ;addition result #44 Lec # 20 Winter99 2-9-2000

USER_STACKTOP equ $0a00 org $0800 HC12 Loop Example Main: lds #USER_STACKTOP ;load stacktop ldaa #ITER ;load number of iterations to perform ldab #COUNT ;load number of iterations performed already loop: deca ;decrement Acc A incb ;increment Acc B cmpa #$00 ;Is Acc A = 0? bne loop ;No, continue with loop stab COUNT ;Otherwise, save the count End: bra End ;done with program org $0900 ITER dc.b #$08 ;Number of loop iterations to perform COUNT dc.b #$00 ;Number of loop iterations performed #45 Lec # 20 Winter99 2-9-2000

HC12 Data Table Example ; This program takes a table of data, and creates a new table ; which is the original table divided by 2 prog: equ $0800 ;put program at address 0x0800 data: equ $0900 ;put data at address 0x0900 count: equ 10 ;number of entries in table org prog ;set program counter to 0x0800 ldx #table1 ;Reg X points to entry to process in table 1 ldy #table2 ;Reg Y points to entry to write to table 2 ldab #count ;ACC B holds number of entries left to process repeat: ldaa 1,x+ ;Get table1 entry into ACC A; inc X to next entry asra ;Divide by 2 staa 1,y+ ;Save in table2; inc Y to next entry in table2 dbne b,repeat ;Decrement number left to process; ;If not done, process next table1 entry swi ;Done -- Exit org data ;initialize table1 (COUNT bytes long) table1: dc.b $07,$ae,$4a,$f3,$6c,$30,$7f,$12,$67,$cf table2: ds.b count ;reserve count bytes for table2. #46 Lec # 20 Winter99 2-9-2000