microcontrollers - york university microcontroller ... •8051 –popular 8-bit microcontroller...

18
1 Microcontrollers Microcontroller A microprocessor on a single integrated circuit intended to operate as an embedded system. As well as a CPU, a microcontroller typically includes small amounts of RAM and PROM and timers and I/O ports. (hyperdictionary.com) Special type of ASIP designed for embedded control applications Microcontrollers can usually run as a single chip system (on chip memory and peripherals). Frees pins on the chip normally used for interfacing with memory etc for programmable I/O Efficient bit manipulation and direct access to part pins

Upload: vuthu

Post on 29-May-2018

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

1

Microcontrollers

Microcontroller

• A microprocessor on a single integratedcircuit intended to operate as anembedded system. As well as a CPU, amicrocontroller typically includes smallamounts of RAM and PROM and timersand I/O ports. (hyperdictionary.com)

• Special type of ASIP designed forembedded control applications

• Microcontrollers can usually run as asingle chip system (on chip memoryand peripherals).

• Frees pins on the chip normally used forinterfacing with memory etc forprogrammable I/O

• Efficient bit manipulation and directaccess to part pins

Page 2: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

2

• Large variety of microcontrollersspanning a wide range of price andperformance– Based on 4-, 8-, 16-, 32-bit processors (8-

bit most popular, 32-bit for high endapplications)

• Most popular are lower end devicesused extensively in cost sensitiveapplications

• Some reasons for popularity ofmicrocontrollers– Speeds design time (many peripherals

integrated)

– Simplifies I/O interfacing

– Reduce/eliminate external memory

– Single chip solution can help optimise forpower, board space, cost,…

Some Examples

• PIC (www.microchip.com)– Versatile, robust, low-power, low-cost

controller

– No external busses, expansion andcommunication through serial peripheralinteraces or I/O ports

– Variety of versions - some with as little as 8pins (small footprint)

Page 3: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

3

– Harvard architecture (8-bit data space) andlimited registers, instruction set andaddressing modes (RISC like)

• 8051– Popular 8-bit microcontroller originally

made by Intel, now made by many others

– A large number of variants- memoryconfiguration, peripherals, pin count, 16-bitvariants …

– Efficient vectored interrupts

– Efficient bit-manipulation instructions usefulin control applications

• ARM (not a chip maker - IP based)– 32-bit RISC processor core embedded into

microprocessors, ASIPs & microcontrollers

– High speed and advanced architecture

– Many applications: network, digitalcameras, PDAs, mobile phones, …

– Some models have both 32-bit and 16-bitinstruction sets

– Windows CE, Linux, Palm OS, SymbianOS, and Java OS, many RTOS options

– support for both microcontroller and DSPfunctions, embedded ICE features …

Page 4: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

4

Motorola HCS12 family– has a high-speed (for a microcontroller),

16-bit central processing unit• programming model identical to M68HC11

• instruction set is a proper superset of theM68HC11 instruction set

• Fairly complex CISC processor with a largenumber of multi-cycle instructions

• Flexible addressing modes

– Large number of built in peripherals,memory, …

• A member of this family used in the lab

• One of hundreds of processors used inembedded systems

• We will give a brief overview but willnot discuss the microcontroller in depthin class– Engineers and designers need to be able

to learn and evaluate different processors,architectures, instruction sets, …

– For this course, you are required tobecome proficient in coding for the HCS12

– You need to become very familiar with datasheet and user guide

• 512K bytes of Flash EEPROM

• 14K bytes of RAM

• 4K bytes of EEPROM

• two asynchronous serialcommunications interfaces(SCI),

• Three serial peripheralinterfaces (SPI)

• an 8-channel IC/OC enhancedcapture time

• two 8-channel, 10-bit analog-to-digital converters (ADC)

• an 8-channel pulse-widthmodulator (PWM)

• a digital Byte Data LinkController (BDLC)

• 29 discrete digital I/O channels

• five CAN 2.0, I2C bus

Page 5: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

5

Page 6: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

6

• Accumulators– Two 8-bit accumulators A and B are used

to hold ALU operands.

– Can be combined into double accumulatorD

• Index Registers– used for indexed addressing

• Stack Pointer– Automatic program stack saves system

context for restoring after interrupts andsubroutine calls

– Can also store temporary data and passparameters to subroutines

– SP register contains address of last datapushed on stack. The stack growsdownward from SP.

– Push decrements SP, pop increments it

