Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller...

26
Embedded Controller Programming 1 Copyright 1999-2004 Ken Arnold 1 Copyright 1999-2004 Ken Arnold 1 Embedded Controller Programming 1 Instructor - Ken Arnold [email protected] Week 1: Introduction and Getting Started These are the course notes to accompany the UCSD Extension class: Embedded Controller Programming I: Assembly Language Programming FIRST send e-mail listing any e-mail addresses you would like to have class notices sent to: [email protected] NEXT send an e-mail message to subscribe to the class discussion group by sending a message to: [email protected] with subject = subscribe The class e-mail will consist of updates between meetings, Q&A, important notices, and interaction with the instructor and other students between classes. Course web site: http://www.hte.com/uconline/ecp programs/other files on the ftp site: ftp://ftp.hte.com/uconline/ecp Ken Arnold [email protected] phone 858-679-1569 or 679-4821 (office) phone 858-335-9361 (mobile) fax 858-679-7569 HiTech 14260 Garden Road, Suite 2A Poway, CA 92064-4972

Transcript of Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller...

Page 1: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 1

Copyright 1999-2004 Ken Arnold 1

Embedded Controller Programming 1

Instructor - Ken [email protected]

Week 1:

Introduction and

Getting Started

These are the course notes to accompany the UCSD Extension class:Embedded Controller Programming I: Assembly Language Programming

FIRST send e-mail listing any e-mail addresses you would like to have class notices sent to:

[email protected] send an e-mail message to subscribe to the class discussion group by sending a message to: [email protected] with subject = subscribe

The class e-mail will consist of updates between meetings, Q&A, important notices, and interaction with the instructor and other students between classes.

Course web site: http://www.hte.com/uconline/ecp

programs/other files on the ftp site: ftp://ftp.hte.com/uconline/ecp

Ken Arnold [email protected] 858-679-1569 or 679-4821 (office)phone 858-335-9361 (mobile)fax 858-679-7569HiTech14260 Garden Road, Suite 2APoway, CA 92064-4972

Page 2: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 1

Copyright 1999-2004 Ken Arnold 2

ECP 1 and 2 Course OverviewInstructor & Student IntroductionsProcessor ArchitectureBasic Instruction SetIntroduction to the SDKHomework #1

Welcome to class!

Copyright 1999-2004 Ken Arnold 3

Overview - ECP 1

uC Architecture and ProgrammingAssembly Language Programming8051 Memory Model and Memory Usage8051 Instruction Set8051 Hardware FeaturesOther Topics

Page 3: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 2

Copyright 1999-2004 Ken Arnold 4

Overview - ECP 2

Focus on ApplicationsLearning to use C for uC ProgrammingAdapting C to the uC environmentFocusing on Modular ProgrammingHandling Basic Peripherals

DisplaysSwitches/KeypadsMotors/Controls

Student Projects !

Copyright 1999-2004 Ken Arnold 5

Administrative Stuff

Fill Out Student Forms Please !Send e-mail to [email protected] Format, Policy

Lecture, Demo, Homework, ProjectClass Web Page:http://www.hte.com/uconline/ecp

Grading4 HomeworkProblems - Due Week after Assigned !Programming Project, Comprehensive Final Exam

Be Here So We Can Start (and Finish) On Time !

Page 4: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 3

Copyright 1999-2004 Ken Arnold 6

Course Objectives

Microcontroller vs. Desktop PCFamiliarity with HardwareFamiliarity with ToolsHands-on Exposure RequiredLow Level Programming, InterfacingMicrocontroller ApplicationsPolite, Invisible computing!

Copyright 1999-2004 Ken Arnold 7

Course Format

In-class: Lecture and demonstrations3 hours * 6 meetingsPlease Ask Questions!!

Outside of Class:Software Development Kit (SDK), Development Setup:

SDK, Prototyping, and Test Equipment

Page 5: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 4

Copyright 1999-2004 Ken Arnold 8

Resources

Software ToolsAssembler

HardwareSDK, Prototyping Board, Components

Support Web Siteshttp://www.hte.com/uconline

General Information

Copyright 1999-2004 Ken Arnold 9

The Toaster Fable

The King Wants a New ToasterThe Pragmatic SolutionThe Politically Correct SolutionThe King Resolves the Conflict

Moral:CS emphasizes most general solutionEE emphasizes minimizing complexity

Page 6: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 5

Copyright 1999-2004 Ken Arnold 10

Instructor

Father of 5, age 6 to 24Preemptive Multi-tasking, Dynamic Priorities!

Wireless InnovationProduct Development and Manufacturing

UCSD Extended StudiesEmbedded Certificate Programs

Copyright 1999-2004 Ken Arnold 11

Student Introduction

Your Name and Background

What Do You Do ?(i.e. - EE at XYZ Corp., etc..)

What Do You Want to Get out of This Class ?

Page 7: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 6

Copyright 1999-2004 Ken Arnold 12

What Is a Microcontroller ?

What Are They ?How Are They Used ?Basic FeaturesSizesFamiliesuC’s vs uP’s, DSP’s, PLD’s

Copyright 1999-2004 Ken Arnold 13

