The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers.    


Datasheet Search Engine   
 
Part # or Description: • 5V RS232 Driver • 2SC5066* • "Real Time Clock" • "USB connector" • "blue led" 5mm • 10 watt zener diode • 2N3055* motorola
 
Search Tip: Try entering the part number only. Include a wildcard (eg. lm317* or 1n4148*)

 

 

M68HC05 Applications Guide M68HC05 Microcontroller Applicati


Datasheet Thumbnail

  

Download PDF



Top Searches for this datasheet



M68HC05AG/AD Rev.
M68HC05 Applications Guide
M68HC05 Microcontroller
Applications Guide
Motorola, Inc., 1996; Rights Reserved
Motorola reserves right make changes without further notice products herein improve reliability, function, design. Motorola does assume liability arising application product circuit described herein; neither does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended unauthorized application, Buyer shall indemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims, costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury death associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola Motorola logo registered trademarks Motorola, Inc. Motorola, Inc. Equal Opportunity/Affirmative Action Employer.
Revision History
Revision History
This table summarizes differences between this revision previous revision this applications guide.
Previous Revision Current Revision Date Changes Location
06/96 Format organizational changes Throughout
M68HC05 Microcontroller Applications Guide MOTOROLA
Revision History
M68HC05 Microcontroller Applications Guide MOTOROLA
List Sections
General Description Microcontroller Operation MC68HC705C8 Functional Data Applications .197 Instruction Details .245 Review Questions .315
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA List Sections
List Sections
M68HC05 Microcontroller Applications Guide Rev. List Sections MOTOROLA
Table Contents
General Description
Contents Introduction Definitions Background Computer Systems Description Microcontroller Applications Overview Project Description
Microcontroller Operation
Contents Introduction Number Systems Computer Codes Computer Memory Computer Architecture Registers Memory Uses Memory Maps Timing Programming Flowchart Mnemonic Source Code Software Delay Program Assembler Listing View Program Operation Detailed Operation Instructions Store Accumulator (Direct Addressing Mode) Load Accumulator (Immediate Addressing Mode) Conditional Branch Subroutine Calls Returns Playing Computer
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Table Contents
Table Contents
On-Chip Peripherals Serial Communications Interface (SCI) Serial Peripheral Interface (SPI) 16-Bit Timer System Memory Peripherals Other On-Chip Peripherals
MC68HC705C8 Functional Data
Contents Introduction Description Hardware Features Software Features General Description Pins Connections Functions (Maskable Interrupt Request) RESET TCAP TCMP OSC1 OSC2 PA7-PA0 PB7-PB0 PC7-PC0 PD5-PD0 Typical Basic Connections On-Chip Memory Memory Types Memory Central Processor Unit Registers Accumulator Index Register Condition Code Register Program Counter Stack Pointer Arithmetic/Logic Unit (ALU)
M68HC05 Microcontroller Applications Guide Rev. Table Contents MOTOROLA
Table Contents
Control Resets Power-On RESET Computer Operating Properly (COP) Watchdog Timer RESET .101 Clock Monitor RESET .103 Addressing Modes .104 Inherent Addressing Mode .105 Immediate Addressing Mode .107 Extended Addressing Mode .109 Direct Addressing Mode .111 Indexed Addressing Modes .113 Indexed, Offset .113 Indexed, 8-Bit Offset .115 Indexed, 16-Bit Offset .117 Relative Addressing Mode .119 Test Branch Instructions .121 Instructions Organized Type .121 Instruction Summary .126 Interrupts .134 Software Interrupt (SWI) .135 External Interrupt .137 Timer Interrupt .137 Serial Communications Interface (SCI) Interrupt .138 Serial Peripheral Interface (SPI Interrupt .138 Microcontroller Input/Output .139 Parallel .139 Serial .142 Serial Communications Interface (SCI) .143 Transmitter .144 Receiver .146 Registers .148 Baud Rate Register (BAUD) .148 Serial Communications Control Register (SCCR1) .151 Serial Communications Control Register (SCCR2) .152 Serial Communications STATUS Register (SCSR) .153 Serial Communications Data Register (SCDAT) .154 Data Formats .155 Hardware Procedures .155 Software Procedures .156
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Table Contents
Table Contents
Initialization Procedure .156 Normal Transmit Operation .157 Normal Receive Operation .157 Application Example .158 Synchronous Serial Peripheral Interface (SPI) .161 Data Movement .163 Functional Description .164 Descriptions .164 Serial Data Pins (MISO, MOSI) .164 Serial Clock (SCK) .165 Slave Select (SS) .165 Registers .166 Serial Peripheral Control Register (SPCR) .166 Serial Peripheral Status Register (SPSR) .168 Serial Peripheral Data Register (SPDR) .169 Application Example .170 Programmable Timer .173 Functional Description .176 Timer Counter Alternate Counter Registers .178 Input-Capture Concept .179 Input-Capture Operation .180 Output-Compare Concept .182 Output-Compare Operation .184 Timer Control Register (TCR) .185 Timer Status Register (TSR) .186 Timer Application Example .187 STOP/WAIT Instruction Effects .187 Power-Consumption Modes .187 Effects On-Chip Peripherals .190 Timer Action During STOP Mode .190 Action During STOP Mode .190 Action During STOP Mode .190 Wait Mode Effects .191 OTPROM/EPROM Programming .192 Erasing .192 Programming .192 Program Register .193 Option Register .194
M68HC05 Microcontroller Applications Guide Rev. Table Contents MOTOROLA
Table Contents
Applications
Contents .197 Introduction .197 Hardware Development Methods .199 Software Development Methods .201 Freeware .203 Third-Party Software .204 Thermostat Project Details .206 Hardware Details .207 Project Programming .210
Instruction Details
Contents .245 Introduction .247 M68HC05 Instruction .249 with Carry without Carry Logical Arithmetic Shift Left. Arithmetic Shift Right. Branch Carry Clear BCLR Clear Memory Branch Carry Set. Branch Equal. BHCC Branch Half Carry Clear BHCS Branch Half Carry Set. Branch Higher. Branch Higher Same. Branch Interrupt High. Branch Interrupt Test Memory with Accumulator Branch Lower Branch Lower Same Branch Interrupt Mask Clear Branch Minus Branch Interrupt Mask Set. Branch Equal Branch Plus. Branch Always BRCLR Branch Clear. Branch Never BRSET Branch
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Table Contents
Table Contents
BSET Memory. Branch Subroutine Clear Carry Bit. Clear Interrupt Mask Clear. Compare Accumulator with Memory Complement. Compare Index Register with Memory Decrement Exclusive-OR Memory with Accumulator. Increment Jump. Jump Subroutine. Load Accumulator from Memory Load Index Register from Memory Logical Shift Left. Logical Shift Right. Multiply Unsigned. Negate Operation Inclusive-OR Rotate Left thru Carry. Rotate Right thru Carry. Reset Stack Pointer Return from Interrupt Return from Subroutine Subtract with Carry. Carry Bit. Interrupt Mask Store Accumulator Memory STOP Enable IRQ, Stop Oscillator. Store Index Register Memory. Subtract. Software Interrupt Transfer Accumulator Index Register Test Negative Zero. Transfer Index Register Accumulator WAIT Enable Interrupt, Stop Processor
Review Questions
Contents .315 Introduction .315 Review Questions .316 Review Questions, Answers, Explanations .330
M68HC05 Microcontroller Applications Guide Rev. Table Contents MOTOROLA
List Figures
Figure
Title
Page
Typical Computer System.24 Temperature Control Flowchart Thermostat Project Block Diagram.28 Expanded Block Diagram.33 M68HC05 Registers Memory Circuitry Typical Memory Example Flowchart.49 Flowchart Mnemonics Delay Routine Flowchart Mnemonics Assembler Listing Explanation Assembler Listing Memory Example Program.59 Subroutine Call Sequence.65 Playing Computer Worksheet.69 Completed Worksheet.70 MC68HC705C8 Microcontroller Block Diagram 40-Pin Dual-In-Line Package Assignments.85 44-Lead PLCC Package Assignments.86 Oscillator Connections Typical Basic Connections MC68HC705C8 Memory M68HC05 Block Diagram Programming Model Accumulator (A).95 Index Register Condition Code Register (CCR) Program Counter (PC) Stack Pointer (SP).98 Hardware Interrupt Flowchart.136 Interrupt Stacking Order .137
M68HC05 Microcontroller Applications Guide Rev.
MOTOROLA
List Figures
List Figures
Figure Title Page
Port Data Direction Registers .139 Port Data Direction Registers .140 Port Data Direction Registers.140 Parallel Port Circuitry.141 Port Fixed Input Port.142 Transmitter Block Diagram .145 Receiver Block Diagram .147 Baud Rate Register .149 Rate Generator Division .149 Serial Communications Control Register One.151 Serial Communications Control Register Two.152 Serial Communications Status Register .153 Serial Communications Data Register .154 Double Buffering.154 Data Formats.155 Normal Transmit Operation Flowchart .157 Normal Receive Operation Flowchart .157 SCII Application Example Program .160 Block Diagram .162 Shift Register Operation .163 Data/Clock Timing Diagram .165 Serial Peripheral Control Register .166 Serial Peripheral Status Register .168 Serial Peripheral Data Register .169 Application Example Diagram .171 Application Example Flowchart .174 Application Example Program .175 Programmable Timer Block Diagram .177 16-Bit Counter Reads.178 Input-Capture Operation.181 Output-Compare Operation.182 Timer Control Register .185 Timer Status Register.186 Timer Application Example Program .188 STOP/WAIT Flowchart .189 Program Register .193 Option Register .194
M68HC05 Microcontroller Applications Guide Rev. List Figures MOTOROLA
List Figures
Figure
Title
Page
Thermostat Project Schematic Diagram.208 Precision Temperature Sensing Circuit .209 Port Summary .211 Port Summary .211 Port Summary.212 Port Summary.212 Display Checkout Flowchart.214 Display Checkout Program Listing .216 Keypad Checkout Flowchart .219 Keypad Checkout Program Listing.220 Main Program Flowchart .222
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA List Figures
List Figures
M68HC05 Microcontroller Applications Guide Rev. List Figures MOTOROLA
List Tables
Table
Title
Page
Decimal, Binary Hexadecimal Equivalents Timeout Period versus CM0.102 Register/Memory Instructions.122 Read/Modify-Write Instructions .123 Branch Instructions.124 Control Instructions.125 Instruction Summary .127 M68HC05 Instruction Opcode Map.133 Vector Address Interrupts Reset .135 Functions .141 Prescaler Baud Rate Frequency Output.150 Transmit Baud Rate Output.151 ASCII-Hexadecimal Code Conversion .159 Thermostat Project Parts List .210
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA List Tables
List Tables
M68HC05 Microcontroller Applications Guide Rev. List Tables MOTOROLA
General Description
Contents
Introduction Definitions Background Computer Systems Description Microcontroller Applications Overview Project Description
Introduction
Welcome world microcontrollers! this applications guide, will develop project using Motorola MC68HC705C8 microcontroller unit (MCU) familiar application home thermostat. MC68HC705C8 member M68HC05 Family MCUs. project will demonstrate only many possible microcontroller functions that use. This guide assumes that have knowledge microcontrollers applications experience. General Description begins with definitions, gives background information, describes computer systems. overview microcontroller applications also presented application project discussed. Microcontroller Operation describes detail microcontrollers operate.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA General Description
General Description
MC68HC705C8 Functional Data contains functional data Motorola MC68HC705C8 MCU. This section gives specific information needed this application. More information found slightly different form BR594/D, MC68HC705C8 Technical Summary, which available separately. Applications shows develop applications gives thermostat project details. Instruction Details provides detailed description each instruction MC68HC05 instruction set. Review Questions contains review questions, answers, explanations.
Definitions
heart computer central processor unit (CPU). microprocessor single chip. computer system plus peripherals such input/output (I/0) devices, memory, program, timing reference. microcontroller very small product that contains many functions found computer system. microcontroller uses microprocessor CPU) well memory peripherals same chip. microcontroller (MCU) packaged single chip that programmed user with series instructions loaded into memory.
M68HC05 Microcontroller Applications Guide Rev. General Description MOTOROLA
General Description Background
Background
Before MCUs, controllers were hard-wired electronic devices whose operation determined circuits wires contained within them. operation MCU-based controller determined primarily program instead components wires. function that implemented using hard-wired digital integrated circuits (ICs) also implemented performed MCU. size complexity devices increase, MCUs become attractive reasons: hard-wired approach requires adding perform more complex tasks; whereas, MCUs require only longer program. Microcontrollers more versatile. change hard-wired system usually involves replacing rerouting wires. Most modifications system made simply changing program. MCUs very useful where many decisions calculations required. easier computational power computer than discrete logic. Microcontrollers being used replace existing designs because they simpler than conventional logic. Since approach programmable, many additional features possible little added cost. Programmability makes possible multiple common piece hardware since only control program needs changed.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA General Description
General Description
Computer Systems Description
Whatever their size, computer systems consist same fundamental parts: CPU, devices, memory, program(s), timing reference (clock) shown Figure
PROGRAM
MEMORY
SWITCH INPUTS CENTRAL PROCESSOR UNIT (CPU) OUTPUTS
DISPLAY
KEYPAD
BEEPER
TEMPERATURE SENSOR
CLOCK RELAY
CRYSTAL
Figure Typical Computer System processes information accordance with program instructions data particular language called machine code. controls system operations provides control signals enabling disabling various peripherals devices. Input devices supply information from outside world. Some input devices convert analog signals into digital signals that understand manipulate. Other input devices translate real-world information into signals required MCUs. Examples this temperature sensor, switch, keypad, typewriter-style keyboard. computer system might have number these input devices.
M68HC05 Microcontroller Applications Guide Rev. General Description MOTOROLA
General Description Computer Systems Description
Output devices controlled signals from MCU. external interface required some output devices translate levels into different voltage current levels. Liquid crystal displays, video display terminals, heating/cooling equipment examples output devices. Memory store information, including instructions data that uses. basic memory types random access memory (RAM read-only memory (ROM). used temporary storage data instructions. computer system write information into read information from arbitrary random order. volatile that contents lost when power removed. data instructions program) stored permanently when manufactured. read information from cannot write information into information nonvolatile that does change even when power removed. programmable read-only memory (PROM) type that programmed user. erasable programmable read-only memory (EPROM) type PROM that erased exposing ultraviolet light. Once erased, EPROM reprogrammed with instructions data. OTPROM type EPROM that manufactured inexpensive plastic package. Since plastic package opaque ultraviolet light, OTPROM programmed only once. Like ROM, PROM, EPROM, OTPROM nonvolatile types memory. program contains instructions data. computer system uses program perform some desired processes. computer clock used timing sequencing various operations. crystal usually used provide reference frequency clock.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA General Description
General Description
Microcontroller Applications Overview
development microcontroller application limited only skill imagination, since elements microcontroller system easily assembled. applications generally allow many functions that make process control simpler more powerful, often reduced cost. Many applications require analog inputs outputs. resulting system equivalent traditional analog controller with number control loops. Control loops regulate output function more inputs. Control loops illustrated flowchart Figure
START CONTROL LOOP
HEATING SELECTED TURN HEATING
TEMP COLD TURN HEATING
TURN HEATING
COOLING SELECTED TURN COOLING
TEMP TURN COOLING
TURN COOLING
Figure Temperature Control Flowchart
M68HC05 Microcontroller Applications Guide Rev. General Description MOTOROLA
General Description Microcontroller Applications Overview
Some applications have costly sensors control mechanisms. cost sensors required input cost control devices required output usually much greater than cost standard MCU. advantage system software replace complex expensive hardware previously required. cost software tradeoff against cost additional hardware space requires. Programming allows complex functions that could easily accomplished with hard-wired devices. Changes functions made programs improved replaced with hardware changes.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA General Description
General Description
Project Description
basic thermostat controller chosen this project because should familiar readers because includes fundamental elements common applications. Figure illustrates home thermostat controller that control both heating conditioning.
DATA ENTRY KEYPAD
CRYSTAL
DISPLAY
INTERFACE
INDOOR TEMPERATURE SENSOR
MICROCONTROLLER
BEEPER
INTERFACE OUTDOOR TEMPERATURE SENSOR INTERFACE
RELAY
HEAT
RELAY
COOL
RELAY
Figure Thermostat Project Block Diagram Since thermostat based MCU, complex functions added. thermostat could include timed setback feature that allows specifying certain times when there will reduced demand heating conditioning, thus giving some energy savings. more unusual feature would measure outdoor temperature control indoor-to-outdoor temperature difference. This would very difficult accomplish with conventional electromechanical thermostat. four fundamental elements this system inputs, outputs, time, microcontroller other elements together. inputs include push-buttons keypad) enter time temperature
M68HC05 Microcontroller Applications Guide Rev. General Description MOTOROLA
General Description Project Description
information into sensors measure indoor outdoor temperatures. Outputs include display show system conditions signals interfaces that control heating conditioning equipment. Time derived from crystal connected MCU. will later, this crystal would used even application have time-of-day requirements, program controls entire operation thermostat. Applications page this manual contains project details.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA General Description
General Description
M68HC05 Microcontroller Applications Guide Rev. General Description MOTOROLA
Microcontroller Operation
Contents
Introduction Number Systems Computer Codes Computer Memory Computer Architecture Registers Memory Uses Memory Maps Timing Programming Flowchart Mnemonic Source Code Software Delay Program Assembler Listing View Program Operation Detailed Operation Instructions Store Accumulator (Direct Addressing Mode) Load Accumulator (Immediate Addressing Mode) Conditional Branch Subroutine Calls Returns Playing Computer On-Chip Peripherals Serial Communications Interface (SCI) Serial Peripheral Interface (SPI) 16-Bit Timer System Memory Peripherals Other On-Chip Peripherals
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Introduction
microcontroller unit (MCU) complete computer system single silicon chip. great many controller applications, satisfy system requirements with additional integrated circuits (ICs). very cost high degree flexibility, these powerful devices finding their into many applications that were previously accomplished with combinational logic even mechanical means. result, there many experienced engineers need become familiar with function application Motorola MCUs. This section, which specifically designed those engineers, also good reference engineers familiar with MCUs from some other manufacturer. block thermostat block diagram Figure page expanded shown Figure show functional blocks within MCU. block central element digital binary computer much like mainframe computers used business except that much smaller. goal this section study internal operation this interacts with other functional blocks within MCU. Although this discussion based relatively simple CPU, principles apply even most powerful mainframe computers. system simple logic elements buses that sequentially interpret execute finite instructions. Starting from specific address memory after reset, mindlessly fetches executes simple instruction after another. Each instruction composed several even simpler steps. small substeps comprising each instruction determined wiring within CPU. transistors, logic gates, buses which comprise called hardware. instructions follows accomplish application task determined user design engineer called software program. Before into discussion internal operations CPU, some basic concepts must understood. following paragraphs discuss numbering systems special codes used computers.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Introduction
CRYSTAL RESET
OSCILLATOR CLOCKS
CENTRAL PROCESSOR UNIT (CPU)
(POWER) (GROUND) ADDRESS
PROGRAM MEMORY DATA
DATA MEMORY
DIGITAL INPUTS
PERIPHERALS
DIGITAL OUTPUTS
Figure Expanded Block Diagram
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Number Systems
Computers work best with information different form than people use. Humans typically work base (decimal) numbering system (probably because have fingers). Digital binary computers work base (binary) numbering system because this allows information represented sets digits, which only zeros ones. turn, zero represented presence absence logic voltage signal line states simple switch. decimal (base numbers, weight each digit times great digit immediately right. rightmost digit decimal integer ones place, digit left tens digit, binary (base numbers, weight each digit times great digit immediately right. rightmost digit binary integer ones digit, next digit left twos digit, next fours digit, then eights digit, Although computers quite comfortable working with binary numbers even binary digits, humans find very inconvenient work with many digits time. base (hexadecimal) numbering system offers practical compromise. hexadecimal digit exactly represent four binary digits, thus, 8-bit binary number expressed hexadecimal digits. correspondence between hexadecimal digit four binary digits represents simple enough that humans work with computers easily learn mentally translate between two. hexadecimal (base numbers, weight each digit times great digit immediately right. rightmost digit hexadecimal integer ones place, digit left sixteens digit, Table demonstrates relationship between decimal, binary, hexadecimal representations values. These three different numbering systems just different ways represent same physical quantities.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Number Systems
Table Decimal, Binary Hexadecimal Equivalents
Base Decimal 1024 65,535 Base Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0001 0000 0001 0001 0110 0100 1111 1111 0100 0000 0000 1111 1111 1111 1111 Base Hexadecimal FFFF
letters through used represent hexadecimal values corresponding through because each hexadecimal digit represent different quantities; whereas, customary numbers only include unique symbols through Thus, some other single-digit symbols used represent hexadecimal values through avoid confusion about whether number decimal hexadecimal, hexadecimal numbers preceded symbol. example, means decimal "sixty-four"; whereas, means hexadecimal "six-four", which equivalent decimal 100. Some other computer manufacturers follow hexadecimal values with capital 64H).
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Hexadecimal good express discuss numeric information processed computers because easy people mentally convert between hexadecimal digits their 4-bit binary equivalent. hexadecimal notation much more compact than binary while maintaining binary connotations.
Computer Codes
Computers must handle many kinds information other than just numbers. Text (alphanumeric characters) instructions must encoded such that computer understand this information. most common code text information American Standard Code Information Interchange ASCII). ASCII code establishes widely accepted correlation between alphanumeric characters specific binary values. Using ASCII code, corresponds capital corresponds space character, etc. ASCII code translates characters 7-bit binary codes, practice information most often conveyed 8-bit characters with most significant equal zero. This standard code allows equipment made various manufacturers communicate because machines this same code. Computers another code give instructions CPU. This code called operation code opcode. Each opcode instructs execute very specific sequence steps that together accomplish intended operation. Computers from different manufacturers different sets opcodes because these opcodes internally hard-wired logic. instruction specific opcodes that knows execute. Even though opcodes differ from computer another, digital binary computers perform same kinds basic tasks similar ways. MC68HC05 understand basic instructions. Some these basic instructions have several slight variations, each requiring separate opcode. instruction MC68HC05 includes unique instruction opcodes. will discuss actually executes instructions little later this section after more basic concepts have been presented.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Computer Codes
opcode such understood CPU, very meaningful human. solve this problem, system mnemonic instruction formats used. opcode corresponds INCA mnemonic, which read "increment accumulator." Although there printed information show correlation between mnemonic instructions opcodes they represent, this information seldom used programmer because translation process automatically handled separate computer program called assembler. assembler program that converts program written mnemonics into list machine codes (opcodes) that used CPU. engineer develops instructions computer mnemonic form then uses assembler translate these instructions into opcodes that understand. will discuss instructions, writing programs, assemblers later this applications guide, should understand that people prepare instructions computer mnemonic form computer understands only opcodes; thus, translation step required change mnemonics opcodes, this function assembler. Before leaving this discussion number systems codes, will look additional codes have heard about. Octal (base notation used some early computer work seldom used today. Octal notation uses numbers through represent sets three binary digits same hexadecimal used represent sets four binary digits. octal system advantage using customary number symbols (unlike hexadecimal symbols through discussed earlier). disadvantages caused octal abandoned hexadecimal notation used today. First all, most computers bits word; these words break down nicely into sets three bits. (Some early computers used 12-bit words which break down into four sets three bits each.) second problem that octal compact hexadecimal. example, ASCII value capital 10000012 binary, 4116 hexadecimal, 1018 octal. When human talking about ASCII value easier "four-one" than "one-zero-one." When mentally translating from hexadecimal binary, easy convert each hexadecimal digit into
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
four binary bits. more difficult make octal-to-binary translation because have remember throw away leading zero first group three binary bits. probably think twice about that last statement, that exactly point. Binary coded decimal (BCD) hybrid notation used express decimal values binary form. uses four binary bits represent each decimal digit. Since four binary digits express different physical quantities there will bit-value combinations that considered invalid (specifically, hexadecimal values through F).Values kept pseudo-decimal form during calculations. When computer does operation, performs binary addition then adjusts result back form. simple example, consider addition 1010. computer adds 0000 10012 0000 00012 0000 10102, 10102 equivalent A16, which valid value. When computer finishes calculation, check performed result still valid value. there carry from digit another there invalid code, sequence steps would performed correct result proper form (0000 10102 corrected 0001 00002 (BCD this example). most cases, inefficient notation computer calculations. better change from decimal binary information entered, computer calculations binary, change binary result back decimal needed display. First, computers capable doing calculations because they need digit-to-digit carry indicator which present computers (though Motorola MCUs have this half-carry indicator). Secondly, forcing computer emulate human behavior inherently less efficient than allowing computer work native binary system.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Computer Memory
Computer Memory
Before operation discussed detail, some conceptual knowledge computer memory required. many beginning programming classes, memory presented being similar matrix pigeon holes where save messages other information. pigeon holes referring like mailboxes large apartment building. This good analogy needs little refinement used explain inner workings CPU. will confine discussion 8-bit that very specific. 8-bit CPU, each pigeon hole mailbox) thought containing eight on/off switches (eight bits data called byte data). Unlike pigeon hole, cannot more information writing smaller, there such thing empty pigeon hole (though contents memory location unknown undefined given time). switches would where each switch would represent single binary digit. binary corresponds switch being binary zero corresponds switch being off. Each pigeon hole (memory location) unique address that information stored reliably retrieved.
Computer Architecture
Motorola M68HC05 M68HC11 8-bit MCUs have specific organization which called Neumann architecture after American mathematician same name. this architecture, memory array interconnected address data bus. address used identify which pigeon hole being accessed, data used convey information either from memory location (pigeon hole) from memory location CPU. Motorola implementation this architecture, there special pigeon holes (called registers) inside CPU, which small scratch control panel CPU. These registers similar memory that information written into them
M68HC05 Microcontroller Applications Guide Rev.
MOTOROLA
Microcontroller Operation
Microcontroller Operation
remembered. However, important remember that these registers directly wired into part addressable memory available CPU. information (other than registers) accessible envisioned CPU) single several thousand pigeon holes. This organization sometimes called 'memory-mapped I/O' system because treats memory locations alike whether they contain program instructions, variable data, input-output (I/O) controls. There other computer architectures, this applications guide intended explore these variations. Fortunately, Motorola architecture discussing easiest understand use. This architecture encompasses most important concepts digital binary computers; thus, information presented this applications guide will applicable even study other architectures. number wires address determines total possible number pigeon holes; number wires data determines amount information that stored each pigeon hole. MC68HC705C8, address bits, making maximum 819210 separate pigeon holes jargon would this access locations). Since data MC68HC705C8 eight bits, each pigeon hole hold byte information. byte eight binary digits, hexadecimal digits, ASCII character, decimal value from 255.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Computer Memory
Registers
Different CPUs have different sets registers. differences primarily number size registers. Figure shows registers found M68HC05. While this relatively simple registers, representative types registers used explain fundamental concepts.
ACCUMULATOR INDEX REGISTER PROGRAM COUNTER CONDITION CODE REGISTER STACK POINTER
CARRY ZERO NEGATIVE INTERRUPT MASK HALF-CARRY (FROM
Figure M68HC05 Registers register, 8-bit scratch-pad register, also called accumulator because often used hold operands result arithmetic operation. register 8-bit index register, which also serve simple scratch pad. main purpose index register point area memory where will load (read) store (write) information. Sometimes index register called pointer register. will learn more about index registers when discuss indexed addressing modes. program counter (PC) register used keep track address next instruction executed. When reset (starts up), loaded from specific pair memory locations called reset vector. reset vector locations contain address first instruction executed CPU.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
instructions executed, logic increments such that always points next piece information that will need. number bits exactly matches number wires address bus. This determines total potentially available memory space that accessed CPU. case MC68HC705C8, bits long; therefore, access bytes (8192) memory. Values this register expressed four hexadecimal digits where upper-order three bits corresponding 16-bit binary address always zero. condition code (CC) register 8-bit register holding status indicators that reflect result some prior operation. three high-order bits this register used always stay logic one. Branch instructions these status bits make simple either decisions. stack pointer (SP) used pointer next available location last-in-first-out (LIFO) stack. stack thought pile cards, each holding single byte information. given time, card stack take card stack. Cards within stack cannot used unless cards piled removed first. accomplishes this stack effect points memory location (pigeon hole), which thought next available card. When pushes piece data onto stack, data value written into pigeon hole pointed then decremented points next previous memory location (pigeon hole). When pulls piece data stack, incremented points most recently used pigeon hole, data value read from that pigeon hole. When first started after reset stack pointer (RSP) instruction, points specific memory location certain pigeon hole).
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Computer Memory
Memory Uses
computer memory holds information needed computer instructions, variable data, even status controls. Some memory locations contain fixed data like instructions tables constant data. This information typically held read-only memory (ROM) although there special requirement that this information located ROM. second type information used computers variable information that changes often during operation system. This type data typically held read-write random-access memory (RAM). Information read from written various locations arbitrary random order. third type information found computer system status control information. This type memory location allows computer system information from outside world. This type memory location unusual because information sensed and, changed something other than CPU. simplest kind memory locations simple input port simple output port. 8-bit MCU, simple input port would consist eight pins that read CPU. simple output port would consist eight pins that control (write to). practice, simple output port location usually implemented with eight latches feedback paths that allow read back what previously written address output port. Figure shows equivalent circuit RAM, input port, typical output port having readback capability. real MCU, this circuit would repeated eight times make single 8-bit location, input port, output port. When stores value address that corresponds Figure (a), WRITE signal activated latch data from data line into flip-flop [1]. This latch static remembers value written until value written this location power removed). When reads address this bit, READ signal activated, which enables multiplexer [2]. This multiplexer couples data from output flip-flop into data line. real MCU, bits actually much simpler than shown here, they functionally equivalent this circuit.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
When reads address input port shown Figure (b), READ signal activated, which enables multiplexer [3]. multiplexer couples buffered data from onto data line. write this address would have meaning. When stores value address that corresponds output port Figure (c), WRITE signal activated latch data from data line into flip-flop [4]. output this latch, which buffered buffer driver [5], appears digital level output pin. When reads address this output port, READ signal activated, which enables multiplexer [6). This multiplexer couples data from output flip-flop onto data line.
READ
DATA (n=0, 1.OR WRITE
READ DATA (n=0, 1.OR
BUFFER DIGITAL INPUT
Input Port
READ
DATA (n=0, 1.OR WRITE
BUFFER DRIVER
DIGITAL OUTPUT
Output Port with Readback
Figure Memory Circuitry
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Computer Memory
Memory Maps
Since there several thousand memory locations system, important have convenient track locations. memory pictorial representation total memory space. Figure typical memory showing subset memory resources MC68HC705C8. Some memory areas (reserved Motorola use) were purposely left this figure make easier understand. complete version this memory found Figure page
$0000 $001F $0020
BYTES MOTOROLA BYTES INSET
$004F $0050 BYTES $00BF $00C0 STACK BYTES $00FF $0100
USER PROM 7680 BYTES
PORT DATA REGISTER PORT DATA REGISTER PORT DATA REGISTER PORT FIXED INPUT REGISTER PORT DATA DIRECTION REGISTER PORT DATA DIRECTION REGISTER PORT DATA DIRECTION REGISTER UNUSED UNUSED UNUSED CONTROL REGISTER STATUS REGISTER DATA REGISTER BAUD RATE REGISTER CONTROL REGISTER CONTROL REGISTER STATUS REGISTER DATA REGISTER TIMER CONTROL REGISTER TIMER STATUS REGISTER INPUT-CAPTURE REGISTER (HIGH) INPUT-CAPTURE REGISTER (LOW) OUTPUT-COMPARE REGISTER (HIGH) OUTPUT-COMPARE REGISTER (LOW) TIMER COUNT REGISTER (HIGH) TIMER COUNT REGISTER (LOW) ALT. COUNT REGISTER (HIGH) ALT. COUNT REGISTER (LOW) EPROM PROGRAM REGISTER RESET REGISTER CONTROL REGISTER UNUSED
$1EFF $1F00
MOTOROLA BYTES
$1FF3 $1FF4 $1FFF
USER PROM VECTORS BYTES
VECTOR (HIGH) VECTOR (LOW) VECTOR (HIGH) VECTOR (LOW) TIMER VECTOR (HIGH) TIMER VECTOR (LOW) VECTOR (HIGH) VECTOR (LOW) VECTOR (HIGH) VECTOR (LOW) RESET VECTOR (HIGH BYTE) RESET VECTOR (LOW BYTE)
$1FF4 $1FF5 $1FF6 $1FF7 $1FF8 $1FF9 $1FFA $1FFB $1FFC $1FFD $1FFE $1FFF
INSET PORT DATA DIRECTION REGISTER
DDRA7 DDRA6 DDRA5 DDRA4 DDRA3 DDRA2 DDRA1 DDRA0
Figure Typical Memory
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
four-digit hexadecimal values along left edge Figure addresses beginning with $0000 increasing $1FIFF bottom. $0000 corresponds first memory location selected (when drives address lines internal address logic zero). $1FFF corresponds last memory location selected (when drives address lines internal address logic one). labels within vertical rectangle identify what kind memory (RAM, PROM, registers, etc.) resides particular area memory. Some areas, such registers, need shown more detail because important know names each individual location. vertical rectangle interpreted 8192 pigeon holes (memory locations). Each these 8192 memory locations contains eight bits data shown inset Figure first memory locations ($0000-$00FF) accessed with direct addressing mode many instructions. this addressing mode, assumes that upper hexadecimal digits address always zeros; thus, only low-order digits address need explicitly given instruction. on-chip registers bytes located $0000-$00FF area memory. memory (Figure expansion area memory identifies each register location with low-order digits address rather than full four-digit address. example, two-digit hexadecimal value appears right port data register, which actually located address $0000 memory map. that have some background knowledge computer memory, continue with discussion CPU.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Timing
Timing
high-frequency clock source (typically derived from crystal connected MCU) used control sequencing instructions. Typical MCUs divide basic crystal frequency more arrive bus-rate clock. Each memory read write takes bus-rate clock cycle. case MC68HC705C8 MCU, 4-MHz (maximum) crystal oscillator clock divided arrive 2-MHz (maximum) internal processor clock. Each substep instruction takes cycle this internal processor clock (500 ns). Most instructions take five these substeps; thus, capable executing about 500,000 instructions every second.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Programming
this point, will write short program mnemonic form, translate into machine code, discuss would execute program. This exercise will provide insight into internal operation computers general. instruction explanations process writing programs will more understandable with this background. program will read state switch connected input pin. When switch closed, program will cause connected output light about second then out. will light again until switch been released closed again. length time switch held closed will affect length time lighted. Although this program very simple, demonstrates most common elements application program. First, demonstrates program sense input signals such switch closures. Second, this example program controlling output signal. Third, on-time about second demonstrates program used measure real time. Because algorithm sufficiently complicated, cannot accomplished trivial manner with discrete components minimum, one-shot with external timing components would required). This example demonstrates that user-defined program (software) replace complex circuits.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Programming
Flowchart
Figure flowchart example program. Flowcharts often used planning tool writing software programs because they show function flow program under development. importance notes, comments, documentation software cannot overemphasized. Just would consider circuit-board design complete until there schematic diagram, parts list, assembly drawing, should consider program complete until there commented listing comprehensive explanation program such flowchart.
FLOWCHART BEGIN
INITIAL CONDITIONS: PORT OUTPUTS DATA PATTERN 1110 0000 PORT
READ SWITCH
CLOSED DELAY DEBOUNCE
TURN
DELAY SECOND
TURN
SWITCH STILL CLOSED DELAY DEBOUNCE
Figure Example Flowchart
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Mnemonic Source Code Once flowchart plan completed, programmer develops series assembly language instructions accomplish functions called each block plan. programmer limited selecting instructions from instruction being used this case MC68HC05). programmer writes instructions mnemonic form which easy understand. Figure shows mnemonic source code next flowchart example program what instructions used accomplish each block flowchart. meanings mnemonics used right side Figure found Instruction Details page 245. During development program instructions, noticed that time delay needed three places. subroutine developed that would generate 50-ms delay. This subroutine used directly places (for switch debouncing) made one-second delay easier produce. keep this figure simple, comments that would usually included within source program documentation omitted. comments will shown complete assembly listing Figure
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Programming
FLOWCHART BEGIN
MNEMONIC PROGRAM
INITIAL CONDITIONS: PORT OUTPUTS DATA PATTERN 1110 0000 PORT
INIT
#$FF DDRC #$E0 PORTC
READ SWITCH
PORTB
CLOSED DELAY DEBOUNCE
DLY50
TURN
BCLR
PORTC
DELAY SECOND
DLYLP
DECA BSET
DLY50 DLYLP PORTC
TURN
SWITCH STILL CLOSED DELAY DEBOUNCE
OFFLP
BRSET
PORTB, OFFLP
DLY50
Figure Flowchart Mnemonics
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Software Delay Program Figure shows expanded flowchart 50-ms delay subroutine. subroutine relatively small program which performs some commonly required function. Even function needs performed many times course program, subroutine only written once. Each place where this function needed, programmer would call subroutine with branch-to-subroutine (BSR) jump-to-subroutine (JSR) instruction.
FLOWCHART START SUBROUTINE
MNEMONIC PROGRAM
INSTRUCTION TIME (CYCLES) (JSR)
SAVE ACCUMULATOR
DLY50
TEMP1
LOAD VALUE CORRESPONDING 50mS OUTLP DECREMENT COUNT INNRLP
CLRX DECX DECA
INNRLP
COUNT EXPIRED RESTORE ACCUMULATOR
OUTLP
TEMP1
RETURN FROM SUBROUTINE
INNRLP executed times each pass through outer loop. OUTLP executed times.
Figure Delay Routine Flowchart Mnemonics
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Programming
Before starting execute instructions subroutine, address instruction which follows BSR) automatically stored temporary memory locations. When finishes executing instructions within subroutine, return-from-subroutine (RTS) instruction performed last instruction subroutine. instruction causes recover previously saved return address; thus, continues program with instruction following BSR) instruction that originally called subroutine. delay routine Figure involves inner loop (INNRLP) within another loop (OUTLP). inner loop consists instructions executed times before reaches branch condition fails. This amounts cycles µs/cycle times 256, which equals 1.536 inner loop. outer loop executes times. total execution time outer loop 32(1536 32(1545) 49.44 miscellaneous instructions this routine other than those outer loop total cycles; thus, total time required execute DLY50 routine 49.461 including time required instruction that calls DLY50. 16-bit timer system MC68HC705C8 also used measure time. timer-based approach actually preferred because perform other tasks during delay, delay time dependent exact number instructions executed DLY50.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Assembler Listing After complete program subprogram written, must converted from mnemonics into binary machine code that later execute. separate computer system, such used perform this conversion machine language. computer program called assembler used. assembler reads mnemonic version program (also called source version program) produces machine-code version program form that programmed into memory MCU. assembler also produces composite listing showing both original source program (mnemonics) object code translation. This listing used during debug phase project part documentation software program. Figure shows listing which results from assembling example program. Comments were added before program assembled. Applications page should thoroughly studied before attempting sample programs this guide. Some sample programs were developed another member M68HC05 Family which slightly different memory than MC68HC705C8. Minor modifications necessary successfully these programs MC68HC705C8. Refer Figure following discussion. This figure shows some lines listing with reference numbers indicating various parts line. first line example assembler directive line. This line really part program; rather, provides information assembler that real program converted properly into binary machine code.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Programming
Simple 68HC05 Program Example Read connected bit-7 port closed When closes, light about Sec; when port wait release, then repeat. Debounce 50ms 0001 0002 0005 0006 009f 00a0 PORTB PORTC DDRB DDRC TEMP1 Direct address port (sw) Direct address port (LED) Data direction control, port Data direction control, port byte temp storage location Program will start $00A0
$00A0 '705C8 INIT
00a0 00a2 00a4 00a6
00a8 00aa 00ac 00af 00bl 00b3 00b6 00b7 00b9 00bb 00be 00cl
#$FF Begin initialization DDRC port outputs Port configured inputs default from reset. #$E0 green LEDs beeper PORTC Turn Some pins port board) happen connected devices which don't apply this example program. pattern turns stuff turns BCLR DECA BSET BRSET PORTB DLY50 6,PORTC DLY50 DLYLP 6,PORTC 7,PORTB,OFFLP DLY50 Read Port Loop till (Neg trick) Delay about debounce Turn (bit-6 zero) Decimal assembles Delay Loop counter loops times (20-19,19-18-1-0) Turn back Loop here till. Debounce release Look next closure
DLYLP
OFFLP
00c3 00c5 00c7 00c8 00c9 00cb 00cc 00ce 00d0
DLY50-Subroutine delay '-50ms Saves original accumulator value will always zero return DLY50 TEMP1 Save accumulator outer loop times OUTLP CLRX used inner loop count INNRLP DECX O-FF, FF-FE,.1-0 loops INNRLP 6cyc*256*1 µS/cyc 1.536ms DECA 32-31, 31-30,.1-0 OUTLP 1545cyc*32*1 µS/cyc 49.440ms TEMP1 Recover saved Accumulator Return
Figure Assembler Listing
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
0001 00a0 00a8 -[1] PORTB -[3] -[4] PORTB -[5] Direct address port (sw) Program will start $00A0 Read Port -[6]->
Figure Explanation Assembler Listing EQU, short equate, used give specific memory location binary number name which then used other program instructions. this case, directive being used assign name PORTB value $01, which address port MC68HC705C8. easier programmer remember mnemonic name PCRTB rather than anonymous numeric value $01. When assembler encounters these names, name automatically converted corresponding binary value much same that instruction mnemonics converted into binary instruction codes. second line shown Figure another assembler directive. mnemonic ORG, which short originate, tells assembler where program will start (the address start first instruction following directive line). directives used more than once program tell assembler different parts program specific places memory. Refer memory select appropriate memory location where program should start. this assembler listing, first fields, (2], generated assembler, last four fields, [3], [4], [5], [6], original source program written programmer. Field label (TOP) which referred other instructions. example program, last instruction "BRA TOP", which simply means will continue execution with instruction that labeled "TOP". When programmer writing program, addresses where instructions will located typically known. Worse yet, branch instructions, rather than using address destination, uses offset (difference) between current value destination address. Fortunately, programmer does have
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Programming
worry about these problems because assembler takes care these details through system labels. This system labels convenient programmer identify specific points program (without knowing their exact addresses); assembler later convert these mnemonic labels into specific memory addresses even calculate offsets branch instructions that them. Field instruction field. mnemonic short load accumulator. Since there variations (different opcodes) load accumulator instruction, additional information required before assembler choose correct binary opcode during execution program. Field operand field, providing information about specific memory location value operated instruction. assembler uses both instruction mnemonic operand specified source program determine specific opcode instruction. different ways specifying value operated called addressing modes more complete discussion addressing modes presented later). syntax operand field slightly different each addressing mode assembler determine correct intended addressing mode from syntax operand. this case, operand PORTB, which assembler automatically converts (recall directive). assembler interprets direct addressing mode address between $0000 $00FF, thus selecting opcode $136, which direct addressing mode variation LIDA instruction. PCRTB been preceded symbol, that syntax would have been interpreted assembler immediate addressing mode value, opcode would have been chosen instead $B6. Field called comment field used assembler translate program into machine code. Rather, comment field used programmer document program. Although does this information during program execution, good programmer knows that most important parts good program. comment this line program says "read port This comment tells someone reading listing port being read, which essential understanding
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
program works. entire line made into comment line using asterisk first character line. addition good comments listing, also important document programs with aflowchartorothercletailed information explaining overall flow operation program.
View Program
Figure memory MC68HC705C8, shows example program fits memory MCU. This figure same Figure except that different portion memory space been expanded show contents locations program. Figure shows that sees example program linear sequence binary codes, including instructions operands successive memory locations. begins this program with program counter (PC) pointing first byte program. Each instruction opcode tells many any) what type operands with that instruction. this way, remain aligned instruction boundaries even though mixture opcodes operands looks confusing Most application programs would located ROM, EPROM, OTPROM. This example program loaded into area avoid having program (and later erase) EPROM. There special requirement that instruction must ROM-type memory execute. concerned, program just series binary patterns which sequentially processed. Carefully study program listing Figure memory Figure Find first instruction DLY50 subroutine Figure then find same bytes Figure should have found following line from near bottom Figure
00c3 DLY50 TEMP1 Save accumulator
outlined section memory Figure area should have identified.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Programming
$0000 $001F $0020
BYTES MOTOROLA BYTES
$004F $0050 BYTES EXAMPLE PROGRAM
$009F $00A0
$00FF $0100
USER PROM 7680 BYTES
$1EFF $1F00
MOTOROLA BYTES
$1FF3 $1FF4 $1FFF
USER PROM VECTORS BYTES
$00A0 $00A1 $00A2 $00A3 $00A4 $00A5 $00A6 $00A7 $00A8 $00A9 $00AA $00AB $00AC $00AD $00AE $00AF $00B0 $00B1 $00B2 $00B3 $00B4 $00B5 $00B6 $00B7 $00B8 $00B9 $00BA $00BB $00BC $00BD $00BE $00BF $00C0 $00C1 $00C2 $00C3 $00C4 $00C5 $00C6 $00C7 $00C8 $00C9 $00CA $00CB $00CC $00CD $00CE $00CF $00D0
$00C3 $00C4
Figure Memory Example Program
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Operation
This section will first discuss detailed operation instructions then explain would execute example program. detailed descriptions typical instructions intended make think like CPU. then through example program using teaching technique called 'playing computer' which pretend interpreting executing instructions program.
Detailed Operation Instructions
Before seeing would execute example program, would help know detail) breaks down instructions into fundamental operations performs these tiny steps accomplish desired instruction. will see, many small steps execute very quickly very accurately within each instruction, none small steps very complicated. logic circuitry inside would seem straightforward design engineer accustomed working with logic even relay logic. What sets apart from these other forms digital logic packing density. Very large scale integration (VLSI) techniques have made possible equivalent thousands integrated circuits single silicon die. arranging these logic gates form CPU, general-purpose instruction executer capable acting universal logic element. placing different combinations instructions device, perform virtually definable function. typical instruction takes five cycles internal processor clock. Although normally important know exactly what happens during each these execution cycles, help through instructions detail understand works internally.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Operation
Store Accumulator (Direct Addressing Mode)
Look instruction Instruction Details. table bottom page, that direct addressing mode version store accumulator instruction. also that instruction requires bytes, specify opcode ($B7) second specify direct address where accumulator will stored. (The bytes shown machine code column table.) will discussing addressing modes more detail later, following brief description will help understanding executes this instruction. direct addressing modes, assumes address range $0000 through $00IFF; thus, there need include upper byte address operand instruction (since always $00). table bottom description found page shows that direct addressing version instruction takes four cycles execute. During first cycle this instruction, reads opcode $B7, which identifies instruction direct addressing version instruction advances next memory location. During second cycle, places value from internal address reads low-order byte direct address ($02 example). uses third cycle this instruction internally construct full address where accumulator stored, also advances points next address memory (the address opcode next instruction). this example, appends assumed value (because direct addressing mode) that read during second cycle instruction arrive complete address $0002. During fourth cycle this instruction, places this constructed address ($0002) internal address bus, places accumulator value internal data bus, asserts write signal. That writes contents accumulator $0002 during fourth cycle instruction.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
This explanation left certain details, such setting condition code flags, gives idea what occurs within during execution single instruction. Load Accumulator (Immediate Addressing Mode) Next, look instruction Instruction Details. immediate addressing mode version this instruction appears machine code column table bottom page. This version instruction takes internal processor clock cycles execute. opcode tells byte data that immediately follows opcode this value accumulator. During first cycle this instruction, reads opcode advances point next location memory (the address immediate operand ii). During second cycle instruction, reads contents byte following opcode into accumulator advances point next location memory (i.e., opcode byte next instruction). While accumulator being loaded, bits condition code register were cleared according data that loaded into accumulator. boolean logic formulae these bits appears near middle instruction page. will value loaded into accumulator $00; otherwise, will cleared. will most significant value loaded logic one; otherwise, will cleared. (negative) condition code used detect sign tows-complement number. twos-complement numbers, most significant used sign bit, indicates negative value, zero indicates positive value. also used simple indication state most significant binary value. Conditional Branch Branch instructions allow select program flow paths, depending upon state particular memory various condition code bits. condition checked branch instruction true, program flow proceeds specified location memory. condition checked branch true, proceeds
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Operation
instruction following branch instruction. Decision blocks flowchart correspond conditional branch instructions program. Most branch instructions contain bytes, opcode relative offset byte. Branch clear (BRCLR) branch (BRSET) instructions require three bytes: opcode, one-byte direct address specify memory location tested), relative offset byte. relative offset byte interpreted twos-complement signed value. branch condition checked true, this signed offset added reads next instruction from this calculated address. branch condition true, just continues next instruction after branch instruction. following excerpt from Figure demonstrates useful conditional branch based condition code that sometimes overlooked.
00a8 00aa 00ac PORTB DLY50 Read Port Loop till (Neg trick) Delay about debounce
first line means "load accumulator with value port MCU." most significant this port connected normally opened switch pulldown resistor. When switch pressed (closed), logic applied port pin. PCRTB instruction executed when switch opened, condition code will cleared. Conversely, PORTB instruction executed when switch closed, condition code will set. second line listing (BPL TOP) read "branch plus TOP." response this instruction, either branches back first line this program falls third line program, depending condition condition code bit. condition code clear, branches first line program. This corresponds interpreting value previously read from port positive value; hence, instruction name "branch plus."
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
Tricks such that just described only read respond conditions. following lines code would accomplish same effect three lines which used N-bit trick.
00a8 00ab BRCLR PORTB, DLY50 Loop till closed Delay about debounce
first line this sequence read "branch port clear." this particular case, second sequence better than first sequence several reasons. second sequence more straightforward (less chance confusion), takes less byte machine code, executes cycle faster than three-line sequence. However, some cases operand (PORTB) needed accumulator some other reason; thus, first instruction sequence based N-bit trick becomes slightly better choice. From practical point view, differences between these approaches very small, either would work well application. Subroutine Calls Returns jump-to-subroutine (JSR) branch-to-subroutine (BSR) instructions automate process leaving normal linear flow program execute instructions then return where normal flow left off. instructions outside normal program flow called subroutine. instruction used from running program subroutine return-from-subroutine (RTS) instruction used return program from which subroutine called. following shows lines assembler listing which will used demonstrate executes subroutine call. Assume that stack pointer (SP) points address $00FF when encounters instruction location $0102.
0100 0102 0105 0201 0203 DECA #$02 SUBBY SUBBY Load immediate value subroutine Store accumulator port Decrement accumulator Loop till accumulator Return from subroutine
SUBBY
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Operation
Refer Figure during following discussion. will begin explanation with executing instruction "LDA #$02" address $0100. left side figure shows normal program flow composed LIDA #$20, SUBBY, that order) consecutive memory locations. right half figure shows subroutine instructions SUBBY DECA, SUBBY, RTS. Each number square brackets indicates cycle internal processor clock. cycle numbers will used references following explanation this figure.
START
$0100 #$02 $0101 $0102 SUBBY $0103 $0104
[27] [28] [29] [30]
[15] [16] [17] [18] [19] [20]
[10] [11] [12] [13] [14] [21] [22] [23] [24] [25] [26]
$0200
SUBBY
DECA
$0201 $0202 $0203 SUBBY
$0105 $0106
Figure Subroutine Call Sequence reads opcode from location $0100 (LIDA immediate). reads immediate data from location $0101 into accumulator. reads opcode from location $0102 (JSR extended) reads high-order extended address from $0103.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
reads low-order extended address from $0104. builds full address subroutine ($0200). writes $00FF decrements $00FE. Another this "push low-order half return address stack." writes $00FE decrements $00FD. Another this "push high-order half return address stack." return address that saved stack $0105, which address instruction that follows instruction. reads opcode from location $0200. This first instruction called subroutine. DECA instruction takes three cycles ([9], [10], [11]). reads opcode ($26) from location $0201. reads relative offset ($FD) from $0202. During #$02 instruction [1], accumulator loaded with value during DECA instruction [9], accumulator decremented (which equal zero). Thus, [14] branch condition true, twos-complement offset ($FD added internal (which $0203 time) value $0200.
[10] [11] [12] [13] [14]
[15] [19] Repeat cycles through [13] except that when DECA instruction [15] executed this time, accumulator went from $00. [20] Since accumulator "equal zero," [19] branch condition true, branch will taken. reads opcode ($81) from $0203.
[21]
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Operation
[22] [26] takes cycles. During last five cycles this instruction, incremented $00FE, high-order return address ($01) read from stack ($00FE), incremented again $00FF, low-order return address ($05) read from stack ($00FF), loaded with this recovered return address ($0105). [27] reads direct opcode ($B7) from location $0105. reads low-order direct address ($02) from location $0106. direct instruction takes total four cycles. During these last cycles instruction, constructs complete address where accumulator will stored appending (assumed value high-order half address direct addressing mode) read during [28]. accumulator ($00 this time) then stored this constructed address ($0002).
[28]
[29] [30]
Playing Computer
Playing computer learning exercise where pretend that executing program. Programmers often mentally check programs playing computer they read through software routine. While playing computer, necessary break instructions down individual processor cycles. Instead, instructions treated single complete operation rather than several detailed steps. following paragraphs demonstrate process playing computer going through subroutine-call exercise Figure playing-computer approach analyzing this sequence much less detailed than cycle-by-cycle analysis done earlier Figure accomplishes same basic goal i.e., shows what happens executes sequence. After seeing this exercise, should attempt same thing with larger program such example Figure begin process preparing worksheet like that shown Figure This sheet includes mnemonic program machine
M68HC05 Microcontroller Applications Guide Rev.
MOTOROLA
Microcontroller Operation
Microcontroller Operation
code that assembles (You could alternately choose listing positioned next worksheet.) worksheet also includes register names across sheet with ample room below write values registers change course program. this worksheet, there area keeping track stack. After become comfortable with stack works, would probably leave this section off, will instructive leave here now. value saved stack, will cross prior value write value right horizontal row. must also update (decrement) value crossing prior value writing value beneath under heading worksheet. value recovered from stack, would update (increment) value crossing value writing value below would then read value from location pointed wherever belongs (e.g., upper lower half PC).
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Operation
STACK POINTER
ACCUMULATOR
CONDITION CODES
INDEX REGISTER
PROGRAM COUNTER
$00FC $00FD $00FE $00FF
0100 0102 0105 0200 0201 0203
INED EXAM ISTIN
SUBBY SUBBY
DECA
#$02 SUBBY
LOAD IMMEDIATE VALUE SUBROUTINE STORE ACCUMULATOR PORT DECREMENTACCUMULATOR LOOP TILL ACCUMULATOR RETURN FROM SUBROUTINE
Figure Playing Computer Worksheet Figure shows worksheet will look after working through whole sequence. Follow numbers square brackets process explained. During process, many values were written later crossed out; line been drawn from square bracket either value crossed mark show which item reference number applies Beginning sequence, should pointing $0100 [1], should pointing $00FF (due earlier assumption). reads executes #$02 instruction (load accumulator with immediate value $02); thus, write accumulator column replace value with $0102, which address next instruction. load accumulator instruction affects bits. Since value loaded $02, would cleared, would cleared [5]. This information found Appendix Since other bits affected
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
LIDA instruction, have knowing what they should this time, question marks unknown positions [5].
STACK POINTER $00FF $00FE $00FD [18] $00FE [19] $00FF
ACCUMULATOR [11] [14]
CONDITION CODES [15]
INDEX REGISTER
PROGRAM COUNTER $0100 $0102 [10] $0200 [12] $0201 [13] $0200 [16] $0201 [17] $0203 [20] $0105
$0002 PORT [21] $00FC $00FD $00FE $00FF
0100 0102 0105 0200 0201 0203
SUBBY
DECA
#$02 SUBBY SUBBY
LOAD IMMEDIATE VALUE SUBROUTINE STORE ACCUMULATOR PORT DECREMENTACCUMULATOR LOOP TILL ACCUMULATOR RETURN FROM SUBROUTINE
Figure Completed Worksheet Next, reads SUBBY instruction. Temporarily remember value $0105, which address where should come back after executing called subroutine. saves low-order half return address stack; thus, write location pointed ($00FF) decrement $00FE. then saves high-order half return address stack; write $00FE again decrement (this time $00FD). finish the-SR instruction, load with $0200 [10], which address called subroutine. fetches next instruction. Since $0200, executes DECA instruction, first instruction subroutine.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation Operation
cross accumulator column write value [11]. also change $0201 [12]. Because DECA instruction changed accumulator from (which zero negative), remain clear. Since were already cleared [5], leave them alone worksheet. executes SUBBY instruction. Since clear, branch condition met, will take branch. Cross $0201 under write $0200 [13]. again executes DECA instruction. accumulator changed from [14] (which zero negative); thus, set, remains clear [15]. advances next instruction [16]. executes SUBBY instruction, this time branch condition true now), branch will taken. simply falls next instruction (the $0203). Update $0203 [17]. instruction causes recover previously stacked Pull high-order half from stack incrementing $00FE [18] reading from location $00FE. Next, pull low-order half address from stack incrementing $00FF [19] reading from $00FF. address recovered from stack replaces value [20]. reads instruction from location $0105. Program flow returned main program sequence where left when subroutine called. (direct addressing mode) instruction writes accumulator value direct address ($0002), which port MC68HC705C8. from worksheet that current value accumulator $00; therefore, eight pins port would driven (provided they configured outputs this time). Since original worksheet have place marked recording value port would make place write there [21]. larger program, worksheet would have many more crossed values time done. Playing computer worksheet like
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
this good learning exercise, but, programmer gains experience, process would simplified. first simplifications would quit keeping track because learn trust take care this you. Another simplification worksheet stop keeping track condition codes. When branch instruction which depends condition code encountered, mentally work backwards decide whether branch should taken. Next, storage values stack would skipped, although still good idea keep track value because fairly common have programming errors resulting from incorrect values fundamental operating principle stack that over period time, same number items must removed from stack were stack. Just left parentheses must matched with right parentheses mathematical formula, JSRs BSRs must matched subsequent RTSs program. Errors which cause this rule broken will appear erroneous values while playing computer. Even experienced programmer will play computer occasionally solve some difficult problem. procedure experienced programmer would much less formal than what explained here, still amounts placing yourself role working what happens program executed.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation On-Chip Peripherals
On-Chip Peripherals
peripheral block circuitry which performs some useful function under control CPU. example peripheral universal asynchronous receiver/transmitter (UART), which acts interface between computer asynchronous serial communication link. most common example such communication link RS-232 RS-422 serial port computer. This standard universal that almost every personal mainframe computer made anywhere world least such port. Before developed, computer designer separate UART integrated circuit include this serial interface function computer. Often number other miscellaneous logic gates were also needed interface UART buses. Since level integration allows thousands logic gates included single integrated circuit, practical several peripherals, including this UART function, same chip along with memories. on-chip serial communications interface (SCI) MC68HC705C8 UART-type peripheral. important manufacturer select peripheral functions that will useful many potential users inclusion chip. This pressure make on-chip peripherals satisfy requirements many customers possible causes need user-selectable options modify operation on-chip peripherals. MC68HC705C8 control registers, which allow user select which parallel pins will inputs which will outputs. Although application likely need only specific mixture inputs outputs, twenty different applications likely need dozen collective mixtures. ability specify direction each time makes this ideal many different applications. Control registers controlled essentially same digital output port. could think control/status registers internal registers connected internal logic rather than pins. change voltage level output pin, writes digital
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA Microcontroller Operation
Microcontroller Operation
value address output port register. level each output port register controls voltage level corresponding pin. case control register, state control register determines logic level internal control signal rather than pin. MC68HC705C8 Functional Data page this applications guide, will find more complete descriptions on-chip peripherals MC68HC705C8.
Serial Communications Interface (SCI)
system MC68HC705C8 UART-type asynchronous serial communications interface. most common this peripheral implement RS-232 interface host computer system (such personal computer). system used communicate over relatively long distances. normal applications, simply writes data parallel data register send formatted serial character. peripheral system takes care details transforming data into proper serial format, including addition start stop bits required meet standards. transmitter even allows characters queued transmission, thus allowing more time prepare additional characters receiver portion automatically detects start character intelligently samples incoming serial data assure correct reception, even noisy applications. activity related receiving serial data converting parallel data performed within peripheral logic with intervention CPU. After character received, simply reads data byte from receive data register. number options offered allow various data rates (baud rates), alternate character formats, automatic standby /wakeup feature. choose between software polling interrupts detection status.
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
Microcontroller Operation On-Chip Peripherals
Serial Peripheral Interface (SPI)
system MC68HC705C8 separate from system used primarily communications with standard peripheral logic chips same circuit board MCU. examples chips that serial-to-parallel parallel-to-serial shift registers, peripherals, peripherals, many others. system works like distributed 16-bit shift register which half shifter (SPI), other half peripheral. When initiates transfer, this distributed shifter rotated eight positions that data master effectively exchanged with data peripheral slave. some cases, loop incomplete, data transferred only from peripheral from peripheral MCU. system typically consists master more slave peripherals. Other configurations such MCUs multiple master systems possible less common. system includes options select shift rate, master slave mode, clock polarity, phase allow compatibility with most synchronous serial peripheral devices from many manufacturers.
16-Bit Timer System
MC68HC705C8 includes 16-bit timer system used measure time produce signals specific period frequency. This system based free-running 16-bit counter, 16-bit output-compare register 16-bit input-capture register. controls timing output signals through output-compare mechanism. schedule output change occur specific time specific count free-running counter), 16-bit value corresponding desired time written output-compare register. When free-running counter matches value output-compare register, planned output change occurs. detects time event measures period input signal with input-capture mechanism. select either positive negative edges detected trigger input-capture mechanism. When selected edge occurs, current value free-running counter (which corresponds time
M68HC05 Microcontroller Applications Guide Rev.
MOTOROLA
Microcontroller Operation
Microcontroller Operation
edge occurred), captured (transferred input-capture register. later read value input-capture register determine exact time when edge occurred.
Memory Peripherals
Memory systems also form peripheral. uses different types memory were discussed earlier, logic required support these memories discussed. memories very straightforward require support logic other than address-select logic distinguish location from another. EPROM (erasable programmable ROM) EEPROM (electrically erasable programmable ROM) memories require support logic programming (and erasure case EEPROM). peripheral support logic MC68HC705C8 like having PROM programmer built into MCU. control register includes control bits select between programming normal modes enable high-voltage programming supply.
Other On-Chip Peripherals
There many other peripherals available MCUs (see other members M68HC05 Family MCUs). These other peripherals include analog-to-digital (A/D) converters, liquid crystal display drivers (LCD), vacuum fluorescent display drivers (VFD).
M68HC05 Microcontroller Applications Guide Rev. Microcontroller Operation MOTOROLA
MC68HC705C8 Functional Data
Contents
Introduction Description Hardware Features Software Features General Description Pins Connections Functions (Maskable Interrupt Request) RESET TCAP TCMP OSC1 OSC2 PA7-PA0 PB7-PB0 PC7-PC0 PD5-PD0 Typical Basic Connections On-Chip Memory Memory Types Memory Central Processor Unit Registers Accumulator Index Register Condition Code Register Program Counter Stack Pointer Arithmetic/Logic Unit (ALU)
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Control Resets Power-On RESET Computer Operating Properly (COP) Watchdog Timer RESET .101 Clock Monitor RESET .103 Addressing Modes .104 Inherent Addressing Mode .105 Immediate Addressing Mode .107 Extended Addressing Mode .109 Direct Addressing Mode .111 Indexed Addressing Modes .113 Indexed, Offset .113 Indexed, 8-Bit Offset .115 Indexed, 16-Bit Offset .117 Relative Addressing Mode .119 Test Branch Instructions .121 Instructions Organized Type .121 Instruction Summary .126 Interrupts .134 Software Interrupt (SWI) .135 External Interrupt .137 Timer Interrupt .137 Serial Communications Interface (SCI) Interrupt .138 Serial Peripheral Interface (SPI Interrupt .138 Microcontroller Input/Output .139 Parallel .139 Serial .142 Serial Communications Interface (SCI) .143 Transmitter .144 Receiver .146 Registers .148 Baud Rate Register (BAUD) .148 Serial Communications Control Register (SCCR1) .151 Serial Communications Control Register (SCCR2) .152 Serial Communications STATUS Register (SCSR) .153 Serial Communications Data Register (SCDAT) .154 Data Formats .155 Hardware Procedures .155
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Contents
Software Procedures .156 Initialization Procedure .156 Normal Transmit Operation .157 Normal Receive Operation .157 Application Example .158 Synchronous Serial Peripheral Interface (SPI) .161 Data Movement .163 Functional Description .164 Descriptions .164 Serial Data Pins (MISO, MOSI) .164 Serial Clock (SCK) .165 Slave Select (SS) .165 Registers .166 Serial Peripheral Control Register (SPCR) .166 Serial Peripheral Status Register (SPSR) .168 Serial Peripheral Data Register (SPDR) .169 Application Example .170 Programmable Timer .173 Functional Description .176 Timer Counter Alternate Counter Registers .178 Input-Capture Concept .179 Input-Capture Operation .180 Output-Compare Concept .182 Output-Compare Operation .184 Timer Control Register (TCR) .185 Timer Status Register (TSR) .186 Timer Application Example .187 STOP/WAIT Instruction Effects .187 Power-Consumption Modes .187 Effects On-Chip Peripherals .190 Timer Action During STOP Mode .190 Action During STOP Mode .190 Action During STOP Mode .190 Wait Mode Effects .191 OTPROM/EPROM Programming .192 Erasing .192 Programming .192 Program Register .193 Option Register .194
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Introduction
MC68HC705C8 microcontroller (MCU) member M68HC05 Family low-cost, single-chip microcontrollers. HCMCS technology used MC68HC705C8 combines smaller size higher speeds with power high noise immunity CMOS. additional advantage CMOS that circuitry fully static. CMOS microcontrollers operated clock rate less than guaranteed maximum. This feature used conserve power since power consumption increases with higher clock frequencies. Static operation also advantageous during product development. software-controlled power-saving modes, WAIT STOP, available conserve additional power. These modes make MC68HC705C8 especially attractive automotive battery-driven applications.
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Description
Description
hardware software highlights MC68HC705C8 shown following subsections.
Hardware Features
HCMOS Technology 8-Bit Architecture Power-Saving Stop, Wait, Data Retention Modes Bidirectional Lines Input-Only Lines Timer Pins Internal Operating Frequency, Volts; MHz, Volts Internal 16-Bit Timer Serial Communications Interface (SCI) System Serial Peripheral Interface (SPI) System Ultraviolet (UV) light EPROM One-Time Programmable (OTPROM) Selectable Memory Configurations Computer Operating Properly (COP) Watchdog System Clock Monitor On-Chip Bootstrap Firmware Programming Software-Programmable External Interrupt Sensitivity External Pin, Timer, SCI, Interrupts Master Reset Power-On Reset Single 3-to 6-Volt Supply (2-Volt Data Retention Mode) On-Chip Oscillator 40-Pin Dual-in-Line Package 44-Lead PLCC (Plastic Leaded Chip Carrier) Package
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Software Features Upward Software Compatible with M146805 CMOS Family Efficient Instruction Versatile Interrupt Handling True Manipulation Addressing Modes with Indexed Addressing Tables Memory-Mapped Power-Saving Standby Modes
General Description
Figure shows MC68HC705C8 block diagram. central processor unit (CPU) contains 8-bit arithmetic logic unit, accumulator, index register, condition code register, stack pointer, program counter, control logic. Major peripheral functions provided on-chip. On-chip memory systems include bootstrap read-only memory (ROM), programmable (EPROM OTPROM), random-access memory (RAM). On-chip devices include asynchronous serial communications interface (SCI), separate serial peripheral interface (SPI), 16-bit programmable timer system. Self-monitoring circuitry included on-chip protect against system errors. computer operating properly (COP) watchdog system protects against software failures. clock monitor system generates system reset clock lost runs slow. illegal opcode detection circuit provides non-maskable interrupt illegal opcode detected.
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Description
DATA DIRECTION
EPROM PROGRAMMING CONTROL
PROGRAM REGISTER
EPROM/OTPROM 7744 BYTES (144 BYTES CONFIGURABLE)
DATA DIRECTION DATA DIRECTION
OPTION REGISTER
BYTES BYTES)
BOOT BYTES
RESET
CONTROL
ARITHMETIC LOGIC UNIT (ALU) M68HC05
REGISTERS
ACCUMULATOR INDEX REGISTER
STACK POINTER PROGRAM COUNTER OSC1 OSCILLATOR OSC2 DIVIDE CONDITION CODES PORT
PORT
PORT
PORT
WATCHDOG CLOCK MONITOR
BAUD RATE GENERATOR
TCMP POWER TIMER SYSTEM TCAP
Figure MC68HC705C8 Microcontroller Block Diagram
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Pins Connections
following paragraphs discuss assignments, functions, basic connections. Because MC68HC705C8 CMOS device, unused input pins must terminated avoid oscillation, noise, added supply current. preferred method terminating pins that configured input output with individual pullup pulldown resistors each unused pin. assignments shown Figure Figure Mechanical data ordering information found BR594/D, MC68HC705C8 Technical Summary, available separately.
Functions
following subsections provide description functions. Power supplied using these pins. power ground. operate from single 5-volt (nominal) power supply. used when programming one-time programmable (OTPROM) EPROM. Programming voltage (14.75 Vdc) applied this when programming PROM. Normally, this connected VDD.
CAUTION:
connect (GND). will damage MCU.
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Pins Connections
(Maskable Interrupt Request)
software programmable option which provides different choices interrupt triggering sensitivity. These options negative edge-sensitive triggering only, both negative edge-sensitive level-sensitive triggering. latter case, either negative edge level input will produce interrupt. completes current instruction before responds interrupt request. When goes low, small synchronization delay occurs, logic latched internally signify interrupt been requested. When completes current instruction, interrupt latch tested. interrupt latch contains logic interrupt mask bit) condition code register clear, then begins interrupt sequence.
RESET
OSC1 OSC2 TCAP TCMP PD5/SS PD4/SCK PD3/MOSI PD2/MISO PD1/TDO PD0/RDI
Figure 40-Pin Dual-In-Line Package Assignments
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
RESET
OSC1
OSC2
TCAP
TCMP PD5/SS PD4/SCK PD3/MOSI PD2/MISO PD1/TDO RD0/RDI
Figure 44-Lead PLCC Package Assignments option selected include level-sensitive triggering, then input requires external resistor "wired-OR" operation. Interrupts page more detail concerning interrupts. RESET RESET active-low bidirectional control signal. input, RESET initializes known startup state. open-drain output, RESET indicates internal failure detected computer operating properly (COP) watchdog timer clock monitor circuitry. This RESET significantly different from RESET signal used other Motorola M68HC05 Family devices. Refer Resets page Interrupts page before designing circuitry generate monitor RESET signal. TCAP TCAP provides input input-capture feature on-chip programmable timer system. Refer input-capture register Programmable Timer page 173. TCMP provides output output-compare feature on-chip timer system. Refer output-compare register Programmable Timer page 173.
TCMP
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Pins Connections
OSC1 OSC2
MC68HC705C8 accept either crystal, ceramic resonator, external input control internal oscillator. internal processor clock derived dividing oscillator frequency (fosc) two. circuit shown Figure 20(a) recommended when using crystal. internal oscillator designed interface with AT-cut parallel resonant quartz crystal ceramic resonator MHz. crystal components should mounted close possible input pins minimize output distortion startup stabilization time.
STOP
MC68HC705C8 OSC1 XTAL OSC2
Crystal/Ceramic Resonator Oscillator Connections
STOP
MC68HC705C8 OSC1 OSC2 UNCONNECTED EXTERNAL CMOS CLOCK
External Clock Source Connections
Figure Oscillator Connections
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
ceramic resonator used place crystal cost-sensitive applications. circuit Figure 20(a) recommended when using ceramic resonator crystal. manufacturer particular ceramic resonator being considered should consulted specific information. external clock applied OSC1 input with OSC2 connected, shown Figure 20(b). PA7-PA0 These eight lines comprise port Each port software programmed input output. These eight lines comprise port Each port software programmed input output. These eight lines comprise port Each port software programmed input output. These seven lines comprise port During power-on reset, these seven pins configured inputs. When system enabled, four these lines, MISO/PD2, MOSI/PD3, SCK/PD4, SS/PD5, used system. When receiver enabled, PD0/RDI becomes receive data input SCI. When transmitter enabled, becomes transmit data output SCI.
PB7-PB0
PC7-PC0
PD5-PD0
Typical Basic Connections
There basic connections that used starting point application minimize time required create prototype system. Figure schematic diagram simple MC68HC705C8 system. This circuit used basis MC68HC705C8 application. most cases, circuitry power supply oscillator used shown this diagram. unused inputs terminated appropriate manner.
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Pins Connections
MC68HC705C8 SYSTEM POWER OSC1 OSC2 MC34064 RESET RESET PD0/RDI PD1/TDO PD2/MISO PD3/MOSI PD4/SCK PD5/SS TCAP TCMP PULLUP RESISTORS RECOMMENDED UNUSED INPUTS (TYP)
Figure Typical Basic Connections
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
On-Chip Memory
MC68HC705C8 memory includes bytes random-access memory (RAM), bytes read-only memory (ROM), 7600 7744 bytes programmable memory (EPROM OTPROM).
Memory Types
means that word memory accessed without having through other words volatile form memory that memory content lost when power removed from chip. contents retained keeping least volts VDD. Power requirements this standby mode very small. very similar except, unlike RAM, possible change contents after manufactured. This type memory useful only storage information programs. special bootstrap mode allows programs downloaded through on-chip serial communications interface (SCI) into internal executed. bootloaded program used variety tasks such loading calibration values into internal EPROM performing diagnostics finished module. MC68HC705C8 on-chip called bootloader ROM. This controls loading process special bootstrap mode. Erasable programmable (EPROM) nonvolatile memory that programmed field user. Nonvolatile memories retain their contents even when power applied. Once been programmed, EPROM cannot written into, read from many times necessary. However, EPROM erased ultraviolet light reprogrammed. OTPROM same EPROM except programmed only once cannot erased.
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data On-Chip Memory
Memory
MC68HC705C8 contains four selectable memory configurations shown Figure memory configurations accessed option register ($1FDF) RAM0 RAM1 bits. During reset, RAM0 RAM1 control bits forced RAM0 RAM1 states determine amount PROM, which selected follows:
RAM0 RAM1 Bytes PROM Bytes 7744 7696 7648 7600
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
$0000 $001F $0020 $002F
BYTES USER PROM BYTES RAM0=0* UNUSED BYTES BYTES RAM0=1*
$004F $0050
BYTES $00BF $00C0 $00FF $0100 STACK BYTES USER PROM BYTES RAM0=0* BYTES RAM0=1*
$015F $0160
USER PROM 7680 BYTES
PORT DATA REGISTER PORT DATA REGISTER PORT DATA REGISTER PORT FIXED INPUT REGISTER PORT DATA DIRECTION REGISTER PORT DATA DIRECTION REGISTER PORT DATA DIRECTION REGISTER UNUSED UNUSED UNUSED CONTROL REGISTER STATUS REGISTER DATA REGISTER BAUD RATE REGISTER CONTROL REGISTER CONTROL REGISTER STATUS REGISTER DATA REGISTER TIMER CONTROL REGISTER TIMER STATUS REGISTER INPUT-CAPTURE REGISTER (HIGH) INPUT-CAPTURE REGISTER (LOW) OUTPUT-COMPARE REGISTER (HIGH) OUTPUT-COMPARE REGISTER (LOW) TIMER COUNT REGISTER (HIGH) TIMER COUNT REGISTER (LOW) ALT. COUNT REGISTER (HIGH) ALT. COUNT REGISTER (LOW) EPROM PROGRAM REGISTER RESET REGISTER CONTROL REGISTER UNUSED
$1EFF $1F00 BOOT BYTES $1FDE $1FDF $1FE0 BOOT VECTORS BYTES $1FEF $1FF3 $1FF4 $1FFF UNUSED BYTES USER PROM VECTORS BYTES OPTION REGISTER VECTOR (HIGH) VECTOR (LOW) VECTOR (HIGH) VECTOR (LOW) TIMER VECTOR (HIGH) TIMER VECTOR (LOW) VECTOR (HIGH) VECTOR (LOW) VECTOR (HIGH) VECTOR (LOW) RESET VECTOR (HIGH BYTE) RESET VECTOR (LOW BYTE) $1FF4 $1FF5 $1FF6 $1FF7 $1FF8 $1FF9 $1FFA $1FFB $1FFC $1FFD $1FFE $1FFF
Refer Option Register page explanation software-selectable memory configurations.
Figure MC68HC705C8 Memory
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Central Processor Unit
Central Processor Unit
MC68HC705C8 responsible executing software instructions their programmed sequence specific application. block diagram shown Figure
CONTROL M68HC05 REGISTERS
ARITHMETIC LOGIC UNIT (ALU)
ACCUMULATOR INDEX REGISTER
STACK POINTER PROGRAM COUNTER CONDITION CODES
Figure M68HC05 Block Diagram
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Registers contains five registers shown Figure Registers memories inside microprocessor (not part memory map).
ACCUMULATOR INDEX REGISTER PROGRAM COUNTER CONDITION CODE REGISTER STACK POINTER
CARRY ZERO NEGATIVE INTERRUPT MASK HALF-CARRY (FROM
Figure Programming Model
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Central Processor Unit
Accumulator
accumulator 8-bit general-purpose register used hold operands, results arithmetic calculations, data manipulations. also directly accessible nonarithmetic operations. accumulator used during execution program when contents some memory location loaded into accumulator. Also, store instruction causes contents accumulator stored some prescribed memory location.
ACCUMULATOR
Figure Accumulator Index Register index register used indexed modes addressing used auxiliary accumulator. This 8-bit register loaded either directly from memory, have contents stored memory, contents compared memory. indexed instructions, register provides 8-bit value that added instruction-provided value create effective address. instruction-provided value bytes long.
INDEX REGISTER
Figure Index Register
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Condition Code Register condition code register contains five status indicators that reflect results arithmetic other operations CPU. five flags half-carry (H), negative (N), zero (Z), overflow (V), carry borrow (C).
CONDITION CODE REGISTER
CARRY ZERO NEGATIVE INTERRUPT MASK HALF-CARRY (FROM
Figure Condition Code Register (CCR) Half-Carry half-carry flag used binary-coded decimal (BCD) arithmetic operations affected addition instructions. when carry occurs between bits Interrupt Mask interrupt mask disables maskable interrupt sources when set. Clearing this enables interrupts. When interrupt occurs, automatically after registers stacked before interrupt vector fetched. external interrupt occurs while set, interrupt latched processed after cleared; therefore, interrupts from lost because being set. After interrupt been serviced, return from interrupt (RTI) instruction causes registers restored their previous values. Normally, would zero after executed. After reset, only cleared software instruction. Negative when result last arithmetic, logical, data manipulation negative (bit result logic one).
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Central Processor Unit
other uses. assigning often-tested flag register memory location, test this simply loading accumulator with contents that location. Zero when result last arithmetic, logical, data manipulation zero. Carry/Borrow used indicate whether there carry from addition borrow result subtraction. Shift rotate instructions operate with through carry facilitate multiple word shift operations. This also affected during test branch instructions. following illustration example condition code bits affected arithmetic operations.
ASSUME INITIAL VALUES ACCUMULATOR CONDITION CODES:
ACCUMULATOR BEFORE ($FF)
CONDITION CODES
EXECUTE FOLLOWING INSTRUCTION: ACCUMULATOR
ACCUMULATOR AFTER ($01)
CONDITION CODES
CONDITION CODES ACCUMULATOR REFLECT RESULTS INSTRUCTION:
because there carry from accumulator. change. Clear because result negative (bit accumulator Clear because result zero. because there carry accumulator.
useful after this operation because accumulator valid value before operation.
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Program Counter program counter 13-bit register that contains address next instruction instruction operand fetched processor.
PROGRAM COUNTER
Figure Program Counter (PC) Normally, program counter advances memory location time instructions instruction operands fetched. Jump, branch, interrupt operations cause program counter loaded with memory address other than that next sequential location. Stack Pointer stack pointer 13-bit register that contains address next free location stack. During reset reset stack pointer (RSP) instruction, stack pointer location $00FF.The stack pointer then decremented data pushed onto stack incremented data pulled from stack.
STACK POINTER
Figure Stack Pointer (SP) When accessing memory, seven MSBs permanently 0000011. These seven bits appended bits produce address within range $00FF $00C0. Subroutines interrupts (decimal) locations. locations exceeded, stack pointer wraps around loses previously stored information. subroutine call occupies locations stack; interrupt uses five locations.
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Central Processor Unit
Arithmetic/Logic Unit (ALU)
arithmetic logic unit (ALU) used perform arithmetic logical operations defined instruction set. various binary arithmetic operations circuits decode instruction instruction register desired function. Most binary arithmetic based addition algorithm, subtraction carried negative addition. Multiplication performed discrete instruction chain addition shift operations within under control control logic. multiply instruction (MUL) requires internal processor cycles complete this chain operations.
Control
control circuitry sequences logic elements carry required operations.
Resets
Reset used force systern known starting address. Peripheral systems many control status bits also forced known state result reset. following four conditions cause reset MC68HC705C8 MCU: External, active-low input signal RESET pin. Internal power-on reset (POR) condition. Internal computer operating properly (COP) watchdog system reset condition. Internal clock monitor reset condition.
Power-On RESET
power-on reset occurs when positive transition detected VDD. power-on reset used strictly power turn-on conditions should used detect drops power supply voltage. There provision power-down reset. power-on circuitry provides 4064 cycle delay from time that oscillator becomes active. external RESET 4064 delay timeout, processor remains reset condition until RESET goes high.
M68HC05 Microcontroller Applications Guide Rev.
MOTOROLA
MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
following internal actions occur result reset: data direction registers cleared zero (input). Stack pointer configured $00FF. condition code register logic one. External interrupt latch cleared. disabled (serial control bits Other bits cleared reset include: TIE, TCIE, RIE, ILIE, RWU, SBK, RDRF, IDLE, Serial status bits TDRE set. prescaler rate control bits SCPO, SCP1 cleared. disable (serial output enable control Other bits cleared reset include: SPIE, MSTR, SPIF, WCOL, MODF. serial interrupt enable bits cleared (SPIE, TIE, TCIE). system configured slave (MSTR Timer prescaler reset zero state. Timer counter configured $FFFC. Timer output compare (TCMP) reset zero. timer interrupt enable bits cleared (ICIE, OCIE, TOIE) disable timer interrupts.
OLVL timer also cleared reset. STOP latch cleared. WAIT latch cleared. Internal address forced restart vector exit from reset, upper byte program counter loaded from $1FFE, lower byte program counter loaded from $1FFF).
M68HC05 Microcontroller Applications Guide Rev. MC68HC705C8 Functional Data MOTOROLA
MC68HC705C8 Functional Data Central Processor Unit
Computer Operating Properly (COP) Watchdog Timer RESET
watchdog timer system intended detect software errors. When being used, software responsible keeping free-running watchdog timer from timing out. watchdog timer times out, indication that software longer being executed intended sequence; thus, system reset initiated. Since timer relies internal clock order detect software failure, clock monitor also included guard against failure clock. When timer enabled, clock monitor should also enabled since timer cannot detect failures internal clock. control register ($1E), shown below, used control watchdog timer clock monitor functions.
COPF
COPE
COPCR RESET CONDITION
SELECT TIME PERIOD WATCHDOG TIMER ENABLE CLOCK MONITOR ENABLE SYSTEM FLAG
Cleared external reset, clock monitor fail resets.
COPF Computer Operating Properly Flag Reading control register clears COPF. clock monitor reset occurred clock monitor reset occurred Clock Monitor Enable readable writable time. Clock monitor enabled Clock monitor disabled COPE Computer Operating Properly Enable timeout enabled timeout disabled
M68HC05 Microcontroller Applications Guide Rev. MOTOROLA MC68HC705C8 Functional Data
MC68HC705C8 Functional Data
Computer Operating Properly Mode These bits used select watchdog timeout period (see Table actual timeout period dependent system clock frequency, but, reference purposes, Table shows relationship between select bits timeout period various system clock frequencies ("E" stands system clock). default reset condition mode bits (CMI cleared, which corresponds shortest timeout period. Table Timeout Period versus
E/215 Div. XTAL Timeout 16.38 65.54 262.14 1.048 XTAL 3.5796 1,7897 Timeout 18.31 73.24 292.95 1.172 XTAL Timeout 32.77 131.07 524.29 2.097 XTAL Timeout 65.54 1.048 4.194
reset register ($1D) used keep watchdog timer from timing out.
COPRR
sequence required reset watchdog timer Write reset register location $ID. Write same address location. Both write operations must occur correct order prior timeout, number instruction

Other recent searches


TDA7529 - TDA7529   TDA7529 Datasheet
TA48015F - TA48015F   TA48015F Datasheet
LX1662 - LX1662   LX1662 Datasheet
LX1663 - LX1663   LX1663 Datasheet
CLV0815E-LF - CLV0815E-LF   CLV0815E-LF Datasheet
BCM-5554 - BCM-5554   BCM-5554 Datasheet
B78476A8067A003 - B78476A8067A003   B78476A8067A003 Datasheet

 

Privacy Policy | Disclaimer
© 2012 Datasheet Archive