department of electronic electrical engineering lecture 2. pic16f84a architecture / instructions...

20
Department of Electronic & Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data). IO (memory mapped) Machine/Assembly code.

Upload: earl-cunningham

Post on 18-Jan-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Lecture 2.

PIC16F84A Architecture / Instructions

Memory. Program/Data (Harvard)File Registers (Data).IO (memory mapped)

Machine/Assembly code.

Page 2: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Understanding the architecture

• To program a PIC you need to know about the device.

• Not like high level programming (Matlab JAVA C?).

• The internal structure of the device is called its architecture.

• The following slide shows the internal structure of the PIC16F84A

• File Registers Store data (8 bits)

• ALU (arithmetic logic unit) Calculations• Buses

Carry data/addresses• Program Memory Stores the

program

Page 3: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)
Page 4: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Program memory1K of instructionseach instruction 14bits

PC -Address of next instruction

Instructions

Program Memory (code)

Page 5: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

General purpose memory68 8bit words

You can use this to store information

Busses are sets of lines that carry data/addresses

PIC puts an address on this bus

BUSES

USER DATA ADDRESSES

Page 6: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Special registers are used for IO

Access these just like user data. Using an addresses

TRISA 5bits to set input/out85h is it's hexidecimal address

read/write data to PORTB to read/setthe state of the pins.

IO

Data Direction (in or out?)

PINS

Page 7: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Arithmetic logic unit does the sums (ADD SUB OR..)

Working register can beused to store results.

Result is put in the working register OR a file register?

STATUS registerZ – result was 0C – carry bitDC - . . .

Data can come from instruction of a file registerALU

Page 8: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Registers and addresses

• Each register has a unique address.• Instructions use this address to read/write a particular register

Page 9: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

RPO Selects the bank

7 bits from opcode

Don't worry about thisyet!

Address

FILE REGISTERS

Special

USER DATA

Page 10: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Important registers

STATUS : result of an operation (e.g. 0) also used to select register bank

W: register used to store result of operation (not got an address)

PC: program counter. Address in program memory of next

instruction. Usually incremented by 1 after instruction has been executed.

Page 11: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

PIC16F84A program memory

Program memory is separate from user data (Harvard architecture)

● 1024 words of program memory (instructions)● Each instruction has 14 bits● You can not read or write to program memory● Execution starts at address 0

Page 12: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Opcode and Operands

The bits in an instructions can encoded:

● opcode➔ what it does (e.g. move something)

● operand(s)➔ What it does it too (e.g. what we move)

Page 13: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Example Machine Instructions (PIC16F84A)

● Each instruction is 14 bits● For example 000010 0 0100000

● 000010 --- subtract the contents of a register from W● 0 --- were we put result (W or file register)● 010000 --- which register

In this case

opcode (instruction) operand (data or address of data) 000010 0 010000

Page 14: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Different types of instructionuse different bits.

Page 15: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Assembly code

We would go mad trying to program in machine code so we use ASSEMBLY CODE

For example 000010 0 0100000 is written as

subwf 20h, w

Subtract W from register number 20h and put the result in W.

A program called an assembler converters assembly code into machine code (MPLABX uses mpasm).

Page 16: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Page 17: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Page 18: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Instruction Descriptions (page 37 ...)

Page 19: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

mpasm reference (Assembly language).

If you want to know more about the assembler please look at the E_Book

mpasm_reference.pdf

You can find this on moodle.

It might be easier to learn from the examples (depends on how your brain works).

There are many features of mpasm that are not in the examples.

Page 20: Department of Electronic  Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)

Department of Electronic & Electrical Engineering

Simple program. Initialize contents of a register.

movlw 5 ; Put the number 5 into W movwf H'16' ; copy W to register 16

Addresses of the registers (hexadecimal)