Introduction to Microprocessors and Assembler Programming - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Introduction to Microprocessors and Assembler Programming

Description:

an understanding of the basic principles of microprocessors and appreciate the ... in assembler language to control a simple working traffic light/pelican crossing. ... – PowerPoint PPT presentation

Number of Views:423
Avg rating:3.0/5.0
Slides: 20
Provided by: visual1
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Microprocessors and Assembler Programming


1
Introduction to Microprocessors and Assembler
Programming   
EE1A2 
  • Sandra I. Woolley
  • Electronic, Electrical and Computer Engineering

2
Summary of Objectives
  • This course has been designed to provide
  • an understanding of the basic principles of
    microprocessors and appreciate the difference
    between microprocessors, microcontrollers and
    DSPs (digital signal processors),
  • a working knowledge of the PIC16F84
    microcontroller,
  • experience of assembler programming and a basic
    appreciation of embedded systems.  

3
Working Knowledge of PIC16F84
  • The course provides an introduction to
    microprocessors using PIC microcontrollers
    manufactured by Microchip (www.microchip.com).
  • The Microchip PIC16F84 is a low-cost,
    single-chip, 8-bit microcontroller.
  • Laboratory exercises program the PIC
    microcontroller in assembler language to control
    a simple working traffic light/pelican crossing.

4
Assessment
  • Questions asked on this component in the final
    EE1A2 written examination.
  • Laboratory exercises
  • 3 exercises over 4x2hr lab sessions
  • Assessment comprises
  • Attendance
  • Checked progress forms (one per student per lab
    session)
  • Group technical report based on final exercise
  • There are no tutorial classes but you can try the
    3 tutorial exercises listed in the handout.
    Sample solutions to the hardest questions
    (tutorial no. 3) are provided in the handout.

5
The Handout
  • Bring the handout to all lectures and laboratory
    sessions.
  • Supplement with your own notes. There will be
    quite a few exercises in the lectures.
  • Distinguish between reference material and
    lecture notes.
  • Read lecture notes in your own time.
  • Familiarise yourself with the reference data
    samples and identify important pages.
  • Study the instruction set listing.

6
The Microchip PIC16F84
  • We use the Microchip PIC16F84 as an example
    processor.
  • The Microchip PIC16F84 is a low-cost,
    single-chip, 8-bit, microcontroller.
  • It is a simple and very popular microcontroller.
  • It will be programmed in assembler in the
    laboratory to control a working traffic
    light/pelican crossing.

7
Course and PIC Resources
  • The course web page httpwww.eee.bham.ac.uk/wool
    leysi/teaching/pic/

8
Introduction to Microprocessors
  • A microprocessor is a programmable logic device
    with a designed set of instructions.
  • It contains three primary components
  • a processing unit (ALU), memory, and, input and
    output (I/O).
  • Arithmetic/Logic Unit (ALU)
  • Performs arithmetic operations such as addition
    and subtraction, and, logic operations such as
    AND, IOR and XOR.
  • Memory
  • Storage of instructions and data.
  • Input and output (I/O)
  • Analogue or digital for external communication.

9
Microprocessors, Microcontrollers and DSPs
  • Microprocessor is an umbrella term for all
    types of processor.
  • Microcontrollers and DSPs evolved from the
    original microprocessors.
  • Microcontrollers
  • Processor specifically designed for control
    applications.
  • DSPs
  • Processors specifically designed for digital
    signal processing.
  • Microprocessors
  • Processors for general purpose processing.

