Professor E. Ambikairajah UNSW Sydney

Similar documents
PIC Discussion. By Eng. Tamar Jomaa

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 2. PIC and Programming

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

ME 515 Mechatronics. A microprocessor

The University of Texas at Arlington Lecture 3

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

DERTS Design Requirements (1): Microcontroller Architecture & Programming

Midrange 8b PIC Microcontrollers. ECE Senior Design 14 February 2017

Chapter 2 Sections 1 8 Dr. Iyad Jafar

Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core

CHAPTER 4. PIC Microcontrollers. Assembly Language Programming. on-line FREE! Index Development systems Contact us

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

PIC 16F84A programming (II)

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

Lecture (04) PIC16F84A (3)

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Assembly Language programming (1)

TKT-3500 Microcontroller systems

Assembly Language Instructions

Processor design - MIPS

EEE111A/B Microprocessors

8051 Microcontrollers

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

ME 475 Lab2 Introduction of PIC and Programming. Instructor: Zhen Wang

Problem Set 1 Solutions

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

Module Contents of the Module Hours COs

Physics 335 Intro to MicroControllers and the PIC Microcontroller

Lecture 11: Control Unit and Instruction Encoding

2.2 THE MARIE Instruction Set Architecture

Mark II Aiken Relay Calculator

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Learning Objectives:

von Neumann Architecture Basic Computer System Early Computers Microprocessor Reading Assignment An Introduction to Computer Architecture

Basic Computer System. von Neumann Architecture. Reading Assignment. An Introduction to Computer Architecture. EEL 4744C: Microprocessor Applications

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

SOLUTIONS!! DO NOT DISTRIBUTE!!

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

THE MICROPROCESSOR Von Neumann s Architecture Model

CSE A215 Assembly Language Programming for Engineers

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

Computer Hardware Requirements for Real-Time Applications

EE 3170 Microcontroller Applications

8051 Instruction Opcodes In Hexadecimal Order

Fig 1. Block diagram of a microcomputer

Instruction Sets: Characteristics and Functions

ME 6405 Introduction to Mechatronics

Design and Implementation of a FPGA-based Pipelined Microcontroller

Chapter 5 Sections 1 6 Dr. Iyad Jafar

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

16.1. Unit 16. Computer Organization Design of a Simple Processor

Microcontrollers. Microcontroller

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Lecture 5. EEE3410 Microcontroller Applications Department of Electrical Engineering Assembly Language Programming (1)

Introduction to Microcontrollers

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

MicroProcessor. MicroProcessor. MicroProcessor. MicroProcessor

Microcontrollers. Introduction to the PIC 8-bit Midrange Family. ECE Senior Design 15 February 2017

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B DIGITAL SYSTEMS II Fall 1999

Educational Simulation of the RiSC Processor

8051 Microcontroller Assembly Programming

Computers in Engineering COMP 208. Computer Structure. Computer Architecture. Computer Structure Michael A. Hawker

COMPUTER STRUCTURE AND ORGANIZATION

COS 140: Foundations of Computer Science

MARIE: An Introduction to a Simple Computer

ECE 486/586. Computer Architecture. Lecture # 7

Micro-programmed Control Ch 15

Faculty of Engineering Systems & Biomedical Dept. First Year Cairo University Sheet 6 Computer I

COMPUTER ORGANIZATION & ARCHITECTURE

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

Machine Instructions vs. Micro-instructions. Micro-programmed Control Ch 15. Machine Instructions vs. Micro-instructions (2) Hardwired Control (4)

Micro-programmed Control Ch 15

AVR Microcontrollers Architecture

EC 413 Computer Organization

Computer and Hardware Architecture I. Benny Thörnberg Associate Professor in Electronics

Embedded Systems Design (630414) Lecture 1 Introduction to Embedded Systems Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

CPE300: Digital System Architecture and Design

These actions may use different parts of the CPU. Pipelining is when the parts run simultaneously on different instructions.

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Introduction to Programming

