Microcontrollers and the Freescale/Motorola HC11 · 1 Microcontrollers and the Freescale/Motorola...
Transcript of Microcontrollers and the Freescale/Motorola HC11 · 1 Microcontrollers and the Freescale/Motorola...
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)
Some products that you might know:NASA’s Sojourner Rover – 8-bit Intel 80C85Palm Vx handheld – 32-bit Motorola Dragonball EZSonicare toothbrush – 8-bit Zilog Z8The Vendo V-MAX 720 Soda Machine – Motorola HC11Miele dishwasher – 8-bit Motorola 68HC05Hunter 44550 Programmable Thermostat – (4-bit cpu)
CMPE12 – Summer 2008 – Slides by ADB 4
Microprocessor unit salesMicroprocessor unit sales are 100 times higher than microcontroller sales
Microprocessor: 220 millionMicrocontroller: 20 billion
Microcontrollers are much, much cheaper
3
CMPE12 – Summer 2008 – Slides by ADB 5
Microcontrollers (1/4)AMCC
Until May 2004, these µCs were developed and marketed by IBM, whose 4xx family was sold to Applied Micro Circuits Corporation.403 PowerPC CPU
PPC 403GCX405 PowerPC CPU
PPC 405EPPPC 405GP/CR PPC 405GPrPPC NPe405H/L
440 PowerPC Book-E CPUPPC 440GPPPC 440GXPPC 440EP/EPx/GRxPPC 440SP/SPe
AlteraNios II 32-bit configurable soft processor Nios 16-bit configurable soft processor
AtmelAT89 series (Intel 8051 architecture)AT90, ATtiny, ATMega series (AVR architecture) (Atmel Norway design) AT91SAM (ARM architecture)AVR32 (32-bit AVR architecture)
Charmed LabsCypress MicroSystemsDallas Semiconductor
CMPE12 – Summer 2008 – Slides by ADB 6
Microcontrollers (2/4)Freescale Semiconductor
Until 2004, these µCs were developed and marketed by Motorola, whose semiconductor division was spun-off to establish Freescale.8-bit
68HC05 (CPU05) 68HC08 (CPU08) 68HC11 (CPU11)
16-bit68HC12 (CPU12) 68HC16 (CPU16) Freescale DSP56800 (DSPcontroller)
32-bitFreescale 683XXMPC500MPC 860 (PowerQUICC) MPC 8240/8250 (PowerQUICC II) MPC 8540/8555/8560 (PowerQUICC III)
FujitsuHoltekInfineon
8-bitXC800 familyC500/C800 family
16-bitXC166 family
32-bit familyTRICORE family
4
CMPE12 – Summer 2008 – Slides by ADB 7
Microcontrollers (3/4)Intel
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:
8KB ROM 512B EEPROM256B RAM
Counter/Timer system8-channel, 8-bit A/D converter
Analog to digital converter(external D/A in our kit)
Parallel I/O portTwo serial I/O ports:
Asynchronous, SCISynchronous, SPI
Expansion bus for external memory
6
CMPE12 – Summer 2008 – Slides by ADB 11
What are RAM and ROM?RAM: Random-access memory
Write to any location with the same effort(Same amount of time)
ROM: (Random-access) read-only memoryPROM: Programmable ROMEPROM: Erasable PROMEEPROM: Electrically-erasable PROMFlash EEPROM: Faster EEPROM
CMPE12 – Summer 2008 – Slides by ADB 12
High-level HC11 architecture
Timer and counter M8601 CPU core
Serial I/O A/D converter
MEMORYInterrupt logic
Port A Port B Port C Port D Port E
7
CMPE12 – Summer 2008 – Slides by ADB 13
Our HC11 microkit
AC/DC Power adapterSerial cable
to PC
LCD
LEDs
Switches
HC11 µC
LCD display brightness control
CMPE12 – Summer 2008 – Slides by ADB 14
Our HC11 microkit boardSerial (RS232C)
connector
EEPROM LEDs
Switches
HC11 µC
LCD display brightness control
External RAM
Interrupt
HW Reset
8
CMPE12 – Summer 2008 – Slides by ADB 16
HC11 programmer-accessible hardwareButtons
ResetInterrupt (IRQ)
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
16
CMPE12 – Summer 2008 – Slides by ADB 32
Example program – echo.asm#include <v2_18g3.asm>
.sect .datasignon: .asciz "CMPE12C Welcome!"prompt: .asciz ">"
.sect .text
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
#include <v2_18g3.asm>
.sect .data
welcome: .asciz " Factorial !"prompt: .asciz "Fact is "blanks: .asciz " "input: .byte 0
.sect .text
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
fact_done:rts
18
CMPE12 – Summer 2008 – Slides by ADB 41
Compiling the
program
CMPE12 – Summer 2008 – Slides by ADB 42
19
CMPE12 – Summer 2008 – Slides by ADB 43
Downloading the program
Just drag & drop…
CMPE12 – Summer 2008 – Slides by ADB 44
Running the program
Note the LEDs: is the number correct?