Programming & Interfacing The 8051 Microcontroller

by : Sencer Yeralan & Ashutosh Ahluwalia

(C) 1993, Addison Wesley


Contents

Preface                                                                                                           xi

I  BACKGROUND                                                                                        1

I.1  Microprocessors and Microcontrollers                                                        1

1.2  Microcontroller-Based Systems Development Tools                                   2

1.3  The 8051 Microcontroller Family Architecture                                           3

1.3.1    On-Chip Memory                                                                    6

1.3.1.1  Internal Random Access Memory                                          6

1.3.1.2  Registers                                                                                 8

1.3.1.3  Bit-Mapped Memory                                                              8

1.3.1.4  Special-Function Registers                                                    8

1.3.1.5  Read Only Memory                                                                10

1.3.1.6  Program Counter                                                                  10

1.3.2    Using the On-Chip Facilities                                                  10

1.3.2.1  Parallel Input/Output Ports                                                   10

1.3.2.2  System Clock Generator                                                        12

1.3.2.3 Serial Port                                                                               12

13.2.4 Timer/Counters                                                                        13

1.3.2.5  Interrupt Control                                                                   16

1.3.2.6 The 8052 Microcontroller                                                       18

1.3.2.7  Power Control                                                                       21

1.4  The 80C515 Microcontroller                                                                     21

1.4.1    Using the 80C515 On-Chip Facilities                                    25

1.4.1.1  Parallel Input/Output Ports                                                   25

1.4.1.2 The Analog-to-Digital Converter                                           26

1.4.1.3 The Enhanced Timer 2                                                            28

1.4.1.4 Timer 2 Input Selection                                                           29

1.4.1.5 Timer 2 Reload Operations                                                     29

1.4.1.6 Timer 2 Compare Operations                                                 30

1.4.1.7 Timer 2 Capture Operations                                                   31

2  ASSEMBLY LANGUAGE PROGRAMMING                                      33

2.1  Background                                                                                               33

2.2  Data Transfer Instructions                                                                          37

2.2.1    The Immediate Addressing Mode                                           38

2.2.2    The Direct Addressing Mode                                                  40

2.2.3    The Register Addressing Mode                                               42

2.2.4    The Register-Specific Addressing Mode                                  42

2.2.5    The Register Indirect Addressing Mode                                  43

2.2.6   The Register Indexed Addressing Mode                                   45

2.2.7   Stack-Oriented Data Transfer                                                 46

2,2.8    Exchange Instructions                                                            47

2.2.9    Bit-Oriented Data Transfer                                                     48

2.3  Data Processing Instructions                                                                      50

2.3.1    Arithmetic Instructions                                                           50

2.3.1.1  Addition and Subtraction Instructions                                   51

2.3.1.2  Increment and Decrement Instructions                                 53

2.3.1.3  Multiplication and Division                                                   55

2.3.1.4 The Decimal Adjust Instruction                                              56

2.3.2    Logic Instructions                                                                   57

2.3.2.1  AND, OR, and EXCLUSIVE-OR Instructions                        57

2.3.2.2  Complement and Clear Instructions                                      58

2.3.2.3  Rotate Instructions                                                                 59

2.3.2.4  The Swap Instruction                                                             60

2.3.2.5  Bit-Oriented Logical Instructions                                          60

2.4  Program Flow Control Instructions                                                            61

2.4.1    Unconditional Jump Instructions                                           62

2.4.2    Conditional Jump Instructions                                               65

2.4.3    Call and Return Instructions                                                   68

2.5  Enhanced Members of the 8051 Family                                                     70

2.6  Interrupts and Real-Time Systems                                                              71

3  ASSEMBLY LANGUAGE TECHNIQUES                                             75

3.1   Introduction                                                                                              75

3.2  Data Block Transfer Routines                                                                    75

3.3  Table Look-Up Procedures                                                                       76

3.4  ASCII Conversion Routines                                                                      79

3.5  N-Way Branching                                                                                     82

3.6  Signed Arithmetic Routines                                                                        84

3.6.1    Twos Complement Conversion Routines                                84

3.6.2    8-Bit Signed Addition and Subtraction                                   87

3.6.3    8-Bit Signed Multiplication and Division                                88

3.7  16-Bit Unsigned Arithmetic Routines                                                          89

3.7.1    16-Bit Addition and Subtraction                                             89

3.7.2    16-Bit Unsigned Multiplication and Division                         91

3.8  16-Bit Signed Arithmetic Routines                                                              97

3.8.1    16-Bit Signed Addition and Subtraction                                 97

3.8.2    16-Bit Signed Multiplication and Division                              98

3.9  Floating-Point Arithmetic Routines                                                             100

3.9.1    Floating-Point Multiplication and Division                            100

3.10 Pseudo-Random Numbers                                                                        106

3.11 String Manipulation Routines                                                                     107

3.12 Software Timing Routines                                                                         111

4  INTRODUCTORY EXPERIMENTS                                                      115

4.1  Input/Output Operations                                                                            116

4.2  A Subroutine for Driving Seven-Segment Displays                                      117

4.3  Using System Calls—Talking to the Host                                                   119

4.4  Interrupt Service Routines                                                                          125

4.4.1    Using an Interrupt Vector Table to Redirect the Interrupts   128

4.4.2    Using Multiple Interrupts                                                       131

4.5  Counter operations                                                                                    133

4.6  Timer Operations                                                                                      137

4.7  Using the PTRA Unit Compare and Capture Functions                              142

