1. Trang chủ
  2. » Công Nghệ Thông Tin

Interfacing PIC Microcontrollers 2 pptx

10 319 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 167,42 KB

Nội dung

Labcenter Electronics www .labcenter.co.uk Manufacturer and supplier of Proteus VSM electronic design system Microchip Technology Inc. www .microchip.com Manufacturer of the PIC microcontroller range and MPLAB IDE Custom Computer Services, Inc. www .ccsinfo.com Manufacturer and supplier of PIC CCS ‘C’ Compilers Data References and Trademark Acknowledgements Microchip Technology Inc., RS Components, Fairchild, Intel, Freescale (Motorola), National Semiconductor, Sensor Technics, Densitron, Honeywell, SGS Thomson, Maxim, ST Microelectronics, HBM, ARM, AVR Atmel, Texas, Vishay. I would also like to thank the dedicated teachers of engineering that I have worked with, especially Melvyn Ball at Hastings College and Chris Garrett at the University of Brighton, and, of course, Julia Bates. Martin Bates Hastings, UK Links, References and Acknowledgements x Else_IPM-BATES_fm.qxd 7/20/2006 11:52 AM Page x Contents Part 1 Microcontroller 1 1 PIC Hardware 3 Processor System 4 PIC 16F877 Architecture 8 PIC Instruction Set 18 Special Function Registers 25 2 PIC Software 35 Assembly Language 37 Software Design 44 ‘C’ Programming 47 3 Circuit Simulation 55 Basic Circuit 56 Software Debugging 63 Hardware Testing 65 Hardware Implementation 70 Program Downloading 73 Else_IPM-BATES_fm.qxd 7/20/2006 11:52 AM Page xi xi Contents xii Part 2 Interfacing 77 4 Input & Output 79 Switch Input 79 Switch Debouncing 81 Timer and Interrupts 84 Keypad Input 87 7-Segment LED Display 88 Liquid Crystal Display 90 5 Data Processing 101 Number Systems 101 Conversion 106 Variable Types 110 Arithmetic 112 6 Calculate, Compare & Capture 121 Calculator 121 Pulse Output 128 Period Measurement 130 7 Analogue Interfacing 141 8-bit Conversion 141 10-bit Conversion 145 Amplifier Interfaces 149 Else_IPM-BATES_fm.qxd 7/20/2006 11:52 AM Page xii Contents xiii Transient & Frequency Response 160 Instrumentation Amplifier 161 Current Loop 163 Comparators 165 Op-amp Selection 168 Analogue Output 168 Part 3 Systems 177 8 Power Outputs 179 Current Drivers 179 Relays & Motors 183 Power Output Interfacing 185 Motor Interfacing 189 9 Serial Communication 201 USART 201 SPI 205 I 2 C 210 10 Sensor Interfacing 223 Sensors 223 Sensor Types 228 Amplifier Design 236 Weather Station 238 Else_IPM-BATES_fm.qxd 7/20/2006 11:52 AM Page xiii 11 System Design 249 Base System 249 Memory System 259 Other PIC Chips 266 System Design 270 Other MCU Families 274 Answers to Assessment Questions 279 Index & Abbreviations 291 Contents xiv Else_IPM-BATES_fm.qxd 7/20/2006 11:52 AM Page xiv Part 1 Microcontroller Else_IPM-BATES_ch001.qxd 6/27/2006 10:04 PM Page 1 1 This page intentionally left blank 2 1 PIC Hardware The microcontroller is simply a computer on a chip. It is one of the most important developments in electronics since the invention of the microprocessor itself. It is essential for the operation of devices such as mobile phones, DVD players, video cameras, and most self-contained electronic systems. The small LCD screen is a good clue to the presence of an MCU (Microcontroller Unit) – it needs a programmed device to control it. Working sometimes with other chips, but often on its own, the MCU provides the key element in the vast range of small, programmed devices which are now commonplace. Although small, microcontrollers are complex, and we have to look carefully at the way the hardware and software (control program) work together to understand the processes at work. This book will show how to connect the pop- ular PIC range of microcontrollers to the outside world, and put them to work. To keep things simple, we will concentrate on just one device, the PIC 16F877, which has a good range of features and allows most of the essential techniques to be explained. It has a set of serial ports built in, which are used to transfer data to and from other devices, as well as analogue inputs, which allow measurement of inputs such as temperature. All standard types of microcontrollers work in a similar way, so analysis of one will make it possible to understand all the others. The PIC 16F877 is also a good choice for learning about micro-controllers, because the programming language is relatively simple, as compared with a microprocessor such as the Intel Pentium™, which is used in the PC. This has a powerful, but complex, instruction set to support advanced multimedia applications. The supporting documentation for the PIC MCU is well designed, Else_IPM-BATES_ch001.qxd 6/27/2006 10:04 PM Page 3 3 and a development system, for writing and testing programs, can be down- loaded free from the Microchip website (www.microchip.com). Processor System The microcontroller contains the same main elements as any computer system: • Processor • Memory • Input/Output In a PC, these are provided as separate chips, linked together via bus connec- tions on a printed circuit board, but under the control of the microprocessor (CPU). A bus is a set of lines which carry data in parallel form which are shared by the peripheral devices. The system can be designed to suit a partic- ular application, with the type of CPU, size of memory and selection of input/output (I/O) devices tailored to the system requirements. In the microcontroller, all these elements are on one chip. This means that the MCU for a particular application must be chosen from the available range to suit the requirements. In any given circuit, the microcontroller also tends to have a single dedicated function (in contrast to the PC); this type of system is described as an embedded application (Figure 1.1). Processor In a microprocessor system or a microcontroller, a single processor block is in charge of all input, output, calculations and control. This cannot operate without a program, which is a list of instructions that is held in memory. The Interfacing PIC Microcontrollers 4 CPU Memory Output Input Figure 1.1 Block diagram of a basic microprocessor system Else_IPM-BATES_ch001.qxd 6/27/2006 10:04 PM Page 4 program consists of a sequence of binary codes that are fetched from memory by the CPU in sequence, and executed (Figure 1.2). The instructions are stored in numbered memory locations, and copied to an instruction register in the CPU via the data bus. Here, the instruction controls the selection of the required operation within the control unit of the processor. The program codes are located in memory by outputting the address of the instruction on an address bus. The address is generated in the program counter, a register that starts at zero and is incremented or modified during each instruction cycle. The busses are parallel connections which transfer the address or data word in one operation. A set of control lines from the CPU are also needed to assist with this process; these control lines are set up according to the requirements of the current in- struction. Decoding the instruction is a hardware process, using a block of logic gates to set up the control lines of the processor unit, and fetching the instruction operands. The operands are data to be operated on (or information about where to find it) which follows most instructions. Typically, a calculation or logical operation is carried out on the operands, and a result stored back in memory, or an I/O action set up. Each complete instruction may be 1, 2 or more bytes long, which includes the operation (instruction) code (op-code) itself and the operand/s (1 byte ϭ 8 bits). PIC Hardware 5 Program Memory Address Instruction 0000 10010011 0001 01010001 0002 10000100 0003 00011001 0004 01011100 0005 xxxxxxxx 0006 xxxxxxxx etc etc CPU Instruction Register Decoder Logic Execution Logic Control lines to system Data bus Address bus Program Counter Figure 1.2 Processor program execution Else_IPM-BATES_ch001.qxd 6/27/2006 10:04 PM Page 5 . Output Interfacing 185 Motor Interfacing 189 9 Serial Communication 20 1 USART 20 1 SPI 20 5 I 2 C 21 0 10 Sensor Interfacing 22 3 Sensors 22 3 Sensor Types 22 8 Amplifier Design 23 6 Weather Station 23 8 Else_IPM-BATES_fm.qxd. 23 8 Else_IPM-BATES_fm.qxd 7 /20 /20 06 11: 52 AM Page xiii 11 System Design 24 9 Base System 24 9 Memory System 25 9 Other PIC Chips 26 6 System Design 27 0 Other MCU Families 27 4 Answers to Assessment Questions 27 9 Index. Acknowledgements x Else_IPM-BATES_fm.qxd 7 /20 /20 06 11: 52 AM Page x Contents Part 1 Microcontroller 1 1 PIC Hardware 3 Processor System 4 PIC 16F877 Architecture 8 PIC Instruction Set 18 Special Function Registers 25 2 PIC Software

Ngày đăng: 02/07/2014, 04:21

TỪ KHÓA LIÊN QUAN

w