ebook img

Pascal For Electronics And Communications PDF

110 Pages·2014·1.89 MB·English
by  MeadowsR. G
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Pascal For Electronics And Communications

PASCAL for Electronics and Communications Richard Meadows BSc, MSc, PhD, FIEE, CEng, FIElecIE, MlnstP, ARCS Head of Electronic and Communications Engineering The Polytechnic of North London PITMAN PUBLISHING 128 Long Acre, London WC2E 9AN A Division of Longman Group UK Limited © R Meadows 1985 First published in Great Britain 1985 This edition published in the Taylor & Francis e-Library, 2005. “To purchase your own copy of this or any of Taylor & Francis or Routledge’s collection of thousands of eBooks please go to www.eBookstore.tandf.co.uk.” Reprinted 1987, 1988, 1989 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording and/or otherwise without either the prior written permission of the Publishers or a licence permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, 33–34 Alfred Place, London WC1E 7DP. This book may not be lent, resold, hired out or otherwise disposed of by way of trade in any for of binding or cover other than that in which it is published, without the prior written permission of the publishers. ISBN 0-203-16888-7 Master e-book ISBN ISBN 0-203-26417-7 (Adobe eReader Format) ISBN 0 273 02155 9 (Print Edition) Contents 1 Introduction 1 1.1 Introduction: computer hardware and software 1 1.2 PASCAL: origins and merits 4 1.3 An example of a program written in PASCAL 5 1.4 An outline of the steps involved in writing and running PASCAL programs 8 2 PASCAL: Some Fundamentals 11 2.1 Introduction and summary 11 2.2 Identifiers: syntax, standard and reserved words 11 2.3 Syntax diagrams 12 2.4 Constants, variables and their declaration 13 2.5 Assignment statements 15 2.6 Values and expressions: some introductory facts 16 2.7 Obtaining an output from a program: WRITE and WRITELN statements 18 2.8 Comments: use to aid program understanding 19 2.9 Beginning to write simple programs 20 2.10 Formatting the output 21 2.11 Inputting data to a program: READ and READLN statements 23 2.12 Simple and compound statements 24 2.13 TYPE: user-defined enumerated scalar and subrange data types 25 Exercises 2 29 3 Expressions, Calculations and Standard Functions 30 3.1 Introduction and summary 30 3.2 Arithmetical calculations: REAL expressions and arithmetic operators 30 3.3 Integer arithmetic: DIV and MOD operators and expressions 31 3.4 Comparison operators and introduction to decision making 32 iv 3.5 Boolean operators and expressions 33 3.6 Standard arithmetic functions 35 3.7 Standard functions involving characters 38 Exercises 3 40 4 Statements for Choice, Selection and Repetition 44 4.1 Introduction and summary 44 4.2 The IF statements 44 4.3 The CASE statement 46 4.4 Repetition 1: the WHILE…DO statement 47 4.5 Repetition 2: the REPEAT…UNTIL statement 49 4.6 Repetition 3: the FOR…TO…DO statement 50 4.7 The GOTO statement 51 Exercises 4 52 5 Procedures and Functions 57 5.1 Introduction and summary 57 5.2 PASCAL programs: basic structure, order, global and local variables 57 5.3 Simple procedures 58 5.4 Procedures with value parameters: passing information to a procedure 60 5.5 Procedures with variable parameters: passing information back from a procedure 62 5.6 Using global variables with procedures to input and output information 64 5.7 User-defined functions 65 Exercises 5 67 6 The Use of Arrays and Files 72 6.1 Introduction and summary 72 6.2 Arrays: their form and declaration 72 6.3 The application of arrays in programs 75 6.4 Introduction to the use of files 80 6.5 File declaration 80 6.6 Reading from and writing to files: RESET and REWRITE statements 82 6.7 TEXT files 84 v 6.8 The applications of files in programs 86 Exercises 6 89 7 Some Further Topics: Packed Arrays, Records and Sets 91 7.1 Introduction and summary 91 7.2 Packed arrays and strings 91 7.3 Records 93 7.4 Sets 95 Exercises 7 96 Answers to Exercises 98 Preface This book has been written to act as a practical guide to learning how to write programs in Standard PASCAL. No prior knowledge of computing or the PASCAL language is assumed, nor is it needed to follow the text. The aim of the book is to provide students and engineers new to PASCAL with the knowledge and understanding of this powerful language so that they can construct their own programs to solve a wide variety of problems. The text follows a logical sequence and at all stages the concepts being introduced are backed by practical program examples drawn principally from basic electronics, circuit theory and communications. Exercise problems are also given at the end of each Chapter (other than the first introductory one) and typical program solutions for these are given in the answer section at the end of the book. Finally, I should like to express my thanks to my colleagues Mike Brinson and Larry Parsons for their many helpful discussions and comments and as always my Editor, John Cushion, for his continued support. Richard Meadows April 1985 Dedication To my wife Lynn and students at PNL and City College. 1 Introduction 1.1 Introduction: computer hardware and software Before starting PASCAL, this chapter briefly reviews some of the important terms associated with computers and programming and at the same time gives a simple insight into how a digital computer operates to “translate” and “run” programs, whether they are written in PASCAL or some other computer language. HARDWARE: the physical components of a computer system Hardware is used to describe any component or unit used in the construction of a digital computer system. Input devices, microprocessor chips, memory chips, I/O chips, auxiliary stores, output devices are all examples of hardware. Fig. 1.1 shows a block diagram of the basic units—the hardware— associated with a typical computer system. The function of these basic units is as follows: Input devices Input devices are required to input data, instructions, programs, etc. to the central processing unit of the computer. They enable the user to communicate with computers. Examples of input devices include: Keyboard devices (similar to electric typewriters). Transducers plus analog-to-digital (A-to-D) converters to convert the transducer signals, e.g. electrical signals from temperature, light, pressure sensors, to the digital binary-coded signals that the computer can “understand”. Tape recorders or cassette players containing programs, data, etc. in digital form stored on magnetic tape. Disc drive units—more readily accessible from the computer’s point of view and therefore much speedier than cassettes—where programs, etc. are stored on magnetic discs. Output devices Output devices are required to translate the computer output, which is in binary form, to human-recognisable form or a form suitable for controlling a machine, etc.. Examples of output devices include: 2 PASCAL FOR ELECTRONICS AND COMMUNICATIONS Printers (to provide “hardcopy” of results). Visual display units (normally abbreviated to VDU) which display results, graphics, games, etc. on a tv- type screen). Lamps Light-emitting diodes (LEDs). Liquid-crystal displays (LCD). Speech devices. Digital-to-analog (D-to-A) converters for converting the computer output to an analog or continuous-type signal form, which, for example, may then be amplified and used to control a specific function in a process or machine. Input/output unit (I/O unit) The input/output (normally abbreviated to I/O) unit forms the interface between the computer and the input and output devices. The I/O unit feeds information in the correct binary- coded form and sequence into the central processor unit from input devices, and also outputs results from the computer to output devices. The input and output lines may enter a common I/O unit which may be programmed to control both the input and output data flow to and from the central processor; or, alternatively, the I/O unit function may be split into two separate devices. The term input port is used to denote both the entry point and/or the device handling input data; the term output port to denote the output point/device for output data. Peripheral devices All devices, such as input and output devices, connected to the I/O ports are known as peripherals. The central processing unit (CPU) The actual computer, as distinct from its peripheral devices, is known as the central processing unit, the CPU. The CPU consists essentially of three basic units: a memory unit, an arithmeticlogic unit, and a control unit. The operation of these three sub-units making up the CPU are closely interrelated. In many microcomputers all three may be contained in as few as two or three or even a single integrated circuit chip. The functions of the three CPU units are as follows: The store or memory unit The store or memory holds the data and instructions of the program which have been fed into the CPU via the I/O unit. It also holds the permanently stored programs (operating systems programs) that permit the operation of the computer system immediately after switch-on. The arithmetic and logic unit (ALU) The ALU performs arithmetic operations (+ − × ÷) and logic decisions on the data fed to it from the memory unit, according to the instructions of the program. The control unit (CU) The control unit interprets and carries out the instructions of the program in the exact sequence—instruction by instruction—as stated by the program held in the memory unit. The CU is the master unit controlling the processing of all instructions and the movement of data to and from the input/ output devices to the memory unit and to and from the ALU. The clock A digital computer is the prime example of a digital-logic sequential system and as such requires a very accurate timing source to ensure perfect synchronism of all its step-by-step operations. The timing source controlling these operations in the CPU is known as the clock. The clock invariably consists of a crystal-controlled oscillator circuit which generates a continuous wavetrain of rectangular pulses of very stable frequency. These pulses are fed to all circuits in the computer system to ensure that they work in exact synchronism. Auxiliary storage devices In many applications the internal store or memory unit of the CPU will prove inadequate. There will not be enough memory space to store all program instructions, data, results, etc. To overcome this problem, auxiliary stores are used. These consist of magnetic devices where programs, data, etc. are stored on magnetic tapes and magnetic discs. A tape of 100m length is capable of storing about one million characters, whilst a disc may store 200+ million. Information from auxiliary stores is fed via the I/O

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.