µ Controller vs. µProcessor

µC Chip Includes:Central ProcessorProgram MemoryData MemoryI/O

Highly IntegratedLow CostSpecialized Architectures

µP Chip Includes:Central Processor

Separate Chips for:Central ProcessorProgram MemoryData MemoryI/O

Highest PerformanceHighest Cost!

Page 8: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 7

Copyright 1999-2004 Ken Arnold 14

Von Neumann Architecture

Single Memory for:ProgramsData

FamiliarMost FlexibleUsed in PCsSpeed Bottleneck:

Memory Interface

Copyright 1999-2004 Ken Arnold 15

Harvard Architecture

Separate Memory for:ProgramsData

Advantages:FasterOverlap Transfers

Instruction FetchData Transfer

Can’t execute Data!

Page 9: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 8

Copyright 1999-2004 Ken Arnold 16

Bus Oriented Microcomputer

Copyright 1999-2004 Ken Arnold 17

One Chip Microcontrollers

Advantages:Fewer chips requiredLower cost and smallerLower powerFewer connectionsMore user I/O pinsReliability is higherK.I.S.S.!

Disadvantages:Reduced flexibilityExpansion is limitedLimited performanceLimited I/ODesign compromised to fit everything on one chip

Page 10: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 9

Copyright 1999-2004 Ken Arnold 18

Hierarchy of Computer Design

Copyright 1999-2004 Ken Arnold 19

Getting Specific...

In order to get into details, we must look into a specific processor architecture.What criteria were used to decide which architecture to use for this course?

A real device, in common useAvailability from multiple manufacturersFree and very low cost development tools available for student use

Page 11: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 10

Copyright 1999-2004 Ken Arnold 20

The 8051 Microcontroller

The most widely used microcontrollerMultiple sources, hundreds of variantsFree software development tools

AssemblerSimulatorC Compilers

Low cost hardware components and tools

Copyright 1999-2004 Ken Arnold 21

The 8051 Family

Originally Designed by IntelIntroduced in 1980PCs Shipped in the Millions per YearBillions of 8051s shipped in one year

1B Sold just by one of the many manufacturersNew Variants Come out All the TimeOther Microcontrollers Ship in Billions/Year

Page 12: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 11

Copyright 1999-2004 Ken Arnold 22

Partial List of 8051 Vendors

IntelThe Original 8051The 80251 Family

Philips8051 Family VariantsThe 8051XA Family

Atmel20 Pin 89Cxx51 Family8051 Family Variants

Dallas SemiconductorHigh Speed VersionsNon Volatile SRAM

Analog Devices, CygnalTemic, ISSI, Matra, OKI, Siemens, SMC, SSI - and Many Others Too !!!IP Cores for ASICs

SynopsisMentor

Copyright 1999-2004 Ken Arnold 23

Embedded Memory

Semiconductor Storage Implications of Storage Technology

Matching Technology to ApplicationRead-Write, Read-Only, Read-Mostly

Non-ideal Memory CharacteristicsAsymmetrical Read, Write

Page 13: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 12

Copyright 1999-2004 Ken Arnold 24

Memory Volatility

Volatile:Loses contents when power is removedUsed for temporary storage of changing values:

VariablesStacks

Non-Volatile:Retains contents after power lossUsed for permanent storage of:

ProgramsConstantsLook-up Tables

Copyright 1999-2004 Ken Arnold 25

8051 Memory ArchitectureSeparate Memory Address Spaces for:

Programs - Non-volatileInternal ROMExternal EPROM

Data - VolatileExternal SRAMInternal RAM

General Purpose RegistersBit Addressable RegistersSpecial Function Registers

Page 14: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 13

Copyright 1999-2004 Ken Arnold 26

Simple 8051 Block Diagram

Copyright 1999-2004 Ken Arnold 27

8051 uC Chip Block Diagram

Page 15: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 14

Copyright 1999-2004 Ken Arnold 28

8051 Instruction Set

Instructions:Data TransferArithmeticLogicalControl

Address ModesImmediateDirectIndirect

Examples:MOV A,90hADD A,#30hANL A,#0FEhCALL subroutine

Examples:MOV A,#30hMOV A,30hMOV A,@R0

Copyright 1999-2004 Ken Arnold 29

8xC52 Program Memory

On-chip Code MemoryNon-volatileDifferent types:

80C52 = Mask ROM87C52 = EPROM89C52 = Flash EPROM

External Code MemoryDesign DependentSDK has EPROM & SRAM

Page 16: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 15

Copyright 1999-2004 Ken Arnold 30

Program Memory Usage

Processor executionBegins at location 0000h

(The “Reset Vector”)

Continues with next instruction

8x52 has 8K bytes of Internal Code Memory on-chip8x32 has NO code space on chipWhen Processor fetches externalinstructions, /PSEN pulses low

Copyright 1999-2004 Ken Arnold 31

SDK Program Memory Map

ROM: 0000-3FFFhMonitor Program

RAM: 4000-User Program/XData

4000-BDFFhUser Programs and Data

Monitor DataReserved: BE00-BFFFhDO NOT Modify!Temporary Storage

Page 17: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 16

