Programming and Interfacing the 8051 Microcontroller in C and Assembly

Similar documents
C8051F020 Utilization in an Embedded Digital Design Project Course. Daren R. Wilcox Southern Polytechnic State University Marietta, Georgia

Digital Electronics Detailed Outline

Microtronics technologies Mobile:

Upon completion of unit 1.1, students will be able to

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Lab Experiment 1: The LPC 2148 Education Board

Lecture N -1- PHYS Microcontrollers

Microcontrollers in Practice

Technical Aspects of Creating and Assessing a Learning Environment in Digital Electronics for High School Students

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

An Introduction to MPLAB Integrated Development Environment

Chapter 13. PIC Family Microcontroller

Soft processors for microcontroller programming education

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

Microcontroller-based experiments for a control systems course in electrical engineering technology

Programming A PLC. Standard Instructions

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

S7 for Windows S7-300/400

Implementing a Digital Answering Machine with a High-Speed 8-Bit Microcontroller

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE

İSTANBUL AYDIN UNIVERSITY

Chapter 2 Logic Gates and Introduction to Computer Architecture

Tutorial for MPLAB Starter Kit for PIC18F

TEACHING COMPUTER ARCHITECTURE THROUGH SIMULATION (A BRIEF EVALUATION OF CPU SIMULATORS) *

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

7a. System-on-chip design and prototyping platforms

2.0 Command and Data Handling Subsystem

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

8051 MICROCONTROLLER COURSE

POCKET SCOPE 2. The idea 2. Design criteria 3

MICROPROCESSOR AND MICROCOMPUTER BASICS

AC : A PROCESSOR DESIGN PROJECT FOR A FIRST COURSE IN COMPUTER ORGANIZATION

Computer and Set of Robots

Microcontrollers Figure 26-1 Objectives Key Words and Terms 26.1 OVERVIEW OF THE MICROCONTROLLER microcontroller

Freescale Semiconductor, I

Fondamenti su strumenti di sviluppo per microcontrollori PIC

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Lab 1 Course Guideline and Review

Special Lecture. Basic Stamp 2 Programming. (Presented on popular demand)

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

Decimal Number (base 10) Binary Number (base 2)

Palaparthi.Jagadeesh Chand. Associate Professor in ECE Department, Nimra Institute of Science & Technology, Vijayawada, A.P.

Introducción. Diseño de sistemas digitales.1

Embedded Software development Process and Tools: Lesson-4 Linking and Locating Software

Development of a Microcontroller Based Robotic Arm

Ingar Fredriksen AVR Applications Manager. Tromsø August 12, 2005

Chapter 12. Development Tools for Microcontroller Applications

3. Programming the STM32F4-Discovery

Accurate Measurement of the Mains Electricity Frequency

MACHINE ARCHITECTURE & LANGUAGE

A Practical Approach to Education of Embedded Systems Engineering

STEPPER MOTOR SPEED AND POSITION CONTROL

The Heartbeat behind Portable Medical Devices: Ultra-Low-Power Mixed-Signal Microcontrollers

A Digital Timer Implementation using 7 Segment Displays

Lab 1: Introduction to Xilinx ISE Tutorial

How to design and implement firmware for embedded systems

Embedded Patient Monitoring System

Am186ER/Am188ER AMD Continues 16-bit Innovation

Microprocessor or Microcontroller?

Figure 1: Graphical example of a mergesort 1.

MX PIC24F Educational Module User Manual

RAPID PROTOTYPING OF DIGITAL SYSTEMS Second Edition

EXPERIMENT 2 TRAFFIC LIGHT CONTROL SYSTEM FOR AN INTERSECTION USING S7-300 PLC

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

AC : ELECTRICAL ENGINEERING STUDENT SENIOR CAP- STONE PROJECT: A MOSIS FAST FOURIER TRANSFORM PROCES- SOR CHIP-SET