4.7.1    Pulse Train Generation with the PTRA Unit                          142

4.7.2    Pulse-Width Modulation                                                         145

4.7.3    Pulse Width and Period Measurement                                   147

4.7.4   Software Timers Using the PTRA Unit                                   162

4.8  Analog-to-Digital Converter                                                                      163

4.9  Interrupt-Driven Timer and Analog-to-Digital Conversion Operation          165

4.10 10-Bit Resolution with the Analog-to-Digital Conversion                           170

4.11 Serial Communications                                                                             176

5  HARDWARE EXPERIMENTS                                                               181

5.1  Implementing Simple Boolean Functions                                                     181

5.1.1 Combinational Logic                                                                 182

5.1.2 Sequential Logic                                                                        184

5.2  Scanning a Keypad                                                                                    185

5.3  Stepper Motor Control                                                                              195

5.4  A Frequency Generator with Timers                                                          201

5.5  Measuring Temperature and Light Intensity

with an Analog-to-Digital Converter                                                      204

5.6  Digital-to-Analog Conversion                                                                     213

5.6.1    Pulse-Width Modulation                                                         214

5.6.2    Using Digital-to-Analog Converter Chips                              218

5.7  DC Motor Speed Regulation with a Feedback System                               222

5.8  Intelligent Peripherals—Interfacing with Liquid Crystal Displays                  232

5.8.1    Display Instructions                                                                237

5.9  Implementing a Multi-Drop RS-485 Network                                            247

5.9.1    Simple Network Programs                                                     248

5.9.2    A Simple Network Protocol                                                    254

5.9.3    An Operational Network                                                        255

6  ENHANCED MEMBERS OF THE 8051 FAMILY                               261

6.1   Fast Microcontrollers                                                                                261

6.2  Enhanced Memory Options                                                                       262

6.3  Additional Data Pointers of the SAB80C517                                             263

6.4  The Multiply and Divide Unit of the SAB80C517                                       264

6.5  The 10-Bit Analog-to-Digital Converter of the SAB80C515A                    265

6.6  The IZC Bus Support of the 83C751                                                         266

6.7  ARCNET Token Bus Network Support of the COM20051                      266

6.8  Information Sources                                                                                   267

7  BUILDING AN 8051-BASED

MICROCONTROI.LER SYSTEM                                                 269

7.1   Hardware                                                                                                 269

7.1.1    An 8051-Based System                                                            269

7.1.2    8051-Based System Bill of Materials                                      274

7.1.3    An 80C515-Based System                                                       277

7.1.4    80C515-Based System Bill of Materials                                  282

7.2  Interfacing the Microcontroller System                                                       284

7.3  MINMON—A Minimal 8051 Monitor Program                                        289

7.3.1    Using the SAB80C515 Baud Rate Generator                            300

7.3.2    Setting Up an Interrupt Vector Table                                         301

7.4 Using the Microcontroller System to Run the Example Program                  303

APPENDIX A

DEVELOPING MICROCONTROLLER APPLICATIONS         305

A.1  Suggested Applications                                                                             306

A.2 The Software Development Cycle                                                              306

APPENDIX B

GENERAL PURPOSE SYSTEM CALLS                                       309

APPENDIX C

8051 FAMILY PRODUCTS AND VENDORS                               315

Software Development Tools                                                              315

In-Circuit Emulators                                                                           318

8051 Family Chip Manufacturers                                                      318

Evaluation Boards                                                                              319

Programmers for the EPROMed Versions of the 8051                      319

Bibliography                                                                                                     321

Index                                                                                                                323


BOOK COVER

Programming & Interfacing The 8051 Microcontroller

PROGRAMMING AND

INTERFACING THE

8051 MICROCONTROLLER

This unique, introductory-level book/disk package  will  not only teach you  the  theory behind  programming

the 8051  microcontroller - the most widely used embedded controller on the market - but will give

you the techniques, software tools, and hands-on experience you need to design a fully-functional industrial

controller.

The disk accompanying the book contains a powerful tool - chip simulation software that enables you to

immediately design and experiment with the chip. Also included on the disk are an MCS-51  cross assembler

as well as all of the source code in the book, saving you hours of tedious typing.

Taking a comprehensive systems approach that integrates hardware, software, and applications, the book

provides detailed information on Intel 8051 assembly language and 8051 and Siemens 80C515 architecture,

programming, and  applications.   You  will  gain  an  understanding  of computerized  industrial  control,

programmable logic, and applications in data acquisition, motor control, and user input/output interfaces.

Numerous working examples - among them a temperature and light measuring system and a motor

speed regulator with feedback - demonstrate how to put the concepts you learn into practice.  You will

also  find  step-by-step  instructions  -  complete  with  circuit  diagrams  and  a  bill  of materials  -  for

building a full-fledged 8051-based microcontroller system.

This combination of theory, practical information, chip simulation software, and source code on disk makes

this book an indispensable resource for anyone who works with embedded controllers.

 

Sencer Yeralan is Associate Professor and Director of the Industrial Research Laboratory and

the University of Florida.  He has held various other industrial and systems engineering positions,

has written numerous articles and book contributions, and has participated in more than 15

private and federally funded research projects.   Ashutosh Ahluwalia works for Siemens

Semiconductor, where he is Senior Product Specialist for microcontrollers.  He has also held

positions in the Quality Assurance Group as well as performing technical support for the 8051

family and 80C166 family of microcontrollers.


Create on : April 10, 2004
- by : David Setya Atmaja
Persons who interest so far :


HomeReturn to Main Page