1 Microcontrollers and the Freescale/Motorola HC11 Summer 2008 CMPE12 – Summer 2008 – Slides by ADB 2 What is a microcontroller? A computer on a chip used to control electronic devices A microprocessor Usually not cutting edge (4-bit to 32-bit) Dependable (all major bugs well known) Predictable (critical for real-time processing) On-chip peripherals and memory Parallel and serial digital I/O Analog I/O Counters and timers Internal ROM, RAM and/or EPROM
20
Embed
Microcontrollers and the Freescale/Motorola HC11 · 1 Microcontrollers and the Freescale/Motorola HC11 Summer 2008 CMPE12 – Summer 2008 – Slides by ADB 2 What is a microcontroller?
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
Microcontrollers and the Freescale/Motorola HC11
Summer 2008
CMPE12 – Summer 2008 – Slides by ADB 2
What is a microcontroller?A computer on a chip used to control
electronic devicesA microprocessor
Usually not cutting edge (4-bit to 32-bit)Dependable (all major bugs well known)Predictable (critical for real-time processing)On-chip peripherals and memory
Parallel and serial digital I/OAnalog I/OCounters and timersInternal ROM, RAM and/or EPROM
2
CMPE12 – Summer 2008 – Slides by ADB 3
What are microcontrollers used in?Microcontrollers are used in
WatchesMicrowavesStereo ReceiversATMsPDAs, MP3 playersAutomobiles (between 9 and 50)
8-bitMCS-48 (8048 family – also incl. 8035, 8038, 8039, 8040, 8X42, 8X49, 8050; X=0 or 7) MCS-51 (8051 family – also incl. 8X31, 8X32, 8X52; X=0, 3, or 7) 8xC251
16-bitMCS-96 (8096 family – also incl. 8061) Intel MCS 296
Lattice SemiconductorMico8 softcore 8 bit microcontroller
Microchip Technology8 and 16-bit microcontrollers with 12 to 24-bit instructions ability to include DSP function 12-bit instruction PIC14-bit instruction PIC
PIC16F8416-bit instruction PIC
National SemiconductorCOP8CR16
NECPhilips SemiconductorsRabbit Semiconductor
CMPE12 – Summer 2008 – Slides by ADB 8
Microcontrollers (4/4)Renesas Technology
(Renesas is a joint venture of Hitachi and Mitsubishi Electric.)SilabsSilicon MotionSTMicroelectronicsTexas InstrumentsToshibaWestern Design CenterUbicomXemicsXilinxZiLOG
5
CMPE12 – Summer 2008 – Slides by ADB 9
Languages for microcontrollers‘99-’00‘98-’99Language
~ 3 %
~ 1 %
~ 5%
~ 69%
~ 21%
~ 2%Other
~ 2%Java
~ 6%C++
~ 80%C
~ 10%Assembly
Source: TRON Association Survey 1998/99 & 1999/2000
CMPE12 – Summer 2008 – Slides by ADB 10
Motorola / Freescale MC68HC11A8M6801 CPU coreMemory:
Switches8 switches, MSb on far left and LSb on far rightAccessed by reading from SWITCHES
LEDs8 LEDs, MSb on far left and LSb on far rightAccessed by writing to LEDSActive low (writing a 0 turns a light on)
LCDTwo lines, 16 characters per lineWe provide some routines output to LCD
CMPE12 – Summer 2008 – Slides by ADB 17
The HC11 instruction set architectureMixed 8-bit/16-bit architecture CISC, with more than 100 opcodesOne instruction can use several addressing modes, depending on how you use itAccumulator architecture
9
CMPE12 – Summer 2008 – Slides by ADB 18
An aside: accumulator architectureOne operand comes from memoryThe other comes from the accumulator
CMPE12 – Summer 2008 – Slides by ADB 19
The HC11 accumulators and registersTwo 8-bit accumulators, or you can use them together as one 16-bit accumulator
Two 8-bit accumulators, A or BOne 16-bit accumulator [A:B], called D
Two index registersTwo 16-bit index registers, X and Y, used for addressing memory or for counting
Special registers16-bit dedicated stack pointer, SP16-bit program counter, PC8-bit condition codes register, CCR
10
CMPE12 – Summer 2008 – Slides by ADB 20
The HC11 registers
CMPE12 – Summer 2008 – Slides by ADB 21
Accumulators: A, B, and DGeneral-purpose 8-bit accumulators
Source/destination of most operationsAlmost always interchangeable
E.g.,ABA, add B to A
A (A + B)B is unchangedNote that there is no AAB instruction
SBA, subtract B from AA (A – B)Note that there is no SAB instruction
7 A 0 7 B 0
15 D 0
11
CMPE12 – Summer 2008 – Slides by ADB 22
Accumulators: A, B, and DSome instructions use [A:B] as a single 16-bit register DE.g.
ADDD #2LDD #1MUL
7 A 0 7 B 0
15 D 0
CMPE12 – Summer 2008 – Slides by ADB 23
Index registers X and Y
16-bit index registers X and Y:Used for indexed addressing modeSwap with register D to perform complex address operations
Address space: 64KBLC-3: 64K words, which is 128 KB
15 X 0
15 Y 0
12
CMPE12 – Summer 2008 – Slides by ADB 24
HC11 User StackThe HC11 has a stack set up at start-upMemory is byte-addressable
PSHA // push accumulator A onto stack// SP = SP – 1 since a byte size
PSHY // push index register Y onto stack// SP = SP – 2 since a word size
PULA // Pop off a byte from the stack into A// SP = SP + 1
PULY // Pop off a word from the stack into Y// SP = SP + 2
CMPE12 – Summer 2008 – Slides by ADB 25
A
An aside: the RPN calculatorRPN is Reverse Polish NotationHP calculatorsE.g., A = CD+E
Push CPush DMultPush EAddPop A
CCDDE
TOPCD+E
13
CMPE12 – Summer 2008 – Slides by ADB 26
Stack pointer: SP16-bit stack pointer, SP
Automatically incremented or decremented on pushes and popsCan be used for data and return addressesReturn address for subroutines is automatically pushed with jsr and popped with rts
15 SP 0
CMPE12 – Summer 2008 – Slides by ADB 27
Program counter: PC16-bit program counter, PC
15 PC 0
14
CMPE12 – Summer 2008 – Slides by ADB 28
Condition code register: CCRFive status indicators
H, half carry (used only for BCD operations)N, negativeZ, zeroV, overflow (two’s complement)C, carry/borrow
many instructions set them all, but not all instructions
Two interrupt masking bitsI, disable all maskable interrupts (1 = disable)X, disable external interrupts (1 = disable)
A STOP-disable bit disables the STOPinstruction
S X H I N Z V C
CMPE12 – Summer 2008 – Slides by ADB 29
Programming on the HC11 microkitDesign environment:
Edit the source file Assemble on UNIX machine
> hc11build file.asm
Will produce an object (executable) file called file.s19Download program to the PC with terminal program TeraTermUpload to the microkit using serial cable
To use kits at homeGet one at BELSHave a connection to ITS machinesGet TeraTerm, which is free
Or any program which is capable of serial communication
15
CMPE12 – Summer 2008 – Slides by ADB 30
Programming on the HC11 microkitAs part of your program, always have
#include <v2_18g3.asm>
What the include file doesSets up memory, including the stack pointerJumps to the “main” labelIncludes a basic library of I/O routines
CMPE12 – Summer 2008 – Slides by ADB 31
Structure of a source program/* header comments */
#include <v2_18g3.asm>
.sect .data// your variables here
.sect .text// your code heremain: // must have a main: function
main: ldx #signonjsr OUTSTRING // write a null-terminated
// string to serial portecho_loop:
ldx #prompt // address of promptjsr OUTSTRING // write out to serial portjsr GETCHAR // getchar returns in ACCAjsr OUTCHAR // write ACCA to screenjsr OUTCRLF // write '\n' to serial portjmp echo_loop
CMPE12 – Summer 2008 – Slides by ADB 33
Example program – factorialThe factorial function
x! = x · (x-1) · (x-2) · … · 3 · 2 · 1Two ways to do it
RecursivelyNon-recursively
Draw a flow chartWrite an algorithm
17
CMPE12 – Summer 2008 – Slides by ADB 34
Example program – factorial.asm (1/2)12345678910111213141516171819
main: ldx #welcomeldaa #1 // line 1jsr LCDSTRING // write to LCD, expects in Xldx #blanksinca // line 2jsr LCDSTRING // write to LCDldx #promptjsr LCDSTRING // write to LCD
CMPE12 – Summer 2008 – Slides by ADB 35
Example program – factorial.asm (2/2)202122232425262728293031323334353637
ldab SWITCHES // B SWITCHESjsr fact_startjsr LCDINT // expects input in Dstab LEDS // LEDS B
always: jmp always
// factorial: assume input in B, output in Dfact_start:
stab input // input Btba // A B
fact: dec input // input (input – 1)ldaa input // A inputbeq fact_done // Z?mul // D (A·B)jmp fact