Secure My-d TM and Mifare TM RFID reader system by using a security access module Erich Englbrecht (info@eonline.de) V0.1draft

Use of Simulator in Teaching Introductory Computer Engineering*

CHAPTER 4 MARIE: An Introduction to a Simple Computer

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Trace Port Analysis for ARM7-ETM and ARM9-ETM Microprocessors

ELEC EXPERIMENT 1 Basic Digital Logic Circuits

Serial port interface for microcontroller embedded into integrated power meter

Programming Logic controllers

Design of a High Speed Communications Link Using Field Programmable Gate Arrays

Experiment 2 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and Matlab Graphic User Interface (GUI)

Computer Performance. Topic 3. Contents. Prerequisite knowledge Before studying this topic you should be able to:

An Overview of Stack Architecture and the PSC 1000 Microprocessor

BUILD VERSUS BUY. Understanding the Total Cost of Embedded Design.

Digital Signal Controller (DSC) Development Tools

Academic year: 2015/2016 Code: IES s ECTS credits: 6. Field of study: Electronics and Telecommunications Specialty: -

Homework # 2. Solutions. 4.1 What are the differences among sequential access, direct access, and random access?

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

The string of digits in the binary number system represents the quantity

ENGI E1112 Departmental Project Report: Computer Science/Computer Engineering

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

SAMPLE CHAPTERS UNESCO EOLSS DIGITAL INSTRUMENTS. García J. and García D.F. University of Oviedo, Spain

Chapter 2 Features of Embedded System

UG103.8: Application Development Fundamentals: Tools

Chapter 4 System Unit Components. Discovering Computers Your Interactive Guide to the Digital World

Intelligent Fleet Management System Using Active RFID

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

AC : PRACTICAL DESIGN PROJECTS UTILIZING COMPLEX PROGRAMMABLE LOGIC DEVICES (CPLD)

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

Transcription:

Programming and Interfacing the 8051 Microcontroller in C and Assembly Sencer Yeralan, P.E., Ph.D. Helen Emery Rigel Press, a Division of Rigel Corporation

PREFACE This book is the result of a complete rewrite of a previous textbook, Programming and Interfacing the 8051 Microcontroller, which is now out of print. Many interesting things have happened since Intel built the first 8051 more than two decades ago, and even more interesting things since we wrote the previous book. First, due to the advancements in personal computers and graphical user interfaces, better software development environments are available for embedded control. Second, microcontrollers have become more powerful and faster as their relative prices have dropped. Perhaps more importantly, larger memory devices are available at lower prices. These factors now make C programming an attractive alternative. Third, with the expansion of the internet, more information is readily available. In particular, manufacturers data sheets and various hardware and software users manuals are available for the downloading. This releases a textbook from the task of repeating detailed specifications. Finally, more and more engineers, students, and hobbyists are involved in embedded control. Almost all engineering schools now have a course on embedded control or microcontrollers for non-electrical engineers. The concept of embedded control has become familiar to the public. Moreover, people now expect a product to include a computer chip. Unlike a few years ago, one no longer needs to define embedded control or a microcontroller. All these changes were anticipated by many in the field. However, the changes were not totally without surprises. Most importantly, we did not anticipate the 8051 to be around much longer after we wrote the previous textbook. New and more powerful microcontroller families were being introduced. We, as well as many in the field, thought that some other microcontroller would essentially make the 8051 architecture obsolete. Although several 8-bit microcontrollers have successfully entered the market, the 8051 family nevertheless continues to enjoy a very large following. In fact, when a microcontroller core needs to be attached to a smart peripheral, such as a USB controller, or an ISA interface, the manufacturers often opt for an 8051. There are several reasons given for the continued use of the 8051. Many people and institutions are familiar with it, or have legacy code still in use. Moreover, there are many good very-low-cost or free support tools in the public. In addition, the 8051 has the most second sources of any 8-bit microcontroller. An industrial design with an 8051 reduces concerns of chip availability and cost. Virtually any conceivable peripheral is available next to an 8051 core: extra memory (ROM, RAM, FLASH, EEPROM), ADC, PWM, MAC, I 2 C, CAN, USB, ARCNET, etc. Newer semiconductor manufacturing techniques have also contributed to the success. It is anticipated that the 8051 s will soon reach the 100 MIPS mark. Improving on the original 12 clock cycles per machine cycle design, newer chips take fewer clock cycles per machine cycle. For example, when there are four clock cycles per machine cycle, the processor runs 3 times faster compared to xi

