6502 Applications
Total Page:16
File Type:pdf, Size:1020Kb
6502 APPLICATIONS RODNAY ZAKS SYBEX BERKELEY • PARIS • DUSSELDORF Cover Art: Daniel Le Noury Every effort has been made to supply complete and accurate information. How ever, Sybex assumes no responsibility for its use; nor any infringements of patents or other rights of third parties which would result. No license is granted by the equipment manufacturers under any patent or patent rights. Manufacturers reserve the right to change circuitry at any time without notice. In particular, technical characteristics and prices are subject to rapid change. Comparisons and evaluations are presented for their educational value and for guidance principles. The reader is referred to the manufacturer’s data for exact specifications. Copyright © 1979 SYBEX Inc. World Rights reserved. No part of this publica tion may be stored in a retrieval system, copied, transmitted, or reproduced in any way, including, but not limited to, photocopy, photography, magnetic or other recording, without the prior written permission of the publisher. Library of Congress Card Number: 78-73740 ISBN 0-89588-015-6 Printed in the United States of America Printing 109 8 7 TABLE OF CONTENTS I. INTRODUCTION.................................................11 II. THE INPUT OUTPUT CH IPS........................... 15 Introduction. Basic Definitions. The 6520 PIA. The 6522. Programming the 6522. The 6530 ROM -RAM I/O Timer (RRIOT). The 6532. Summary. III. 6502 SYSTEMS.......................................................64 Introduction. Standard 6502 System. The KIM-1. TheSYM-1. The AIM 65. Other boards. IV. BASIC TECHNIQUES......................................... 78 Introduction SECTION 1: THE TECHNIQUES Relays. Switches. Speaker. A Morse Generator. Time o f Day Clock. A Home Control Program. A Telephone Dialer. SECTION 2: COMBINA TIONS OF TECHNIQUES Introduction. Generating a Siren Sound. Sensing an Input Pulse. Pulse Measurement. A Simple Music Program. KIM Traffic Control. Learn the Multiplication Table. Summary. V. INDUSTRIAL AND HOME APPLICATIONS 145 Introduction. A Traffic Control System. Dot Matrix LED. Displaying Switch Values. Tone Generation. Music. A Burglar Alarm. DC Motor Control. Analog to Digital Conversion (A Heat Sensor). Summary. VI. THE PERIPHERALS..................................216 Introduction. Keyboard. Paper Tape Reader or ASCII Keyboard. Micro printer. Summary. VII. CONCLUSIONS 241 APPENDIX A - A 6502 ASSEMBLER IN BASIC.... 243 Introduction. General Description. Usingthe Assembler. Syntax. HP2000F BASIC. APPENDIX B -MULTIPLICATION GAME: THE PROGRAM..................................................259 APPENDIX C - PROGRAM LISTINGS (Chapter 4 Part 1) ............................................... 262 - Program 4-1: Morse - Program 4-2: Time o f Day - Program 4-3: Home Control - Program 4-4: Phone Dialer APPENDIX D - HEXADECIMAL CONVERSION TABLE..................................... 273 APPENDIX E - ASCII CONVERSION TABLE..........274 APPENDIX F - 6502 INSTRUCTIONS 275 PREFACE This book presents practical application techniques for the 6502 microprocessor. It assumes an elementary knowledge of microproces sor programming on the level of the preceding book in this series (Ref erence C202: Programming the 6502). Understanding how to program the microprocessor chip itself (the 6502) is only a prerequisite for the actual programming of a microprocessor board connected to real devices. The next problem is to learn how to write actual applica tion programs involving the input/output ports and other facilities available in a real system. This book addresses itself to this problem. It will present the techniques and programs required for typical appli cations, using the actual input-output chips available on a board. The programs presented in this book will require a minimum of ac tual hardware to be effectively implemented. The user is therefore en couraged to practice the concepts and techniques presented here on actual hardware. A realistic description of possible applications boards will be presented. The programs are applicable to any 6502-based mi crocomputer board such as the KIM, the SYM, the AIM 65, or others. Many programs can be run directly on one or more of these boards while others will require some changes. However, the concepts and techniques are common to all. The application programs presented in this book will allow the reader to build a complete home alarm system, which includes fire detection and other features, an electronic piano, a motor speed regulator, an appli ance or hobby-train controller, a time-of-day clock, a simulated traf fic control system, a morse code generator, an industrial control loop for temperature control, including analog-to-digital conversion, and more. This book is intended to teach all the basic skills required to apply the 6502 to real life applications. It is preceded in our 6502 series by “ C202 - Programming the 6502,” and followed by “ G402 - 6502 Games.” ACKNOWLEDGEMENTS Many persons have contributed to the checkout, development or im provement of these programs. Special acknowledgements are due by the author to: Pierre Le Beux, Daniel David, Jaff Lin, Eric Martinot, Tricourt, and to Eric Novikoff (ASM65 assembler). The following persons have also contributed valuable comments on the final draft of the manuscript, and their contribution is gratefully acknowledged: John McClenon, Doug Trusty, Philip Hooper, Daniel David, Robert Chitsum, and John Smith. The following companies have provided access to valuable informa tion and resources at an early date, and their contribution is gratefully acknowledged: Rockwell International, Synertek Systems, Apple. The listings of Chapter Four, part 1 have been produced on a Rockwell System 65. The listings of part 2 have been produced with the ASM65 assembler listed in Appendix A. TABLE OF ILLUSTRATIONS 1- 1 Standard Programming Form ................................................. 14 2- 1 Typical P IO ................................................................................ 16 2-2 The 6520 P IA ............................................................................. 20 2-3 6520 Internal Architecture ........................................................ 21 2-4 Buffer A ..................................................................................... 23 2-5 Buffer B ..................................................................................... 23 2-6 6520 Memory M ap.................................................................... 24 2-7 6520 Register Selection ............................................................. 25 2-8 6520 Control Registers ............................................................. 25 2-9 6520 CA2 C ontrol ..................................................................... 26 2-10 6520 CB2 C ontrol ..................................................................... 26 2-11 Interrupt Control (CA1, CB1 Inputs) ...................................... 27 2-12 Identifying the P IO ................................................................... 29 2-13 Identifying the Ports.................................................................. 30 2-14 6522 Internal Architecture....................................................... 31 2-15 6522 VIA Memory M ap............................................................ 32 2-16 6522 Registers...............................................:.......................... 32 2-17 Using the 6522: STA D D R A .................................................... 33 2-18 Using the 6522: STA DDRB ..................................................... 34 2-19 Using the 6522: STA O R A ....................................................... 35 2-20 Using the 6522: LDA ORB ........................................................ 35 2-21 Peripheral Control Register...................................................... 36 2-22 Interrupt Flag Enable Register (IFR /IER ).............................. 37 2-23 Control Lines Function (ACR) ................................................ 37 2-24 PCR Detailed Operation (courtesy:Rockwell) ....................... 38 2-25 Continued: PCR Detailed Operation...................................... 38 2-26 Reading Data When Ready ....................................................... 39 2-27 6522-Auxiliary Control Register ............................................. 40 2-28 Interrupt Registers .................................................................... 41 2-29 6522-Auxiliary Control Register Controls Timer 1 Modes... 44 2-30 6522-Auxiliary Control Register Selects Timer 1 Operating Modes ..................................................................... 44 2-31 Timer Addressing...................................................................... 45 2-32 Timer 1 in Free Running M ode ................................................ 46 2-33 Shift Register Control............................................................... 46 2-34 6522 Register Selection is Direct............................................... 48 2-35 Connecting Multiple 6522’s-Generating an IR Q ................... 52 2-36 6530 Internal Architecture ........................................................ 60 2-37 6530 Memory M ap .................................................................... 61 2-38 6532 Internal Architecture ........................................................ 62 2-39 6532 Addressing ........................................................................ 63 2- 40 Comparison Chart of the Four PIO’s .......................