Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Department of Electronic & Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)."— Presentation transcript:

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

2 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

3

4 Department of Electronic & Electrical Engineering Program memory 1K of instructions each instruction 14bits PC -Address of next instruction Instructions Program Memory (code)

5 Department of Electronic & Electrical Engineering General purpose memory 688bit 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

6 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/out 85h is it's hexidecimal address read/write data to PORTB to read/set the state of the pins. IO Data Direction (in or out?) PINS

7 Department of Electronic & Electrical Engineering Arithmetic logic unit does the sums (ADD SUB OR..) Working register can be used to store results. Result is put in the working register OR a file register? STATUS register Z – result was 0 C – carry bit DC -... Data can come from instruction of a file register ALU

8 Department of Electronic & Electrical Engineering Registers and addresses Each register has a unique address. Instructions use this address to read/write a particular register

9 RPO Selects the bank 7 bits from opcode Don't worry about this yet! Address FILE REGISTERS Special USER DATA

10 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.

11 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

12 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)

13 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

14 Department of Electronic & Electrical Engineering Different types of instruction use different bits.

15 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).

16 Department of Electronic & Electrical Engineering

17

18 Instruction Descriptions (page 37...)

19 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.

20 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)

21 Department of Electronic & Electrical Engineering Simulator doing previous slide


Download ppt "Department of Electronic & Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data)."

Similar presentations


Ads by Google