Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups.
By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Prof. Jorge A. Ramón Introducción a Microcontroladores.
EE1A Revision What should you be expected to do in a typical exam question ? Understanding of basic principles. Ability to perform simple circuit analysis.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Programming and Problem Solving
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Railway Foundation Electronic, Electrical and Processor Engineering.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 26: PIC microcontroller intro.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 30: PIC data memory.
Microcontroller Architecture— PIC18F Family
Railway Foundation Electronic, Electrical and Processor Engineering.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Microcontroller Architecture PIC18F Family
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
CoE3DJ4 Digital Systems Design
Training program: Mechanic - electrotechnician Program name: Digital processing - microprocessors III. class Microcontrollers Elaborated by: Vlastimil.
Microprocessor and Interfacing PIC Code Execution
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use ECE/CS 352: Digital Systems.
Embedded System Spring, 2011 Lecture 5: The PIC Microcontrollers Eng. Wazen M. Shbair.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
9/20/6Lecture 2 - Prog Model Architecture, Data Types and Addressing Modes.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Department of Electronic & Electrical Engineering Template program. Input / Output (IO) ● Template program. ● Introduction to IO ● Setting up for IO ●
Chapter 11 Data Acquisition and Manipulation The aims of this chapter are to introduce: the main features of a data acquisition system; the characteristics.
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Chapter 12 Some PIC Microcontroller Advances The aims of this chapter are to introduce: To introduce in overview two microcontrollers which show some enhanced.
Department of Electronic & Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data).
Working with Time: Interrupts, Counters and Timers
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
Chapter 5 Building Assembler Programs The aims of this chapter are to introduce: how to visualise a program, and represent it diagrammatically; how to.
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
5-2-1 PIC microcontroller. Learning objectives To aid revision, areas that are examinable are identified by a vertical line in the left margin. Where.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ read/write and clock inputs Sequence of control signal combinations.
An Introduction to Embedded Systems, and the PIC Microcontroller Lecture 8: Interrupts The aims of this session are to explore the structure and application.
Prof. Ahmad Abu-El-Haija
Control Unit Lecture 6.
Tiny Computers, Hidden Control
Microprocessor Systems Design I
Microprocessor Systems Design I
HTP Programme: Assembler
The 8051 Microcontroller and Embedded Systems
Microprocessor Systems Design I
PIC – ch. 2b Md. Atiqur Rahman Ahad.
Microprocessor Systems Design I
Tiny Computers, Hidden Control
Chapter 1 Introduction.
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Introducing the PIC Mid-Range Family and the 16F84A
68000 Architecture, Data Types and Addressing Modes
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
ECE 352 Digital System Fundamentals
EECE.3170 Microprocessor Systems Design I
Presentation transcript:

Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip MPLAB TM Integrated Development Environment; the PIC 16 Series instruction set, and the use of certain instructions; program simulation, and the MPLAB software simulator MPSIM TM ; program download to a target system. Designing Embedded Systems with PIC Microcontrollers: Principles and Applications 2 nd Edition. Tim Wilmshurst Instructors using Designing Embedded Systems with PIC Microcontrollers are welcome to use or change these slides as they see fit. Feedback, to is The copyright to all diagrams is held by Microchip Technology, or T. Wilmshurst, unless otherwise stated

The Problem of Programming, and Programming Options What options do we have for programming a microcontroller? Use Machine Code Use High Level Language Use Assembler Shall I compare thee to a summer day ?

The Assembler Option

Developing a Simple Project Write/modify Source Code Assemble/Compile (Simulate) Download Test in Hardware

The PIC 16 Series ALU f for file (i.e. memory location in RAM), a 7-bit number; b for bit, to be found within a file also specified, a single bit; d for destination, as described above, a single bit; k for literal, an 8-bit number if data, or 11-bit if address

The PIC 16 Series Instruction Set

clrw clears the value in the W register to zero. There are no operands to specify. Column 5 tells us that the Status register Z bit is affected by the instruction. As the result of this instruction is always zero, the bit is always set to 1. No other Status register bits are affected. clrf f clears the value of a memory location, symbolised as f. It is up to the programmer to specify a value for f, which needs to be a valid memory address. Again, because the result is zero, the Status register Z bit is affected. addwf f,d adds the contents of the W register to the contents of a memory location symbolised by f. There is a choice of where the result is placed, determined by the value of the operand bit d. Because of the different values that the result can take, all three condition code bits, i.e. Z, C, and DC are affected by the instruction. addlw k adds a literal, i.e. an 8-bit number written into the program and represented by k, to the value held in the W register. Like the addwf instruction, The Z, C, and DC Status register bits can all be affected by the instruction. bcf f,b clears a single bit in a memory location, symbolised by f. The bit number b will take a value from 0 to 7, to identify any one of the 8 bits in a memory location. No Status register flags are affected, even though it is possible to imagine that the result of the instruction could be to set a memory location to zero. goto k This instruction causes the program execution to jump to another point in the program, whose address is given by the constant k. It is up to the programmer to give a value for k. No Status bits are affected. Some Example Instructions