the original 8051 at the same oscillator frequency. Recently, two companies have announced 8051 s achieving one machine cycle per clock cycle. This book uses Rigel s Integrated Development Environment (IDE) Reads51. Reads51 is free for students and educational institutions. Simply download Reads51 and the examples in this book from www.riglcorp.com. Support material for the book, such as manufacturers data sheets for the components used in the experiments are also available at this web site. Most of the experiments use the standard 8051. Reads51 version 4.x includes an improved chip simulator with a virtual TTY window and virtual ports. Many experiments may be run in the chip simulator while the user interacts with the ports by clicking on the icons in the virtual I/O window. This is particularly useful for students who develop their code offline. The full impact of the experiments is achieved when actual hardware is used. The book uses Rigel s RMB- S development board with the 80C515 microcontroller, manufactured by Infineon Technologies (formerly Siemens Microelectronics). The 80C515 contains more ports for interfacing, an improved Timer 2 unit (PTRA) for Pulse-Width Modulation (PWM), and an internal Analog-to-Digital Converter (ADC). Circuit diagrams, parts lists, and simple firmware are given in Chapter 7 for those who would like to build their own 8051- or 80515-based board. In summary, you may, 1. Use the chip simulator given with Rigel Corporation s Reads51 Integrated Development Environment (IDE). The latest version of the IDE may be downloaded from www.rigelcorp.com. 2. Build an 8051- or 80515-based microcontroller system as described in this book and run the programs on the system, 3. Use a commercial evaluation system or an in-circuit emulator. Since the experiments focus on interfacing the microcontroller, a good set of laboratory test and measurement instruments is recommended. A basic voltmeter and a logic probe will go a long way in debugging hardware. A logic probe may be built simply be connecting an LED to a 470-ohm resistor. Laboratory studies, especially for demanding applications, would benefit from a logic analyzer and an oscilloscope. The Hewlett Packard / Agilent Technologies HP54645D mixed signal storage oscilloscope was used in the development of the experiments in the book. Such oscilloscopes are particularly suited for microcontroller circuits, since they display both digital and analog information. The digital and analog signals may be stored and analyzed, similar to features found in logic analyzers. They also measure times and voltages. The chapters follow a logical order. Both assembly language and C language experiments are presented. Being a lower-level language, assembly is a better way to start working with the microcontroller. With an understanding of assembly language code, writing C code becomes relatively straightforward. Those readers xii