Microprocessors
Microprocessors
DSPs
Microprocessors
Microcontrollers
10
Microprocessors, Microcontrollers and DSPsMany
processors are hybrids, for example, the dsPIC.
Microprocessors (General purpose processors)
DSPs (Digital Signal Processors) Designed to be
good at mathematics for signal processing.
Microcontrollers (Processors good at control)
Typically compact, low power, good I/O capacity,
limited computational power)
ASICs (Application Specific Integrated
Circuits) FIXED PURPOSE HARDWARE
FPGAs (Field Programmable Gate Arrays) FLEXIBLE
PROGRAMABLE HARDWARE
11
Microprocessor Programming
  • A program is a set of instructions written in a
    specific sequence for a processor to accomplish
    specified tasks.
  • An instruction is defined as a complete task
    (such as addition) performed by the
    microprocessor. Each microprocessor has its own
    set of instructions.
  • To be intelligible to the microprocessor,
    instructions must be supplied in binary, i.e., as
    machine language.
  • Assembler language is a symbolic language which
    represents instructions with short human-readable
    mnemonics. For example, in PIC assembler a null
    operation or no operation is represented by the
    mnemonic NOP.
  • An assembler is a software tool that converts
    assembler source programs into machine language
    object files.
  • Assemblers contain built-in debugging tools which
    can detect syntax errors.
  • For example, MPLAB is Microchip's PIC
    development environment which includes an
    assembler that generates assembled files (object
    files) with .HEX extensions which are used to
    program PIC chips.  

12
Microprocessor Programming
  • There is a one-to-one correspondence between the
    assembly language mnemonics and the machine code
    instructions.
  • Machine and assembly languages are referred to as
    low-level languages.
  • Programs written in these languages are generally
    faster and more compact than higher-level
    language programs but not transferable to other
    processors.
  • High-level languages such as C, Pascal and BASIC
    are machine-independent. Programs (source code)
    written in these languages are translated by
    compilers or interpreters into machine language
    compatible with the given processor. The
    translated code is called object code. Each
    microprocessor needs its own compiler or
    interpreter.
  • An important advantage of high-level languages is
    that they are much easier to debug.

13
An Example of PIC Assembler
  • Instruction lines are arranged in columns
  • (labels, operators, operands.)
  • The example program is purposely over-commented.
    In your lab exercises, you will be encouraged to
    write shorter comments which describe the more
    general function of lines of code.
  • Questions
  • What symbol is used as a delimiter to distinguish
    a comment from an instruction?
  • Where is PORTB in the register file (data memory)
    map? (Find the register file map in the notes
    and the more detailed map in the PIC reference
    data at the back of this study guide.)
  • What are the physical locations of the PORTB pins
    (RB pins) on the PIC microcontroller? (You
    will need to look at a pin-out diagram).