Writing in Assembler label instruction operand(s) ;comment Assembler format: ;now switch on red led Start bsf status,5 ;select memory bank 1 addwf counter For example: labelcomment operands commentLeft-most space optional instruction

Assembler Directives These look like Assembler mnemonics, but are instructions to the (Cross-) Assembler program itself. They differ from one Assembler to the other, though there does tend to be some similarity. Example MPASM Directives Assembler DirectiveSummary of Action listimplement a listing option* #includeinclude additional source file orgset program origin equdefine an assembly constant; this allows us to assign a value to a label endend program block

Representing Numbers RadixExample Representation Decimal D‘255’ Hexadecimal H‘8d’ or Ox8d Octal O‘574’ Binary B‘ ’ ASCII ‘G’ or A‘G’

Assembler File Structure (Simple Form) For us, this will be MPLAB Written by you, as a text file, in Assembler format Files that the Assembler (e.g. MPLAB) generates Source File Assembler Executable File List File Error File.asm.hex.lst.err

;****************************************************************** ;Very first program ;This program repeatedly adds a number to the Working Register. ;TJW Tested ;****************************************************************** ; ; use the org directive to force program start at reset vector org 00 ;program starts here clrw ;clear W register loop addlw 08 ;add the number 8 to W register goto loop end ;show end of program with "end" directive A First Program

Introducing MPLAB Continue here with the MPLAB tutorial from page 86 of the book.

A Larger Program – Using Data Memory and Moving Data ;***************************************************************************** ;Fibo_simple ;In a Fibonacci series each number is the sum of the two previous ones, ;e.g. 0,1,1,2,3,5,8,13, ;This program calculates Fibonacci numbers within an 8-bit range. ;Program intended for simulation only, hence no input/output. ;TJW Tested by simulation ;**************************************************************************** ;these memory locations hold the Fibonacci series Fib0equ 20 ;lowest number fib1 equ 21 ;middle number fib2 equ 22 ;highest number fibtemp equ 23 ;temporary location for newest number org 00 ;preload initial values clrf fib0;clear location fib0 movlw 1;move value 1 to W register movwf fib1;move W register to fib1 movwf fib2;move W register to fib2 ; forward movf fib1,0 ;move the contents of fib1 to W register addwf fib2,0;add W reg to fib2 movwf fibtemp;move new number formed to fibtemp ;now shuffle numbers held, discarding the oldest (ie fib0) movf fib1,0 ;move fib1 to W register movwf fib0;move W register to fib0 movf fib2,0;move fib2 to W register movwf fib1;move W register to fib1 movf fibtemp,0 ;move fibtemp to W register movwf fib2;move W register to fib2 goto forward end

;************************************************************** ;ELECTRONIC PING-PONG DATA MOVE ;This program moves push button switch values from Port A to the ;leds on Port B TJW ;************************************************************** ; ;Configuration Word: WDT off, power-up timer on, code protect off, RC oscillator ; list p=16F84A ;specify SFRs status equ 03 porta equ 05 trisa equ 05 portb equ 06 trisb equ 06 ; org 00 ;Initialise startbsfstatus,5 ;select memory bank 1 movlwB' ' movwftrisa;port A according to above pattern movlw00 movwftrisb;all port B bits output bcfstatus,5 ;select bank 0 ; ;The “main” program starts here clrf porta;clear all bits in ports A loopmovfporta,0;move port A to W register movwfportb;move W register to port B gotoloop end Opening explanatory comments SFR locations specified, by equating labels to numbers, taken directly from RAM memory map Initialisation Actual Program Program start address specified Directive specifying processor A Simple Data Transfer Program

Downloading to a Microcontroller It is possible to program the memory of the microcontroller either by removing it, and placing it in a dedicated programmer such as the PICstart; or (if the right connections are made, and the microcontroller has the capability) by connecting an in-circuit programmer, such as the PICkit 2. Both PICstart, and PICkit 2, connect back to a PC running MPLAB.

Instruction Formats of PIC Mid-Range Microcontrollers End of Lecture Note