Introduction to Microcontrollers

Similar documents
Introduction to Microcontrollers II

Introduction to Microcontrollers II

Microcontrollers. Microcontroller

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

Introduction to Microcontrollers III

Introduction to Microcontrollers III

Exam I Review February 2017

EE 3170 Microcontroller Applications

Cross Assembly and Program Development

EE 3170 Microcontroller Applications

Programming the Motorola MC68HC11 Microcontroller

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

Microprocessors/Microcontrollers

Computer Organization I. Lecture 28: Architecture of M68HC11

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

Introduction to Computers - Chapter 4

Mark II Aiken Relay Calculator

HC11 Instruction Set

Microcomputer Architecture and Programming

CHAPTER 8. Solutions for Exercises

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

538 Lecture Notes Week 5

TEMPERATURE SENSOR. Revision Class. Instructor / Professor LICENSE

538 Lecture Notes Week 5

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

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

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

1. Memory Mapped Systems 2. Adding Unsigned Numbers

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

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

Using the stack and the stack pointer

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

ECE 331: PC Lab 3 Stack and Subroutines

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

Microcontrollers and the Freescale/Motorola HC11

EE 308 LAB 1 ASSEMBLER, SIMULATOR, AND MONITOR. Introduction and Objectives

MC68HC12 Parallel I/O

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

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

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

AN1745. Interfacing the HC705C8A to an LCD Module By Mark Glenewinkel Consumer Systems Group Austin, Texas. Introduction

Lab 7: Asynchronous Serial I/O

MC9S12 Address Space

Lab 1 MC9S12 Assembler and Monitor

Lab 1 MC9S12 Assembler and Monitor

CS/ECE 5780/6780: Embedded System Design

Chapter 7 Central Processor Unit (S08CPUV2)

Introduction to Programming

UNIVERSITY OF HONG KONG DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING. Principles of Computer Operation

Example Programs for 6502 Microprocessor Kit

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

The Motorola 68HC11 Instruc5on Set

SEVEN SEGMENT DISPLAY LAB EXPERIMENT

UNIVERSITY OF HONG KONG DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING

Introduction to the 9S12 Microcontroller

Lab 8: Debugging Embedded Devices and Software

HC11 Instruction Set Architecture

Microcontroller & Interfacing

68HC12 Training Lab Student Exercise Book

AN Kbyte Addressing with the M68HC11. Overview

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

EE4390 Microprocessors

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

HC11 Instruction Set Architecture

instruction 1 Fri Oct 13 13:05:

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

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

A Simple MC9S12 Program

Introduction to CPU architecture using the M6800 microprocessor

Introduction to 6811 Programming

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


SECTION 6 CENTRAL PROCESSING UNIT

8051 Overview and Instruction Set

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

ASSIGNMENT 3: PLAYING WITH THE 68HC11. Due Wednesday, Oct 9, 2002

Getting Started with the HCS12 IDE

ECE 4510/5530 Microcontroller Applications Chapter 1

Prototype Control Board for an Automated Bar (Robotic Bar Monkey)

538 Lecture Notes Week 1

Homework 12 Solutions

Design of Embedded Systems Using 68HC12/11 Microcontrollers

8051 Microcontrollers

Computer Architecture 2/26/01 Lecture #

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

Chapter 3. Z80 Instructions & Assembly Language. Von Neumann Architecture. Memory. instructions. program. data

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Timing Generation and Measurements

Interfacing the HI7190 to a Microcontroller

8051 microcontrollers

EE4390 Microprocessors. Lessons 2, 3 68HC12 Hardware Overview, Subsystems, and memory System

PUSH BUTTON. Revision Class. Instructor / Professor LICENSE

EE 3170 Microcontroller Applications

Segment 1A. Introduction to Microcomputer and Microprocessor

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)

Lecture 6 Assembly Programming: Branch & Iteration

Transcription:

Motorola M68HC11 Specs Assembly Programming Language BUFFALO Topics of Discussion Microcontrollers M68HC11 Package & Pinouts Accumulators Index Registers Special Registers Memory Map I/O Registers Instruction Set 1

