С and the Programming for Multitasking. Thomas W. Schultz. Purdue University West Lafayette, Indiana

Similar documents
BASIC INTERFACING CONCEPTS

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

EMBEDDED SYSTEMS: Jonathan W. Valvano INTRODUCTION TO THE MSP432 MICROCONTROLLER. Volume 1 First Edition June 2015

THE AVR MICROCONTROLLER AND EMBEDDED SYSTEMS. Using Assembly and С

SOME ASSEMBLY REQUIRED

THE 8051 MICROCONTROLLER

PROGRAMMING AND CUSTOMIZING

EC 6504 MICROPROCESSOR AND MICROCONTROLLER

Programming 8-bit PIC Microcontrollers in С

THE 8051 MICROCONTROLLER

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Acknowledgments About the Author

Verilog HDL. A Guide to Digital Design and Synthesis. Samir Palnitkar. SunSoft Press A Prentice Hall Title

SECTION A. (i) The Boolean function in sum of products form where K-map is given below (figure) is:

Diploma in Embedded Systems

PROBLEM SOLVING WITH FORTRAN 90

Microprocessor Theory

acret Ameya Centre for Robotics & Embedded Technology Syllabus for Diploma in Embedded Systems (Total Eight Modules-4 Months -320 Hrs.

A Tutorial Introduction 1

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

ощ 'ршорвшэш! цвн-эориэу ощ 'sajbpossv # PIPG DUJ 'ssjmoossv ^ PIPG pipa w н OX ЛЮН VAV


Embedded Systems. Embedded Programmer. Duration: 2 weeks Rs Language and Tools. Embedded System Introduction. Embedded C programming

Embedded Controller Programming 2

B.Sc II Year Computer Science (Optional)

VALLIAMMAI ENGINEERING COLLEGE. SRM Nagar, Kattankulathur DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

The Definitive Guide to the ARM Cortex-M3

Preface Introduction... 23

Microcontrollers. Principles and Applications. Ajit Pal +5 V 2K 8. 8 bit dip switch. P2 8 Reset switch Microcontroller AT89S52 100E +5 V. 2.

Microcontroller & Interfacing

Table of Contents at a Glance

QUESTION BANK CS2252 MICROPROCESSOR AND MICROCONTROLLERS

Serial Communications: A C++ Developer's Guide

Arduino Internals. Dale Wheat. Apress

Contents Part I Basic Concepts The Nature of Hardware and Software Data Flow Modeling and Transformation

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Internetworking With TCP/IP

Microprocessor and Microcontroller question bank. 1 Distinguish between microprocessor and microcontroller.

Pearson New International Edition. The 8051 Microcontroller and Embedded Systems Mazidi Mazidi McKinlay Second Edition

PROGRAMMABLE LOGIC CONTROLLERS. Wiley USING CODESYS A PRACTICAL APPROACH TO IEC. Dag H. Hanssen Institute of Engineering and Safety,

Computer Architecture

The Verilog Hardware Description Language

Computer Organization and Microprocessors SYLLABUS CHAPTER - 1 : BASIC STRUCTURE OF COMPUTERS CHAPTER - 3 : THE MEMORY SYSTEM

C# Programming: From Problem Analysis to Program Design. Fourth Edition

WITH C+ + William Ford University of the Pacific. William Topp University of the Pacific. Prentice Hall, Englewood Cliffs, New Jersey 07632


PART B UNIT II PART A


CHAPTER - 2 : DESIGN OF ARITHMETIC CIRCUITS

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

Sencer Yeralan and Helen Emery Gainesville, Florida January 2000

Quadros. RTXC Kernel Services Reference, Volume 1. Levels, Threads, Exceptions, Pipes, Event Sources, Counters, and Alarms. Systems Inc.

MLR INSTITUTE OF TECHNOLOGY DUNDIGAL , HYDERABAD QUESTION BANK

Practical C++ Programming

Chapter 4. Enhancing ARM7 architecture by embedding RTOS

Fundamentais of Programmable Logic Controllers, Sensors, and Communications. Jon Stenerson

Short Term Courses (Including Project Work)

Description of the Simulator

EMBEDDED Systems. Functions. MODULE- 1 C programming with data Structure Introduction to C. Array and String. Control Flow Statements In C

Tasks and Objectives: Certified LabVIEW Architect

C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming

CS401 - Computer Architecture and Assembly Language Programming Glossary By

MSP430 Microcontroller Basics

1. Attempt any three of the following: 15

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY COMPUTER ARCHITECURE- III YEAR EEE-6 TH SEMESTER 16 MARKS QUESTION BANK UNIT-1

COS 140: Foundations of Computer Science

MPI: A Message-Passing Interface Standard

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING YEAR : III SEM : VI

Linux Kernel Architecture

Data Communications. From Basics to Broadband. Third Edition. William J. Beyda

Mechanism Design using Creo Parametric 3.0

Internetworking With TCP/IP

Chapter 4. MARIE: An Introduction to a Simple Computer. Chapter 4 Objectives. 4.1 Introduction. 4.2 CPU Basics

MICROPROCESSOR Architecture, Programming and Interfacing SUNIL MATHUR. Assistant Professor Maharaja Agrasen Institute of Technology Delhi

Table of Contents. Chapter Description Page. 1. PLC Fundamentals Ladder Logic

CONTENTS CHAPTER 1: NUMBER SYSTEM. Foreword...(vii) Preface... (ix) Acknowledgement... (xi) About the Author...(xxiii)

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS

Intel Architecture Software Developer s Manual

DEPARTMENT OF ECE QUESTION BANK SUBJECT: MICROPROCESSOR AND MICROCONTROLLER UNIT-1 PART-A (2 MARKS)

Microprocessors and Microcontrollers. Assignment 1:

Excel Programming with VBA (Macro Programming) 24 hours Getting Started

Embedded and Real-Time Operating Systems

Understanding the Concepts and Features of Macro Programming 1

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

ARM CORTEX-R52. Target Audience: Engineers and technicians who develop SoCs and systems based on the ARM Cortex-R52 architecture.

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Microprocessors and Interfacng. Question bank

Embedded System Curriculum

LabVIEW Basics I: Introduction Course

16-Bit Intel Processor Architecture

7. Discuss the hardware signals and superscalar architecture of Pentium BTL 2 Understand

1. (a) Draw the internal architecture of 8085? Explain each block. (b) What are the special functions of GPRs in 8086? And explain them?

ARM Processors for Embedded Applications

Digital VLSI Design with Verilog

ECE 354 Introduction to Lab 2. February 23 rd, 2003

PESIT Bangalore South Campus

Using the FreeRTOS Real Time Kernel

S.R.M. INSTITUTE OF SCIENCE & TECHNOLOGY SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Transcription:

С and the 8051 Programming for Multitasking Thomas W. Schultz Purdue University West Lafayette, Indiana PTR Prentice Hall Englewood Cliffs, New Jersey 07632

Preface Introduction Chapter 1 WHY THE 8051? xiv PLANNING xv PROGRAMMING LANGUAGES xv PROGRAMMING xvi MODULAR PROGRAMMING xvii 8051 HARDWARE xvii MULTITASKING xvii REVIEW AND BEYOND xviii Project Planning DO YOU HAVE A PROJECT? 1 SYSTEM PLANNING 3 HARDWARE/SOFTWARE TRADEOFFS HARDWARE PLANNING 8 SOFTWARE PLANNING 8 RULES FOR TASK PARTITIONING 9 REAL-TIME DATA FLOW DIAGRAMS

vi DEFINING TASK INTERFACES 10 HOW BUSY IS THE PROCESSOR? 11 SYSTEM INTEGRATION 12 TESTING AND MAINTAINING?! 12 SELF-TEST ROUTINES 13 CLOSURE ON DECISION MAKING 13 REVIEW AND BEYOND 14 Chapter 2 Three Languages WHY THESE THREE? 15 WHY NOT BASIC? 16 VARIABLES 17 SHORTHAND DEFINE AND LITERALLY 19 MEMORY SPACES 19 PORTS 22 EXAMPLE: LIGHTS TO SWITCHES 23 BITWISE OPERATORS 27 ROTATE AND SHIFT 30 ASSIGNMENT OPERATORS 34 IDENTIFYING BIT CHANGES 34 ARITHMETIC OPERATORS 35 LOGICAL OPERATORS 44 PRECEDENCE 46 REVIEW AND BEYOND 49 Chapter 3 Looping and Branching DECISIONS 51 FLOWCHARTS 51 STRUCTURED LANGUAGE 52 BRANCHING CONSTRUCTS 54 IF/THEN/ELSE 54 CONDITIONAL OPERATOR 56 SWITCH/DO CASE 56 LOOPING CONSTRUCTS 58 WHILE LOOP 60 ITERATIVE LOOP 63 EXAMPLE: TIME DELAY 65 REVIEW AND BEYOND 67 Chapter 4 Pointers and Based Variables STRENGTH OF С (AND PLM) 68

Chapter 5 ARRAYS 68 LOOK-UP TABLES 71 STRUCTURES 73 STRUCTURE TEMPLATE 75 ARRAY OF STRUCTURES 75 ARRAYS WITHIN STRUCTURES 76 MEMORY SPACES AND EFFICIENCY 79 ADDRESSES 79 POINTERS 80 UNIVERSAL POINTERS 80 ARRAY POINTERS 82 ARRAYS OF ARRAY POINTERS 84 STRUCTURE POINTERS 86 UNIONS 87 REVIEW AND BEYOND 89 Routines SUBROUTINES, PROCEDURES, AND FUNCTIONS 90 EASE OF UNDERSTANDING 92 NESTED ROUTINES 95 PASSING PARAMETERS 96 EXAMPLE: SAY NUMBER 96 RETURNING VALUES 101 EXAMPLE: READ AN A-D CONVERTER 103 EXAMPLE: SCAN A KEYBOARD 106 IN-LINE CODE ALTERNATIVES 107 SCOPE OF VARIABLES 108 STYLE SUGGESTIONS 113 REVIEW AND BEYOND 115 Chapter 6 Modular Program Development WHY MODULAR? 116 PROGRAM PIECES 117 THE DEVELOPMENT PROCESS 117 FILE NAMING CONVENTIONS 119 ASSEMBLER 119 EXAMPLE: STEPPER DRIVER ASM51 120 HEX FILES 125 COMPILER PL/M 125 EXAMPLE: STEP DRIVER PL/M 126 COMPILER С 129 EXAMPLE: STEPPER DRIVER С 129

viii LIBRARIES 133 LINKER/LOCATER 133 OVERLAYING 134 SHARING VARIABLES 134 SHARING SUBROUTINES/PROCEDURES/ FUNCTIONS 137 MIXING LANGUAGES 137 PARAMETER-PASSING CONVENTIONS 138 COMPATIBILITY BY TEST 139 EXAMPLE: ASSEMBLY LINKED TO PL/M OR С 140 CODE EFFICIENCY 141 REVIEW AND BEYOND 155 Chapter 7 8051 Family Hardware 156 TIMERS AND COUNTERS 157 EXAMPLE: A 1MSEC TIMER 158 OTHER MODES 160 TIMER2 160 INTERRUPTS 162 MORE OR LESS INTERRUPT SOURCES 163 REGISTER BANKS CONTEXT SWITCHING 164 THE 8051 UART 165 EXAMPLE: SERIAL BUFFERING 167 SHIFT REGISTER MODE 172 NINTH-BIT MODE 172 MEMORY EXPANSION FOR THE 8051 173 COMMERCIAL BOARDS 177 THE 8051 FAMILY MEMBERS 178 SPECIAL TIMER FEATURES IN THE 8051 EXPANDED FAMILY 178 REVIEW AND BEYOND 181 Chapter 8 Real-Time Ideas 182 BEYOND SINGLE-PROGRAM THINKING 182 WHAT IS "REAL TIME?" 182 TASKS 183 MULTITASKING 184 REAL-TIME HAND WARE REQUIREMENTS 185

IX WHY AN OPERATING SYSTEM FOR MULTITASKING? 185 HOW DO OPERATING SYSTEMS REALLY WORK? 186 DCX51 187 DCE51 189 RTXTINY 189 TWO BASIC GROUPS OF RTOS 190 USX 190 CMX 191 BYTE-BOS 191 OBSERVATIONS ON USX, CMX, BYTE-BOS, AND RTXC 192 REVIEW AND BEYOND 193 Chapter 9 Timing and Scheduling 194 KEEPING TRACK OF TIME 194 EXAMPLE: SOLENOID CYCLER 195 EXAMPLE: PULSE GENERATOR 200 EXAMPLE: SOLENOID CYCLER WITH RTOS 202 EXAMPLE: PULSE TASK WITH RTOS 209 EXAMPLE: REVIEW AND BEYOND 218 Chapter 10 Communication and Synchronization 219 TASK COMMUNICATION 219 SHARED VARIABLES FOR COMMUNICATION 219 SEMAPHORES AND SIGNALING 220 MESSAGES 221 COMPARING COMMUNICATION RESOURCES 221 RESOURCES, POOLS, AND LISTS 224 EXAMPLE: SOLENOID SEQUENCER II (KEY ENTRY) 225 SOLENOID SEQUENCER II WITH RTOS 236 REVIEW AND BEYOND 266 Chapter 11 Interrupt, Priority, and Context 267 INTERRUPT EVENTS 267 CONTEXT SWITCHING 267

X BUILT-IN INTERRUPT EVENTS 269 INTERRUPT HANDLERS 270 INTERRUPTS USING THE OPERATING SYSTEM 270 SETTING PRIORITY 271 EXAMPLE: ENVELOPE DETECTOR 273 EXAMPLE: MOTOR SPEED CONTROL SYSTEM 274 EXAMPLE: SPEED CONTROL WITHRTOS 287 REVIEW AND BEYOND 301 Chapter 12 Distributed Systems 302 USING SEVERAL CONTROLLERS 302 DIRECT PARALLEL 303 PARALLEL BUFFERED WITH HANDSHAKING 303 SERIAL INTERCONNECTION 303 SERIAL RING 304 NINTH-BIT TREE 304 RS-485 304 I 2 C BUS 305 BITBUS AS A NETWORK PROTOCOL 306 BITBUS AS A SYSTEM 306 IF YOU HATE TO PROGRAM! 307 PARTITIONING FOR DISTRIBUTED CONTROL 307 REVIEW AND BEYOND 308 Chapter 13 Multitasking in Review 309 BENEFITS OF RTOS 309 COSTS OF RTOS 310 Appendix A 8051 Assembly Instructions 312 A WORD ABOUT ACCESS AND ADDRESSES 312 DATA MOVING INSTRUCTIONS 313 BRANCHING INSTRUCTIONS 315 ARITHMETIC OPERATIONS 317 LOGICAL OPERATORS 319 DECIMAL INSTRUCTIONS 321

XI Appendix В Language Details 322 LANGUAGE SWITCHING HINTS 322 С COMPILER INFORMATION 325 Appendix С Hardware Information 336 Appendix D CONVENTIONAL 8051 FAMILY BOARDS 336 BITBUS CARDS 348 DEVELOPMENT RESOURCES 348 Vendors Addresses, Phones, and Products 351 COMPILERS AND ASSEMBLERS 352 REAL-TIME OPERATING SYSTEMS 352 CHIPS 353 COMMERCIAL BOARDS 354 BITBUS BOARDS 355 DEVELOPMENT HARDWARE 355 Appendix E RTOS Systems Calls 356 Index 361