ELCT708 MicroLab Session #1 Introduction to Embedded Systems and Microcontrollers. Eng. Salma Hesham

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

MECE336 Microprocessors I

17. Instruction Sets: Characteristics and Functions

1. INTRODUCTION TO MICROPROCESSOR AND MICROCOMPUTER ARCHITECTURE:

Chapter 11: Interrupt On Change

Pipeline Processors David Rye :: MTRX3700 Pipelining :: Slide 1 of 15

JNTUWORLD. 1. Discuss in detail inter processor arbitration logics and procedures with necessary diagrams? [15]

Micro-programmed Control Ch 17

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Microprocessors and Microcontrollers Prof. Santanu Chattopadhyay Department of E & EC Engineering Indian Institute of Technology, Kharagpur

Hardwired Control (4) Micro-programmed Control Ch 17. Micro-programmed Control (3) Machine Instructions vs. Micro-instructions

Multi Cycle Implementation Scheme for 8 bit Microprocessor by VHDL

Mod-5: PIC 18 Introduction 1. Module 5

Transcription:

ELEC2117 Chapter 3a: PIC16F886 Instruction set Professor Eliathamby Ambikairajah Head of School of Electrical Engineering and Telecommunications, UNSW, Sydney 06 March 2017

Prof E Ambikairajah Instruction Set For a microcontroller to operate, it needs instructions (i.e. the commands that the microcontroller understands) on what to do in the form of a program. The PIC microcontroller executes instructions from program memory, starting from address zero (0000H), when the PIC is reset upon power-up. The PIC 16F886 is a Reduced Instruction Set Computer (RISC) and there are 35 instructions for it. One of the important characteristics of RISC architecture is that each instruction is contained in a single binary word and in our case, the binary word is 14-bits which contains (a) The instruction code (b) Address or data information. The RISC are well-optimised in terms of operating speed, simplicity in architecture and code compactness. The PIC microcontroller fetches a 14-bit instruction from the program memory in a single instruction cycle. 1

Clock Frequency and Instruction Cycle The overall speed of the microcontroller operation is solely dependent on the clock frequency. Clock speed for the PIC16F886: DC to 20 MHz (external clock) Internal Oscillator for the PIC16F886 is software selectable with the clock frequency ranging from 31 khz to 8 MHz The main oscillator frequency (internal or external) is divided by 4 to obtain an instruction cycle time. Four clock pulses are required to execute one instruction except for any program branches which need 8 clock cycles. Table below provides selected clock frequencies and the resulting instruction cycle durations. Overall power consumption of the microcontroller depends on the clock frequency. The higher the speed of operation, the higher the power dissipation. 2

Instruction Pipeline In many CPUs, the instruction is first fetched from the program memory and then executed (a sequential process) The combination of Harvard Architecture and RISC architecture used in PIC microcontrollers allows the program instructions to be pipelined. That is, while the CPU is executing one instruction, it is also fetching the next instruction. A Schematic diagram representing the pipeline process is shown below and it can be seen that while instruction 1 is being executed, instruction 2 is already being fetched. This simple design provides a doubling in execution speed. 3

Arithmetic Logic Unit (ALU) The ALU (shown below) of PIC16F886 receives data from the working register (W) and from the data memory or from the instruction. For many instructions, the results of the ALU can either be stored in the W register (d-bit =0) or stored in data memory (d-bit =1) For certain instructions, the d-bit is specified within the instructions After an arithmetic/logical operation, the ALU modifies the Z, DC, C bits of the STATUS register. 4

35 Instructions for the PIC16F886 5

Prof E Ambikairajah Instruction Descriptions The first column gives the Mnemonic together with the code, specifying the type of operand The second column gives the description of the instruction The third column provides the number of instruction cycles required to execute the instruction The fourth column provides the 14-bit opcode The fifth column shows the three bits (Z, DC, C) of the STATUS register affected by the instruction Description Add the contents of the W and f registers. If d = 0 the result is stored in the W register. If d = 1 the result is stored back in register f. Legend f - any memory location (7-bit) W - working register d destination bit (single bit) 6

