MECE336– Microprocessors I

PIC Overview
Instructions and Machine Code
MECE336– Microprocessors I
PIC 16F84A – Basics
Associate Prof. Dr. Klaus Werner Schmidt
Department of Mechatronics Engineering – Çankaya University
Compulsory Course in Mechatronics Engineering
Credits (3/2/4)
Course Webpage: http://MECE336.cankaya.edu.tr
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
PIC Overview: Block Diagram
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
PIC Overview: Main Components
Memory
Store program
Store data
Support Functions
Power, timer
Arithmetic Logic Unit
Logic operations (AND, OR, etc.)
Additions, subtractions
Peripherals
Digital inputs/outputs
Timer, interrupt
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
PIC Overview: Memory
Program Memory
Data Memory
Flash
RAM File registers
Program Counter
EEPROM
Stack
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
PIC Overview: Memory Description
Program Memory
Program memory is loaded with program instructions to be executed
Range of the program memory is 0000 to 03FF (hexadecimal)
Program counter always holds address of the next instruction
Stack
Temporary memory that stores values of the program counter in case
of special instructions (CALL, RETURN)
Configuration Word
Define configurable features of MC at program download (not during
operation)
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
PIC Overview: Program Memory
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
PIC Overview: Memory Description
Data and Special Function register memory (RAM)
Two memory banks
Bank 0: Address 0x00 to 0x4F
Bank 1: Address 0x80 to 0xCF
Address 0x50 to 0x7F and 0xD0 to 0xFF are not implemented in
PIC16F84A
Special function registers (SFRs): configure interaction between CPU
and peripherals
General-purpose data memory
EEPROM
Non-volatile memory for holding data values for long term operation
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
PIC Overview: Memory Banks
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
PIC Overview: Supporting Functions
Description
Timer for power-up of MC
holds MC in Reset state until
power stabilizes
External oscillator can be
connected for stable timing
Watchdog timer forces Reset if
MC crashes
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
PIC Overview: Arithmetic Logic Unit
Description
Performs logic instructions such
as AND, OR, XOR
Performs additions, subtractions
Operates on 8bit data from the
working register W and the data
bus
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
PIC Overview: Peripherals
Description
PORTA and PORTB
Digital inputs/outputs
Timer input at RA4
Interrupt input at RB0
Each pin is configured in the SFRs
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
PIC Overview: Basic Program Structure
Directives
Program is processed by the Assembler
Pass information and instructions to the assembler using directives
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
PIC Overview: General Operation
Basic Program and Instructions
list
p=16F84A
org 00
......
Program Code
......
end
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Instructions
14 bit Instruction Word
MSB (bit 13)
LSB (bit 0)
OPCODE
Operand 1
Operand 2
Opcode: specifies the instruction type
Operands: specify the operation of the instruction (one or two
operands)
Bit sequence of instruction represents the machine code
Types of Instructions
Byte-oriented Instructions
Bit-oriented Instructions
Literal and Control Operations
CALL and GOTO Instructions
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Byte-oriented Instructions
Byte-oriented File Register Operations
Examples
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
Instructions and Machine Code:Table
Byte-oriented File Register Operations
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Bit-oriented Instructions
Bit-oriented File Register Operations
Examples
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Bit-oriented Instructions
Bit-oriented File Register Operations
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Literal and Control
Literal and Control Operations
Examples
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Literal and Control
Literal and Control Operations
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: CALL and GOTO
CALL and GOTO Instructions
Examples
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Example Program
Klaus Schmidt
MECE336 – Microprocessors I
Department
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Hex file
Example
:02 0000 04 0000 FA
:04 0000 00 8C010028 47
:04 0004 00 00340034 90
:00 0000 01 FF
General Format of Each Line – :BB AAAA TT HHHH....HHH CC
BB: Two digit hex byte count (number of data bytes on the line)
AAAA: Four digit hex starting address of the data record
TT: A two digit record type:
00
01
02
04
Data record
End of File record
Segment Address record
Linear Address record
HH: Two digit hex data byte in low byte/high byte combinations.
CC: Two digit hexadecimal checksum
Klaus Schmidt
Department
MECE336 – Microprocessors I
PIC Overview
Instructions and Machine Code
Instructions and Machine Code: Explanation
Klaus Schmidt
MECE336 – Microprocessors I
Department