What is a Microcontroller? Computer on a chip: CPU, memory, I/O devices, timing devices 68HC11 most widely used Used in automobiles, appliances, instruments, industrial controllers Control applications vs data processing Microcontroller Systems MCU Clock Circuit Other Memory & Peripherals Buffers & Converters Power Supply Bus - Data Address Control Outside World Buffers: condition I/O to proper levels Bus: data, address, control signals Clock: Fixed-frequency timing signal MCU: CPU, Memory, Registers connected by internal bus CPU: controls microcontroller operations Memory: program & data storage ROM, RAM, EEPROM Registers: temporary storage for data manipulation 2

Motorola 68HC11 MicroController Unit The CPU: 68HC11E9 8-Bit word size 6800 Instruction set w/extensions Modes of Operation: Single Chip Expanded Special Boot Test What about memory? On Chip Memory: (Refer to Chapter 4 in HC11 Reference Manual) 12k EPROM User Program & Data 512 of EEPROM Semipermanent data, calibration tables 256-512 RAM variables & temp 3

68HC11E9 Pin Connections Ground VSS Pin 1 E Clock Pin 5 PORTA Pins 34-27 PORTB Pins 42-35 PORTE Pins 43-50 Accumulators A, B 8-bit accumulators, location of math and logic functions D 16-bit accumulator, actually same physical device as A and B taken together Storage Capabilities Index Registers X, Y 16-bit registers, used for indexed addressing (may be used as general storage registers or counters) 4

Special Registers P 16-bit program counter, keeps track of address of next instruction to be executed. S 16-bit stack pointer, used for temporary storage of the program counter (needed for subroutines) C 8-bit condition code register. Stores several 1-bit flags (status indicators), and interrupt masks More 68HC11 info Input/Output: (Memory mapped) 5 parallel digital I/O ports RS-232 (connect to terminals or PCs) High Speed Synchronous Serial Parallel Handshake (Printer) Timer functions Generate precise digital signals Measure frequency and pulse width Count external events Real Time Clock 8-channel, 8-bit Analog to Digital Converter 5

I/O Registers PORTA $1000 I-0,1,2 O-3,4,5,6 BI-7 PORTB $1004 Output Only PORTC $1003 BI DDRC $1007 Def: 0=I, 1=O PORTD $1008 BI DDRD $1009 PORTE $100A Input Only Instruction Set Introduction Refer to Appendix A of HC11 Reference Manual Move Instructions Load Load value (or contents of memory location) TO Accumulators Store Store values FROM Accumulators TO Memory Transfer Transfer contents of Accumulators Stack Instructions Push and Pull Clear Instructions Clear Accumulators 6

Arithmetic Instructions Addition, Subtraction, Division Logic Instructions AND, OR, NOT Shift Instructions Shift Left, Shift Right, Rotate Left Rotate Right Control Instructions Branches Immediate Mode Direct Addressing Addressing Modes (8-Bit) Page 0 Addressing Extended Addressing (16-Bit) Indexed Addressing Use index registers X,Y 7

Immediate Mode data immediately follows instruction Use # before number constant Example: LDAA #$64 loads value $64 into AccA LDAA #100 same as above 100 = $64 AccA $64 Direct Addressing (8-bit) Mode 8-bit address of data follows instruction Also called Page 0 Addressing because assumes most significant nibble is 00 Example: LDAA $64 loads contents of memory address $0064 into AccA AccA $0064 $0065 8

Extended Addressing (16-bit) Mode 16-bit address of data follows instruction Example: LDAA $100A loads contents of memory address $100A into AccA Also: PORTE EQU $100A LDAA PORTE same as above AccA $1009 $100A Indexed Addressing Mode the operand s address is the content of the index register plus the constant given in the instruction Example: LDX #$1000 LDAA $A,X loads value $1000 into X loads value at memory location [[$1000] + $0A] into AccA AccA $1009 $100A 9

Programming the 68HC11 Know your design goals & criteria Write code and save as text file with.a11 extension Either: 1. Assemble code with AS11.exe or AS11.EXE filename.a11 -L CRE >filename.lst Load.LST file 2. Use onboard assembler Getting Started First make sure you have a copy of AS11.EXE (from the lecture webpage- see Lecture7) For easier use put it in the directory where you have your.a11 files (like your floppy disk) Next run a MS-DOS Command Prompt Window by selecting Start:Run: command.exe This brings up a command prompt window. Change the working directory to the location of your.a11 files. 10