14
Programming in PIC Assembler
  • WRITTEN BY SIW
  • DATE 01/01/2004
  • FILE SAVED AS TEST.ASM
  • DEVICE 16F84
  • OSCILLATOR XT (4MHZ)
  • WATCHDOG DISABLED
  • FUNCTION OUTPUTS THE VALUE 0XF1 TO
    8 LEDS CONNECTED TO PORTB
  • ----------------------- EQUATES
    ------------------------------------
  • PORTB EQU 0X06 ASSIGN THE PORTB
    REGISTER TO THE LABEL 'PORTB'
  • ----------------------- MAIN PROGRAM
    ------------------------------------
  • START ORG 0X00 'ORG' SPECIFIES THE
    MEMORY LOCATION OF THE PROGRAM
  • MOVLW 0X00 MOVE THE VALUE 00, I.E.,
    ALL 0'S TO W
  • TRIS PORTB CONFIGURE PORTB WITH THE
    VALUE IN W (THE
  • WORKING REGISTER)
    1INPUT AND 0OUTPUT.
  • SO 00 (ALL 0'S) MAKES
    ALL PORTB LINES OUTPUTS.
  • CLRF PORTB CLEAR THE PORTB REGISTER
  • MOVLW 0XF1 MOVE THE HEX VALUE F1 TO
    THE WORKING REGISTER
  • MOVWF PORTB MOVE THE VALUE OF W TO
    THE OUTPUT (PORTB)
  • LOOP GOTO LOOP

15
Programming in PIC Assembler
  • WRITTEN BY SIW
  • DATE 01/01/2004
  • FILE SAVED AS TEST.ASM
  • DEVICE 16F84
  • OSCILLATOR XT (4MHZ)
  • WATCHDOG DISABLED
  • FUNCTION OUTPUTS THE VALUE 0XF1 TO
    8 LEDS CONNECTED TO PORTB
  • ----------------------- EQUATES
    ------------------------------------
  • PORTB EQU 0X06 ASSIGN THE PORTB
    REGISTER TO THE LABEL 'PORTB'
  • ----------------------- MAIN PROGRAM
    ------------------------------------
  • START ORG 0X00 'ORG' SPECIFIES THE
    MEMORY LOCATION OF THE PROGRAM
  • MOVLW 0X00 MOVE THE VALUE 00, I.E.,
    ALL 0'S TO W
  • TRIS PORTB CONFIGURE PORTB WITH THE
    VALUE IN W (THE
  • WORKING REGISTER)
    1INPUT AND 0OUTPUT.
  • SO 00 (ALL 0'S) MAKES
    ALL PORTB LINES OUTPUTS.
  • CLRF PORTB CLEAR THE PORTB REGISTER
  • MOVLW 0XF1 MOVE THE HEX VALUE F1 TO
    THE WORKING REGISTER
  • MOVWF PORTB MOVE THE VALUE OF W TO
    THE OUTPUT (PORTB)
  • LOOP GOTO LOOP

Comments start with a semi-colon
Operands column (data for instructions)
Label column
Operator column (instructions directives)
16
Programming in PIC Assembler
  • WRITTEN BY SIW
  • DATE 01/01/2004
  • FILE SAVED AS TEST.ASM
  • DEVICE 16F84
  • OSCILLATOR XT (4MHZ)
  • WATCHDOG DISABLED
  • FUNCTION OUTPUTS THE VALUE 0XF1 TO
    8 LEDS CONNECTED TO PORTB
  • ----------------------- EQUATES
    ------------------------------------
  • PORTB EQU 0X06 ASSIGN THE PORTB
    REGISTER TO THE LABEL 'PORTB'
  • ----------------------- MAIN PROGRAM
    ------------------------------------
  • START ORG 0X00 'ORG' SPECIFIES THE
    MEMORY LOCATION OF THE PROGRAM
  • MOVLW 0X00 MOVE THE VALUE 00, I.E.,
    ALL 0'S TO W
  • TRIS PORTB CONFIGURE PORTB WITH THE
    VALUE IN W (THE
  • WORKING REGISTER)
    1INPUT AND 0OUTPUT.
  • SO 00 (ALL 0'S) MAKES
    ALL PORTB LINES OUTPUTS.
  • CLRF PORTB CLEAR THE PORTB REGISTER
  • MOVLW 0XF1 MOVE THE HEX VALUE F1 TO
    THE WORKING REGISTER
  • MOVWF PORTB MOVE THE VALUE OF W TO
    THE OUTPUT (PORTB)
  • LOOP GOTO LOOP

The header contains some really important
information about the device and its settings
and, most importantly, the FUNCTION statement
that says what it connects to and what it does.
17
Assembling TEST.ASM in MPLAB
  •  
  • Here is the program in the assembler (MPLAB).
  • The software colours the code. Comments are
    shown here in green, labels in purple and
    instructions in bold blue.
  • The Output window below shows the assembly
    progress as the .hex file is generated.

We will get these warning about the TRIS
instruction. But note the build is successful.
More on a TRIS alternative later.
18
TEST.LST
  •  
  • TEST.LST The listing file produced by MPLAB as
    part of the assembling process.
  • The hex values of the machine language object
    file are shown on the left-hand side.
  • For example, MOVLW can be seen to map to value
    30)

The machine code program. Note no comments,
just instructions and their data.
19
Thank YouApplications, processor architecture
and PIC programming exercises in the next
lecture   
 
  • The rest of the slides in this presentation are
    about microprocessor history and are included for
    interest only (they are not assessed).
Write a Comment
User Comments (0)
About PowerShow.com