11

13

14

Total 35 Instructions 14

Programming a Microcontroller A programmer can write programs for a computer in the following ways: High Level Language (BASIC, FORTRAN, C, C++ etc.) The programs written in high level programming language can run on a variety of computers. Writing a program in a high level programming language is much easier than an equivalent program written in an assembly language or in a machine language. Programs written in high-level languages are translated into machine code by a compiler. Assembly Language An assembly language is a machine dependent language and is also a low level programming language. The programmers must know the architecture of the processor for which the program is written. Assembly language programs are translated into machine code (ones and zeros) by an assembler. Assembly language is used when speed is essential or if an operation cannot be performed in a high-level language. Machine code These are zeros and ones and directly executed by a computer. This code is the lowest level of computer software and incredibly slow to write and error-prone. Each computer has its own machine code. 15

Prof E Ambikairajah Assembly Language Programming Assembly language programs have a simple format and there are four parts: LABEL A Label, An Instruction Mnemonic (op-code), An operand, A comment. Mnemonic (OP-code) Operand Comments start movlw 0xFF ;Load the W register with a constant The Machine code for movlw H FF would be: 11 0000 1111 1111 Move Literal to W Operand as a constant Hex FF The operands may be a register, a variable, a literal constant, a label, a memory address. Comments are optional but must begin with a semi-colon. 19

Microchip MPASM Assembler The assembler offered by Microchip is known as MPASM. The assembler program has to be processed by the assembler and in order to aid this process assembler directives are required. Assembly directives are commands and do not affect the operation of the microcontroller. A few MPASM examples are shown below: Assembler directive Directive description Processor 16f886 It must be written at the beginning of each program and it defines the type of the microcontroller EQU It used to replace a numeric value by a symbol. eg: Max EQU H 25 or PORTB EQU 06 ORG It specifies a location in program memory where the program starts: e.g ORG H 00 END Each program must end using this directive and the assembler immediately stops compiling. #include During compiling, it enables the assembler to use data contained in another file. e.g #include <p16f886.inc> The number representation in MPASM Assembler is shown below: Radix Examples Decimal D 342 or.342 Hexadecimal H 9D or 0x9D or 09D octal O 467 Binary b 10001101 ASCII A G 19

Prof E Ambikairajah Chapter 3a: Exercise 1 Calculate the clock frequency that will give an instruction cycle time of 1.753 micro seconds Using the information in page 5 (35 Instructions for the PIC16F886) the 14-bit opcode is given as 11 1111 1111 0010. Identify and explain the function/operation of the opcode. What is the duration of PIC16F886 instruction cycle? Briefly explain. Three PIC microcontrollers (A, B & C) have maximum clock speeds 10MHz, 20MHz, 24MHz respectively. Microcontroller A divides its clock by 4 to give one clock cycle, microcontroller B by 8, and microcontroller C by 12. Microcontrollers A & C take 2 clock cycles to perform an instruction, while microcontroller B takes three clock cycles. Which PIC microcontroller performs that instruction faster? What do you understand when we say that the PIC16F886 microcontroller is an 8-bit microcontroller? Describe the Data Memory layout of PIC16F886 (number of banks, SFRs, GPRs, etc). Draw a schematic explaining the layout. Explain in few words the purpose of the fourth address location in the data memory (Bank 0,1,2, & 3) of the PIC16F886 microcontroller. What is the function of the W register in the PIC16F886 microcontroller? 19

Prof E Ambikairajah ELEC2117: References 1. Designing Embedded Systems with PIC Microcontrollers Tim Wilmshurst, Elsevier, 2010 2. PIC Microcontrollers Free online book mikroelektronika ; http://www.mikroe.com/products/view/11/book-pic-microcontrollers/ 3. PIC 16F886 Data Sheet (2007), Microchip Technology; www.microchip.com 20