Assemble your.a11 file using the command line: As11.exe filename.a11 L cre>filename.lst This creates a.lst file which you can use for de-bugging. It also creates a.s19 file which is loaded into the HC11. Open your.lst file in notepad and check for errors. HINT: If your.s19 file is 0 bytes, you probably had errors in your.a11 file. 11

COUNT.A11 Count pulses at an input. * Two digit bcd output. * Bruce Hoeppner 11/10/92 * Bounceless input at bit 0 of Port E * Output to Port B PORTB equ $1004 org $C000 ;origin in user RAM * Initialize MAIN clra staa PORTB * Loop while input = 0 WAIT0 ldab $100a ;read input andb #$01 ;mask off 7 msbs bnewait0 * Loop while input = 1 WAIT1 ldab $100a ;read input andb #$01 ;mask off 7 msbs beq WAIT1 adda#$01 ;increment AccA daa ;adjust forbcd staa$1004 ;write to Port B jmp WAIT0 Comments Sample Code A11File * in first column ; after commands Labels in first column Commands tabbed to right Assembling count.a11 0001 * COUNT.A11 Count pulses at an input. 0002 * Two digit bcd output. 0003 * Bruce Hoeppner 11/10/92 0004 0005 * Bounceless input at bit 0 of Port E 0006 * Output to Port B 0007 1004 PORTB equ $1004 0008 0009 c000 org $C000 ;origin in user RAM 0010 * Initialize 0011 c000 4f MAIN clra 0012 c001 b7 10 04 staa PORTB 0013 0014 * Loop while input = 0 0015 c004 f6 10 0a WAIT0 ldab $100a ;read input 0016 c007 c4 01 andb #$01 ;mask off 7 msbs 0017 c009 26 f9 bne WAIT0 0018 0019 * Loop while input = 1 0020 c00b f6 10 0a WAIT1 ldab $100a ;read input 0021 c00e c4 01 andb #$01 ;mask off 7 msbs 0022 c010 27 f9 beq WAIT1 0023 0024 c012 8b 01 adda #$01 ;increment AccA 0025 c014 19 daa ;adjust for bcd 0026 0027 c015 b7 10 04 staa $1004 ;write to Port B 0028 c018 7e c0 04 jmp WAIT0 Sample Code LST File Created after using As11.exe Useful for finding errors in code 12

INNOTOUT.A11 INNOTOUT.A11 Read word, NOT it, Write it * Bruce Hoeppner 01 JAN 94 * * Read an 8-bit word from PortE. * Complement the word. * Write the word to PortB. * Loop Continuously. * Essentially this turns the HC11 into an * Octal Inverter. * Definitions PORTB equ $1004 ******************************************** * Load program into 8k user RAM START org $C000 * Read 8-bit word from PortE into AccA ldaa $100a * Complement the word. coma * Write the word to PortB staa PORTB * Jump back to beginning of program jmp START * End of INNOTOUT.A11 0001 * INNOTOUT.A11 Read word, NOT it, Write it 0002 * Bruce Hoeppner 01 JAN 94 0003 * 0004 * Read an 8-bit word fromporte. 0005 * Complement the word. 0006 * Write the word to PortB. 0007 * Loop Continuously. 0008 * Essentially this turns the HC11 into an 0009 * Octal Inverter. 0010 0011 * Definitions 0012 1004 PORTB equ $1004 0013 ******************************************** 0014 * Load program into 8k user RAM 0015 c000 START org $C000 0016 0017 * Read 8-bit word from PortE into AccA 0018 c000 b6 10 0a ldaa $100a 0019 * Complement the word. 0020 c003 43 coma 0021 * Write the word to PortB 0022 c004 b7 10 04 staa PORTB 0023 0024 * Jump back to beginning of program 0025 c007 7e 00 00 jmp START 0026 13