who wish to write applications in assembly language may skip sections dealing with C. On the other hand, strictly speaking, readers who would like to write the code in C but wish not to deal with assembly may skip sections on assembly. However, these readers are still advised at least to read the sections on assembly language, since a low-level understanding of the microcontroller aids in writing efficient and effective high-level code in the long run. Those who wish to build their own 8051-based microcontroller system are recommended to start from Chapter 1 and read the entire book before they build the system. In our experience, such review provides a useful general understanding, and saves time in the long run. The reader is assumed to be familiar with digital logic (gates and flip/flops). Chapter 1 gives the fundamental concepts of microcontrollers. It also introduces the properties of the Intel 8051 and Siemens 80C515 microcontrollers. Chapter 2 discusses Intel's MCS-51 assembly language, which is used by all members of this microcontroller family. The instruction set is partitioned into three logical sets: data transfer instructions, data manipulation instructions, and program flow control instructions. Illustrative code is given for each instruction. The examples focus on a single machine instruction at a time. A brief overview of the everexpanding family of 8051-based microcontrollers concludes the chapter. Chapter 3 builds on the basic understanding of assembly language by introducing commonly used techniques. These techniques combine several different types of instructions to accomplish a meaningful task in an effective manner. Many of the examples given are from the monitor programs used by Rigel s 8051 family boards. These techniques include data manipulation and transfer, look-up tables, branching, string manipulation, software timing routines, and arithmetic routines. The examples are not optimized for speed or length, as it is typically done in application notes. Attention here is given to code readability and ease of understanding. A structured programming approach is taken. Tasks that can be identified as independent logical units are implemented as individual subroutines. This makes the programs more hierarchical and easier to dissect and comprehend. Chapter 4 introduces hardware experiments using assembly language. These experiments may be studied with any evaluation system, provided that a few push buttons, LEDs, seven-segment displays, and a speaker are available. In this book, such interface devices are called User Input/Output Devices (UIOD). A breadboard for prototyping is recommended. Experiments in Chapter 4 deal with the on-chip peripherals. Each experiment focuses on a separate peripheral. Digital input and output operations, counter and timer operations, interrupt routines, and analog-todigital conversion are presented. xiii

Chapter 5 introduces the C programming language. The hardware experiments given in Chapter 4 are written in C. Comparing C code to assembly code is an instructive effort in and of itself. Chapter 6 extends the applications to external circuitry. Examples combine many onchip facilities to accomplish useful tasks. The examples use both C and assembly language. The examples build upon many of the techniques and routines presented in Chapters 3, 4, and 5. Chapter 7 gives all the information necessary to build an 8051-based microcontroller system. Circuit diagrams and a bill of materials are given. The listing of a skeletal monitor, MINMON is provided along with instructions to extend the monitor. All software listed is available on Rigel s web site www.rigelcorp.com. Chapter 8 summarizes the steps involved in software development. It suggests further experiments and projects. Appendix A gives a very brief overview of the Reads51 IDE. Up-to-date information may be found in the various tutorials, quick start sheets and user s guides available on Rigel s web site. Appendix B reviews the C programming language. Appendix B is a good place to start for those who are new to C. The material is not intended to be an exhaustive study of the language. The reader is referred to the numerous textbooks on the subject for in-depth information. Appendix C presents the number systems used in this textbook. Binary, hexadecimal, binary-coded decimal, and two s complement formats are discussed. Appendix D is a compilation of information sources for the 8051. Manufacturers of chips, boards, and test equipment as well as parts suppliers and software companies are listed. As mentioned, the example code given is not optimized for speed or length. This book does not intend to replace the manufacturer's data books or application notes. It is intended as a comprehensive introductory book. The authors think that the reader may attempt almost any applications development after reading this book. Experienced programmers or persons familiar with microcontrollers in general, but not well acquainted with the 8051 family of microcontrollers may use the book as a cookbook of ideas, example code, and applications circuitry. The subject of embedded control and microcontrollers is a very rapidly changing field. Even mature architectures like the 8051 display a flurry of activity as new members of the family are introduced and new and more powerful development tools are made available. Much information and many resources are available on the web. We strongly suggest that the reader closely follow the field by periodically checking the relevant web sites. Appendix D lists manufacturers and information sources as of November 2000. xiv

Perhaps the most significant contribution of this textbook is its hands-on approach to the many experiments. Simply implementing the experiments would give an otherwise uninitiated reader a good general feel for embedded control. After many years of developing industrial embedded control systems, we still enjoy constructing experiments for an educational audience. We hope you find it enjoyable and informative. We were surprised to find out how many of our readers actually built their own system from scratch. Hearing from you has always been our greatest satisfaction. Please drop us a line. Sencer Yeralan and Helen Emery Gainesville, Florida October 2000 xv