– Subroutines call and interrupts• Before entering subroutine, return address is

pushed onto the stack

• Typically also push on state of registers etc atstart of routine and restore before returning

• On return from subroutine, the return address ispopped off the stack and program resumesexecution at this address

Page 7: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

7

• Program counter (PC)– holds the 16-bit address of the next

instruction to be executed.

– automatically incremented each time aninstruction is fetched.

• Condition code register (CCR)– Contains status and control bits

– Status flags: Half carry (H), Negative (N),Zero (Z), Overflow (V), Carry/borrow (C)

– X-mask, I-mask bits: used to enableinterrupts

– S-bit: enables stop instruction

Peripherals

• Peripherals are controlled through aseries of memory mapped registers– Default range $0000 - $03FF ($ for hex

number)

– Moveable to any other 2kB block

– For example, to write to portB output ports• movb #$00,DDRB; set PORTB pins to output

• movb #$AA, PORTB; set alternate bits

Page 8: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

8

Operating modes

• Special operating modes - factory testand development modes

• Normal modes– Single-chip: no external memory interface

– Expanded-wide mode: PORTA andPORTB replaced by multiplexed16-bitaddress and data busses for externalmemory interface

– Expanded-wide mode: like expanded widebut uses an 8-bit data bus

MCS12 Data types

– Bits

– 5-bit signed integers

– 8-bit signed and unsigned integers

– 8-bit, 2-digit binary-coded decimal numbers

– 9-bit signed integers

– 16-bit signed and unsigned integers

– 16-bit effective addresses

– 32-bit signed and unsigned integers

Page 9: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

9

– Negative integers: two’s complement form.

– Five-bit and 9-bit signed integers are usedonly as offsets for indexed addressing.

– Sixteen-bit effective addresses are formedduring addressing mode computations.

– Thirty-two-bit integer dividends are used byextended division instructions.

– Extended multiply and extended multiply-and-accumulate instructions produce 32-bitproducts.

HCS12 instructions

• Consist of 1-2 byte operation code(opcode) and 0-5 bytes of operandaddressing information

• Opcode determines operation to beperformed and how to interpretaddressing information to accessoperands

• HCS12 has very flexible addressingmodes

Page 10: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

10

• Examples loading accumulator A– Immediate ldaa #$0A ; A fl $0A

– Direct ldaa $0A ; A fl m[$0A]

– Indexed– Constant offset 5, 9 or 16 bit

ldaa 8,X ; A fl m[X+8]– Auto pre-decrement (offset 1-8)

ldaa 8,-X ; X fl X-8

; A fl m[X]– Auto pre-decrement (offset 1-8)

ldaa 8,X+ ; A fl m[X+8]

; X fl X+8

Page 11: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

11

– Indirect Indexed (pointer table)

ldx 2000

ldaa [10,X] ; A fl m[m[2010]]

HCS12 Instruction Set

• CISC instruction set with manyspecialised instructions

• Multi-cycle execution time

• Instruction set covers a variety ofinstruction types: Memory and Registeroperations, Logic, Arithmetic, …

Memory and RegisterOperations

• Load and Store operations move databetween main memory and CPUregisters (A,B,D,X,Y,SP,CCR)

• Transfer and Exchange instructionsmove data between CPU registers

• Move instructions move data betweenmemory locations (do not affect CCR)

• Stack operations push onto and pop(pull) from stack

Page 12: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

12

Page 13: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

13

Arithmetic and LogicOperations

• Binary addition, subtraction,multiplication and division

• Boolean logic

• Fast increment and decrementinstructions (for counters) - do not affectCCR

• Specialised instructions for BCDarithmetic

Page 14: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

14

Page 15: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

15

Program control operations

• Short (8-bit) and long (16-bit) branchinstructions

• Loop primitive instructions for counterbased loops (while/for loop)

• Opcodes to call and return fromsubroutines, return from interrupts andcall software interrupts

Page 16: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

16

Page 17: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

17

Other instructions

• Test and compare (not used as muchas in other instruction sets)

• Fuzzy logic

• Multiply and accumulate (DSP)

• Max, min

• Table lookup

• Stop, Wait

• Background and Null instructions

Reading description ofopcodes

• Shows– machine language opcodes for different

addressing modes

– Cycle by cycle execution sequence

– Affect on status bits

• For example …

Page 18: Microcontrollers - York University Microcontroller ... •8051 –Popular 8-bit microcontroller originally made by Intel, now made by many others

18