Mult4bit.lst Assembling mult4bit.a11 0001 * MULT4BIT.A11 Multiply using repeated addition 0002 * P = M x N 0003 * Bruce Hoeppner 10/7/89 0004 0005 c000 org $C000 ;origin in user RAM 0006 0007 c000 f6 10 0a ldab $100a ;load M & N into AccB 0008 c003 17 tba ;Copy B to A 0009 c004 c4 0f andb #$0f ;Mask off M from N 0010 c006 44 lsra 0011 c007 44 lsra 0012 c008 44 lsra 0013 c009 44 lsra ;Move M to 4 LSBs 0014 c00a 84 0f anda #$0f ;Mask off N from M 0015 c00c b7 d0 00 staa $d000 ;Store acca in temp 0016 c00f 4f clra ;clear accumulator A 0017 Continued on next slide Mult4bit.lst 0018 c010 c1 00 multiply cmpb #00 ;check for N = 0 0019 c012 2e 03 bgt addem ;branch to addem when 0020 * ;accb > 0 0021 c014 7e e0 0a jmp $e00a ;when N = 0 you are done 0022 * ;go back to BUFFALO 0023 0024 c017 bb d0 00 addem adda $d000 ;acca = acca + M 0025 c01a 5a decb ;decrement accb 0026 * ;accb = accb - 1 0027 * ;N = N - 1 0028 0029 c01b b7 d0 01 staa $d001 ;store result P 0030 0031 c01e 20 f0 bra multiply 0032 0033 c020 end ;end of MULT.A11 14

Bit User Fast Friendly Aid to Logical Operations BUFFALO Quick Reference (9-19) Numeric Values assumed HEX ASM <addr> Onboard assembler <CR> Next line of code <backspace> abort onboard assembly G <addr> Go, execute help More BUFFALO LOAD T download assembled file MD <addr> memory display MM <addr> memory modify <space> next memory location <CR> return to BUFFALO RM register modify T <n> trace (NOTE: set P before trace) 15

Using the On-board Assembler 0011 * Definitions 0012 1004 PORTB equ $1004 0013 0014 * Load program into 8k user RAM 0015 c000 START org $C000 0016 0017 * Read 8-bit word from PortE into AccA 0018 c000 b6 10 0a ldaa $100a 0019 * Complement the word. 0020 c003 43 coma 0021 * Write the word to PortB 0022 c004 b7 10 04 staa PORTB 0023 0024 * Jump back to beginning of program 0025 c007 7e 00 00 jmp START * Only recognizes HEX values ASM C000 <CR> ldaa 100a <CR> coma <CR> staa #1004 <CR> jmp C000 More Fun and Educational Reading HC11 Reference Manual BUFFALO Monitor Quick Users Reference 68HC11 Instruction Set Introduction Sample Programs Search Motorola s Website for 68HC11 16

Experiment #7: 68HC11 Introduction Purpose: Learn to use microprocessors and microcontrollers, particularly the Motorola 68HC11. Learn to program in 68HC11 assembly language. Become familiar with programming the M68HC11. Preparation: Read the entire section of this laboratory exercise in this Laboratory Manual. Also read and familiarize yourself with the sections in the Class Notes pertaining to Microprocessors. Prepare data for each experiment section of this lab. Indicate a specific test plan for each experiment. Edit a text file containing the 68HC11 assembly language program: COUNT.A11. Download AS11.EXE from the class website. Assembly the program using the AS11.EXE assembler. >AS11 COUNT.A11 -L CRE >COUNT.LST Check COUNT.LST for errors. Correct any errors, and re-assemble. Design a two digit (decimal) 7-segment display to connect to HC11-143 PortB connector. Paste, tape or staple copies of your LST files into your notebook. Reminder: Bring to lab: a printout of COUNT.LST, a floppy disk containing your source file, COUNT.A11, and object code file, COUNT.S19. Experiment Procedure: 1. 68HC11 Start-Up and Test Measure the E clock frequency and duty cycle of the M68HC11EVB Simple Output: Use the BUFFALO monitor's Memory Modify (MM) command to change an output port. Simple Input: Use the BUFFALO monitor's Memory Display (MD) and/or Memory Modify (MM) commands to change and display the binary value at an input port. 2. On-Board Assembly -- Arithmetic: Multiplication using repeated addition. Enter program MULT4BIT.A11 into the EVB's memory using the on-board assembler (ASM C000). Connect PortE pins to logic switches. N is 4 lsbs. M is 4msbs. Run the program using the Go (G C000) command. Use the Memory Display (MD) command to display the product at address $D001 (P). Repeat steps b through d for a several values of M and N. 3. Uploading Programs -- Counter program. Uploading programs from PC to EVB. (If PC is not available enter COUNT.A11 into the EVB using the onboard assembler.) Turn off power to the EVB. Connect PortE, bit 0 to a push-button on the CADET. (A pull-up resistor is needed.) Connect your two-digit display to PortB of the EVB. Execute the Count program. 17