Copyright 1999-2004 Ken Arnold 32

Data Memory

External SRAMExternal chipTypically SRAM

Internal RAMGeneral Purpose RegistersBit Addressable RegistersSpecial Function Registers

Copyright 1999-2004 Ken Arnold 33

Data Memory AddressesExternal Data 0000-FFFFhInternal Data 00-FFh

General Purpose 00-7FhG.P. Register BanksBit AddressableGeneral Purpose “Scratch Pad”

Indirect Access 80-FFhUse MOV @R0 or @R1

SFRs Direct 80-FFhOverlapped addressesDirect address MOV 00-FFhSpecial Internal Registers

Page 18: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 17

Copyright 1999-2004 Ken Arnold 34

Internal Data Memory

Registers R0..78 registers per bank4 Banks available

Bit AddressableGeneral PurposeSpecial Function Registers (SFRs)

Accumulator, I/OTimers, misc. registers

Copyright 1999-2004 Ken Arnold 35

Bit Addressable Memory

Internal Data MemoryByte Addresses 20-2FhBit Addresses 00-7Fh

Allows individual bit operations:

MOV bits to/from CarrySETB sets a bit to 1CLR clears a bit to 0JB conditional jump

Page 19: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 18

Copyright 1999-2004 Ken Arnold 36

8051 Instruction Set

Instructions:Data TransferArithmeticLogicalControl

Address ModesImmediateDirectIndirect

Examples:MOV A,90hADD A,#30hANL A,#0FEhCALL subroutine

Examples:MOV A,#30hMOV A,30hMOV A,@R0

Copyright 1999-2004 Ken Arnold 37

Simple 8051 Block Diagram

Page 20: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 19

Copyright 1999-2004 Ken Arnold 38

Development Tools

SoftwareTranslators

AssemblersCompilers

LinkersDebug Monitor

SDK Monitor ROM

Performance AnalyzersFind Execution Bottlenecks

HardwareIn-Circuit Emulators

Substitutes for CPU chipAllows seeing “inside” uC

Logic AnalyzerView Timing and Bus Cycles

Logic ProbeOscilloscopeLights and Beepers

Copyright 1999-2004 Ken Arnold 39

Hardware Handling Issues

Precautions Regarding:Take Precautions against ESDAvoid Touching Contacts: Metal OxidationPower = heat and smoke

But Don’t Be Afraid!!SDKs are easy to fix and connect to probesSockets for all ICs, and are easily replacedUnlike surface mounted components!

Page 21: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 20

Copyright 1999-2004 Ken Arnold 40

Introduction to the SDK

Software Development Kit ConnectionsPower, Serial Port, ICE CableDocumentation available at: ftp://ftp.hte.com/uconline/ecp/sdkstuff/SDK Users manual: sdk31man.pdfSDK Schematic: sdk31sch.pdf

PC Setup, Software SetupCommon Problems

Copyright 1999-2004 Ken Arnold 41

PC Software for SDK

Hyperterminal, MTTTY, or ProcommTerminal Emulator to connect to SDKCommand line monitor ROM on SDK

asm51 8051 Cross assembler translatesInput, 8051 source: *.asmOutput, Intel Hex object format: *.hexand listing file: *.lst

Page 22: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 21

Copyright 1999-2004 Ken Arnold 42

SDK Introduction

Demonstrate System SetupIntroduce SDK OperationCode Development CycleDownload and Test

Copyright 1999-2004 Ken Arnold 43

SDK - Top View

Page 23: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 22

Copyright 1999-2004 Ken Arnold 44

Demonstration of SDK

Connecting the SDKEditing “Hello World” programAssembling programDownloading Hex file to SDKRunning the modified SDK program

Copyright 1999-2004 Ken Arnold 45

SDK Power Connection

Page 24: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 23

Copyright 1999-2004 Ken Arnold 46

SDK Serial Connector

Copyright 1999-2004 Ken Arnold 47

SDK Serial Cable

Red Stripe

Page 25: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 24

Copyright 1999-2004 Ken Arnold 48

Summary

IntroductionMicrocontroller ArchitectureMemoryInstruction Set IntroDevelopment ToolsSDK Intro

Copyright 1999-2004 Ken Arnold 49

Homework Assignment

Setup SDK and SoftwareModify “Hello World” Program

Change output string to Hello <your name>Optional: Try other changes...

Increment Port 1 OutputsBlink an LED!Echo charactersPlay!!!

Page 26: Embedded Controller Programming 1 - HTEhte.com/uconline/ecp/ecp101.pdfEmbedded Controller Programming 1 ... Assembly Language Programming 8051 Memory Model and Memory Usage ... Embedded

Embedded Controller Programming 1

Copyright 1999-2004 Ken Arnold 25

Copyright 1999-2004 Ken Arnold 50

ReferencesSDK User’s ManualArnold, “Embedded Controller Hardware Design”Ayala, “The 8051 Microcontroller”Cook, "A First Course in Digital Electronics"Foster, “Real Time Programming”Gonick, “The Cartoon Guide to Physics”Horowitz & Hill, “The Art of Electronics”Wakerly, “Digital Design”Schultz, “C and the 8051” vol I and II