SlideShare a Scribd company logo
PIC
Lecture 03
PIC18 features
• RISC architecture
• On-chip program (code) – ROM
• Data RAM
• Data EEPROM
• Timers
• ADC
• USART and I/O ports
Simple view of PIC
Lecture 03 basics of pic
Program ROM
• ROM is used to store programs (program or code ROM)
• PIC 18 program ROM
• Flash [letter F for this]
• OTP (One Time Programmable) [letter C for this]
• Masked (during fabrication process)
Data RAM and EEPROM
• RAM is for data storage.
• RAM Space = General Purpose Register (GPR) + Special Function
Registers (SFR)
• Microchip website gives only the GPR size (because SFRs are fixed)
• EEPROM:
• To store critical data that does not need to be changed very often
PIC microcontroller pheripherals
• ADC (10 bits)
• Timers
• USART (Universal Synchronous Asynchronous Receiver Transmitter)
PIC architecture and assembly
language programming
The WREG register
• The majority of PIC registers are 8 bits
• Therefore, only one data type: 8 bits
• Any data larger than 8 bits must be broken into 8-bits chunks.
• WREG  working register (only one)
• WREG  similar to accumulator in other microprocessors
• WREG  for all arithmetic and logic instructions
Understanding the WREG register
• MOVLW
• Move 8-bit data into WREG register
• Move a literal (L) value to WREG (W)
•
•
• MOVLW 25H ;move value 25H (25 in hex) into WREG
Understanding the WREG register
• ADDLW
• Add literal value K to WREG and put the result back to WREG
• WREG = WREG + k
Understanding the WREG register
Understanding the WREG register
PIC FILE Register
• File register  data memory space  read/ write (static RAM)
• File register data RAM = SFR + GPR
• SFR
• Dedicated to special functions
• ALU status
• Timers
• Serial communication
• I/O ports
• ADC
• ….Etc.
PIC FILE Register (Contd..)
• PIC SFRs are fixed and 8-bits
• More SFR registers while PIC has more timers, ADCs etc
• GPR (General purpose registers or RAM)
• For data storage and scratch pad
• Large GPR size means more difficulties in managing using assembly language
• C compiler need more registers to handle parameters and perform job faster
PIC FILE Register (Contd..)
PIC FILE Register (Contd..)
PIC FILE Register (Contd..)
PIC FILE Register (Contd..)
Simple instructions with the default access
bank
• MOVWF  (W: WREG, F: file register)
• This instruction tells to the CPU to move the source register of WREG to a
destination in the file register.
Special function registers
Simple instructions with the default access
bank GPR
Example
Example
More instructions
• ADDWF fileReg, D
SFR or GPR
Adding the content of
WREG and a file
register
Destination bit
D=0  destination is WREG
D=1  destination is file register
Example
Example - answer
Example
Example - answer
To make things less confusion
Destination = WREG
Destination = A file register
Try this..
Answer 1
Answer 2
WREG, File Registers and ALU
ALU instructions using both WREG and fileReg
File register instructions using fileReg or
WREG as destination
COMF instruction
How to write a program to toggle the SFR of Port B continuously forever?
COMF instruction
DECF
• Decrement (subtract one) the content of fileReg and place the result
in WREG or fileReg.
• Destination is fileReg
• Destination is WREG
MOVF
• This mnemonic is intended to perform MOVFW.
• MOVF fileReg, D
• If D=0  it copies the content of fileReg to WREG
• If D=1  fileReg is copied to itslef
MOVFF
• Copies data from One
location in fileReg 
another location in
fileReg
• Without going through
the WREG
PIC Status Register
• Flag register (status register)
PIC Status Register
• C (carry flag)
• This is set whenever there is a carry out from D7 bit (8th bit)
• This is affected after 8-bit addition and subtraction
• DC (digital carry flag) [Auxiliary Carry Flag]
• This bit is set whenever if there is a carry from D3 to D4 (during add and sub)
• This is used for BCD arithmetic
• Z (zero flag)
• If the result of arithmetic or logical operation is zero then z=1, otherwise (z=0)
for non-zero result.
PIC Status Register
• OV (overflow flag)
• This is used for signed number arithmetic
• N (Negative flag)
• This is also used for signed number arithmetic
• D7=0  N=0  result is positive
• D7=1  N=1  result is negative
• Not all instructions affect the flags
PIC Status Register
PIC Status Register
Flag bits and decision
• Status flags are also called conditional flags.
• Some instruction will make conditional jump (branch) based on the
status of the flag bits.
PIC data format representation
• Hex numbers
If the value started with hex digit (A-F), then it must
be preceded with zero.
PIC data format representation
• Binary numbers (1 way)
• Decimal numbers (2 ways)
• ASCII character
Assembler Directives
• Instructions  What to do using the CPU
• Directives (pseudo instructions)  Directions to the assembler
• Ex: EQU, SET, ORG and END
• EQU
• This is used to define a constant value or fixed address.
Assembler Directives
• SET
• This is used to define a constant value or fixed address.
• SET and EQU directives are identical.
• The value assigned by the SET directive may be reassigned later.
• ORG
• This is used to indicate the beginning of the address. (For both code and
data).
• The number that comes after ORG must be in hex.
Assembler Directives
• END
• This indicates to the assembler the end of source file (asm).
• Last line of the program
• LIST
• This indicates to the assembler the specific PIC chip
• We use LIST to state the target chip
Assembler Directives
• #include
• This tells the assembler to use the libraries associated with the specific PIC
• _config
• This tells the assembler the configurations bits for the target chip.
• Don’t use incorrect config:  it may meke the chip unusable
• radix
• This indicates whether the numbering system is hexadecimal or decimal.
• Default is hexadecimal
• For decimal
Rules for labels
• Meaningful
• Unique
• Label  consist of
• upper and lower case letters
• digits
• ?
• .
• @
• _
• $
• First character  alphabetic character
• Don’t use reserved words (check the assembler for more details)
Structure of assembly language
• Four fields
Optional fields
Line of the code by
name
Structure of assembly language (Example-
asm file)
Steps to create a program
Steps to create a program
• Sample of PIC err file
Steps to create a program
• Sample of List file
Program counter (PC)
• Another important register in the PIC microcontroller.
• The PC is used by the CPU to point the address of the next instruction
to be executed.
• The PC is incremented automatically.
• The wider the PC  CPU can access more memory locations
• 14-bit PC  214 (16K) code  (from 0000 to 3FFFH)
• 16-bit  216 (64K) code  (0000-FFFFH)
• 21-bit  221 (2M)  (000000-1FFFFFH)
Program counter (PC)
• PIC18 on-chip ROM Size and address space
Program counter (PC)
Program counter (PC)
Executing a program byte by byte
Two bytes
instructions
Four bytes instruction
Executing a program byte by byte
• ROM contents
Why PIC use Harvard architecture?
Instruction size of PIC 18
• MOLW (2 byte instruction)
Opcode (8 bits) Literal
value
Instruction size of PIC 18
• ADDLW
• MOVWF
Instruction size of PIC 18
• MOVFF (4 bytes)
• GOTO (4 bytes)
Because,
instructions are
either 2 bytes or 4
bytes
Ways to increase performance
• There are three ways available to microprocessor designers to
increase the processing power of CPU
• Increase clock frequency  more power and heat dissipation
• Use Harvard architecture  very expensive and unrealistic for x86
architecture
• Use RISC architecture
Microchip used all three methods
Features of RISC
• Feature 1: RISC processors have fixed instruction size.
• Feature 2: Use large number of registers (at least 32 registers).
• Feature 3: RISC processors have a small instruction set.
• Feature 4: more than 95% of instructions are executed with only one
clock cycle.
• Feature 5: RISC processors have separate buses for data and code.
• Feature 6: due to the small set of instructions, they are implemented
using the hardwire method. (no more than 10% of transistors)
• Feature 7: RISC uses load/store architecture. (no direct access to
external memory for arithmetic operations, only via registers)
• Shall we try MPLAB IDE?????
Summary

More Related Content

PPTX
8051 microcontroller features
PDF
Seven segment interfacing with 8051.pdf
PPT
PIC 16F877A by PARTHIBAN. S.
PPTX
8257 DMA Controller
PDF
ARM Architecture
PDF
Microcontroller pic 16 f877 registers memory ports
PPTX
RISC - Reduced Instruction Set Computing
PPT
Serial Peripheral Interface(SPI)
8051 microcontroller features
Seven segment interfacing with 8051.pdf
PIC 16F877A by PARTHIBAN. S.
8257 DMA Controller
ARM Architecture
Microcontroller pic 16 f877 registers memory ports
RISC - Reduced Instruction Set Computing
Serial Peripheral Interface(SPI)

What's hot (20)

PDF
8051 microcontroller
PPSX
LECT 1: ARM PROCESSORS
PDF
Soc architecture and design
PPSX
Evolution Of Microprocessors
PDF
Microcontroller pic 16f877 architecture and basics
PDF
ARM 32-bit Microcontroller Cortex-M3 introduction
PPTX
Semiconductor Memory
PPTX
RTC Interfacing and Programming
PPT
Spi master core verification
PDF
Introduction to 80386
PPTX
Intel 8259 - Programmable Interrupt Controller
PPTX
Pin diagram 8085
PPTX
I2C Protocol
DOCX
UNIT I- CPLD & FPGA ARCHITECTURE & APPLICATIONS
ODP
APB protocol v1.0
PPT
8259 updated
PDF
80386 microprocessor system instruction
PDF
Jtag presentation
PPTX
Interfacing technique with 8085- ADC[0808]
8051 microcontroller
LECT 1: ARM PROCESSORS
Soc architecture and design
Evolution Of Microprocessors
Microcontroller pic 16f877 architecture and basics
ARM 32-bit Microcontroller Cortex-M3 introduction
Semiconductor Memory
RTC Interfacing and Programming
Spi master core verification
Introduction to 80386
Intel 8259 - Programmable Interrupt Controller
Pin diagram 8085
I2C Protocol
UNIT I- CPLD & FPGA ARCHITECTURE & APPLICATIONS
APB protocol v1.0
8259 updated
80386 microprocessor system instruction
Jtag presentation
Interfacing technique with 8085- ADC[0808]
Ad

Similar to Lecture 03 basics of pic (20)

PPTX
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
PPTX
Topic 2 ARM Architecture and Programmer's Model.pptx
PPTX
Arm architecture chapter2_steve_furber
PPT
8051.ppt microcontroller full detail explnation
PPTX
Embedded computing platform design
PDF
Introduction to Processor Design in System Verilog
PPT
10 instruction sets characteristics
PPTX
ARM introduction registers architectures
PPTX
ARM-7 ADDRESSING MODES INSTRUCTION SET
PPT
W8_1: Intro to UoS Educational Processor
PPTX
Module 2 ARM CORTEX M3 Instruction Set and Programming
PPT
Processor Design Flow architecture design
PPTX
It322 intro 1
PPTX
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
PPTX
Architecture of pentium family
PPTX
PDF
introduction to embedded systems part 1
PPTX
Pentium processor
PDF
Introduction to pic microcontroller
PPTX
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
Topic 2 ARM Architecture and Programmer's Model.pptx
Arm architecture chapter2_steve_furber
8051.ppt microcontroller full detail explnation
Embedded computing platform design
Introduction to Processor Design in System Verilog
10 instruction sets characteristics
ARM introduction registers architectures
ARM-7 ADDRESSING MODES INSTRUCTION SET
W8_1: Intro to UoS Educational Processor
Module 2 ARM CORTEX M3 Instruction Set and Programming
Processor Design Flow architecture design
It322 intro 1
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
Architecture of pentium family
introduction to embedded systems part 1
Pentium processor
Introduction to pic microcontroller
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
Ad

More from Vajira Thambawita (20)

PDF
Lecture 4 principles of parallel algorithm design updated
PDF
Lecture 3 parallel programming platforms
PDF
Lecture 2 more about parallel computing
PDF
Lecture 1 introduction to parallel and distributed computing
PDF
Lecture 12 localization and navigation
PDF
Lecture 11 neural network principles
PDF
Lecture 10 mobile robot design
PDF
Lecture 09 control
PDF
Lecture 08 robots and controllers
PDF
Lecture 07 more about pic
PDF
Lecture 06 pic programming in c
PDF
Lecture 05 pic io port programming
PDF
Lecture 04 branch call and time delay
PDF
Lecture 02 mechatronics systems
PDF
Lecture 1 - Introduction to embedded system and Robotics
PDF
Lec 09 - Registers and Counters
PDF
Lec 08 - DESIGN PROCEDURE
PDF
Lec 07 - ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS
PDF
Lec 06 - Synchronous Sequential Logic
PDF
Lec 05 - Combinational Logic
Lecture 4 principles of parallel algorithm design updated
Lecture 3 parallel programming platforms
Lecture 2 more about parallel computing
Lecture 1 introduction to parallel and distributed computing
Lecture 12 localization and navigation
Lecture 11 neural network principles
Lecture 10 mobile robot design
Lecture 09 control
Lecture 08 robots and controllers
Lecture 07 more about pic
Lecture 06 pic programming in c
Lecture 05 pic io port programming
Lecture 04 branch call and time delay
Lecture 02 mechatronics systems
Lecture 1 - Introduction to embedded system and Robotics
Lec 09 - Registers and Counters
Lec 08 - DESIGN PROCEDURE
Lec 07 - ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS
Lec 06 - Synchronous Sequential Logic
Lec 05 - Combinational Logic

Recently uploaded (20)

PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
English Language Teaching from Post-.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
From loneliness to social connection charting
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Introduction and Scope of Bichemistry.pptx
O7-L3 Supply Chain Operations - ICLT Program
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
English Language Teaching from Post-.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
human mycosis Human fungal infections are called human mycosis..pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Pharma ospi slides which help in ospi learning
Cardiovascular Pharmacology for pharmacy students.pptx
From loneliness to social connection charting
NOI Hackathon - Summer Edition - GreenThumber.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Anesthesia in Laparoscopic Surgery in India
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Lecture 03 basics of pic

  • 2. PIC18 features • RISC architecture • On-chip program (code) – ROM • Data RAM • Data EEPROM • Timers • ADC • USART and I/O ports
  • 5. Program ROM • ROM is used to store programs (program or code ROM) • PIC 18 program ROM • Flash [letter F for this] • OTP (One Time Programmable) [letter C for this] • Masked (during fabrication process)
  • 6. Data RAM and EEPROM • RAM is for data storage. • RAM Space = General Purpose Register (GPR) + Special Function Registers (SFR) • Microchip website gives only the GPR size (because SFRs are fixed) • EEPROM: • To store critical data that does not need to be changed very often
  • 7. PIC microcontroller pheripherals • ADC (10 bits) • Timers • USART (Universal Synchronous Asynchronous Receiver Transmitter)
  • 8. PIC architecture and assembly language programming
  • 9. The WREG register • The majority of PIC registers are 8 bits • Therefore, only one data type: 8 bits • Any data larger than 8 bits must be broken into 8-bits chunks. • WREG  working register (only one) • WREG  similar to accumulator in other microprocessors • WREG  for all arithmetic and logic instructions
  • 10. Understanding the WREG register • MOVLW • Move 8-bit data into WREG register • Move a literal (L) value to WREG (W) • • • MOVLW 25H ;move value 25H (25 in hex) into WREG
  • 11. Understanding the WREG register • ADDLW • Add literal value K to WREG and put the result back to WREG • WREG = WREG + k
  • 14. PIC FILE Register • File register  data memory space  read/ write (static RAM) • File register data RAM = SFR + GPR • SFR • Dedicated to special functions • ALU status • Timers • Serial communication • I/O ports • ADC • ….Etc.
  • 15. PIC FILE Register (Contd..) • PIC SFRs are fixed and 8-bits • More SFR registers while PIC has more timers, ADCs etc • GPR (General purpose registers or RAM) • For data storage and scratch pad • Large GPR size means more difficulties in managing using assembly language • C compiler need more registers to handle parameters and perform job faster
  • 16. PIC FILE Register (Contd..)
  • 17. PIC FILE Register (Contd..)
  • 18. PIC FILE Register (Contd..)
  • 19. PIC FILE Register (Contd..)
  • 20. Simple instructions with the default access bank • MOVWF  (W: WREG, F: file register) • This instruction tells to the CPU to move the source register of WREG to a destination in the file register. Special function registers
  • 21. Simple instructions with the default access bank GPR
  • 24. More instructions • ADDWF fileReg, D SFR or GPR Adding the content of WREG and a file register Destination bit D=0  destination is WREG D=1  destination is file register
  • 29. To make things less confusion Destination = WREG Destination = A file register
  • 34. ALU instructions using both WREG and fileReg
  • 35. File register instructions using fileReg or WREG as destination
  • 36. COMF instruction How to write a program to toggle the SFR of Port B continuously forever?
  • 38. DECF • Decrement (subtract one) the content of fileReg and place the result in WREG or fileReg. • Destination is fileReg • Destination is WREG
  • 39. MOVF • This mnemonic is intended to perform MOVFW. • MOVF fileReg, D • If D=0  it copies the content of fileReg to WREG • If D=1  fileReg is copied to itslef
  • 40. MOVFF • Copies data from One location in fileReg  another location in fileReg • Without going through the WREG
  • 41. PIC Status Register • Flag register (status register)
  • 42. PIC Status Register • C (carry flag) • This is set whenever there is a carry out from D7 bit (8th bit) • This is affected after 8-bit addition and subtraction • DC (digital carry flag) [Auxiliary Carry Flag] • This bit is set whenever if there is a carry from D3 to D4 (during add and sub) • This is used for BCD arithmetic • Z (zero flag) • If the result of arithmetic or logical operation is zero then z=1, otherwise (z=0) for non-zero result.
  • 43. PIC Status Register • OV (overflow flag) • This is used for signed number arithmetic • N (Negative flag) • This is also used for signed number arithmetic • D7=0  N=0  result is positive • D7=1  N=1  result is negative • Not all instructions affect the flags
  • 46. Flag bits and decision • Status flags are also called conditional flags. • Some instruction will make conditional jump (branch) based on the status of the flag bits.
  • 47. PIC data format representation • Hex numbers If the value started with hex digit (A-F), then it must be preceded with zero.
  • 48. PIC data format representation • Binary numbers (1 way) • Decimal numbers (2 ways) • ASCII character
  • 49. Assembler Directives • Instructions  What to do using the CPU • Directives (pseudo instructions)  Directions to the assembler • Ex: EQU, SET, ORG and END • EQU • This is used to define a constant value or fixed address.
  • 50. Assembler Directives • SET • This is used to define a constant value or fixed address. • SET and EQU directives are identical. • The value assigned by the SET directive may be reassigned later. • ORG • This is used to indicate the beginning of the address. (For both code and data). • The number that comes after ORG must be in hex.
  • 51. Assembler Directives • END • This indicates to the assembler the end of source file (asm). • Last line of the program • LIST • This indicates to the assembler the specific PIC chip • We use LIST to state the target chip
  • 52. Assembler Directives • #include • This tells the assembler to use the libraries associated with the specific PIC • _config • This tells the assembler the configurations bits for the target chip. • Don’t use incorrect config:  it may meke the chip unusable • radix • This indicates whether the numbering system is hexadecimal or decimal. • Default is hexadecimal • For decimal
  • 53. Rules for labels • Meaningful • Unique • Label  consist of • upper and lower case letters • digits • ? • . • @ • _ • $ • First character  alphabetic character • Don’t use reserved words (check the assembler for more details)
  • 54. Structure of assembly language • Four fields Optional fields Line of the code by name
  • 55. Structure of assembly language (Example- asm file)
  • 56. Steps to create a program
  • 57. Steps to create a program • Sample of PIC err file
  • 58. Steps to create a program • Sample of List file
  • 59. Program counter (PC) • Another important register in the PIC microcontroller. • The PC is used by the CPU to point the address of the next instruction to be executed. • The PC is incremented automatically. • The wider the PC  CPU can access more memory locations • 14-bit PC  214 (16K) code  (from 0000 to 3FFFH) • 16-bit  216 (64K) code  (0000-FFFFH) • 21-bit  221 (2M)  (000000-1FFFFFH)
  • 60. Program counter (PC) • PIC18 on-chip ROM Size and address space
  • 63. Executing a program byte by byte Two bytes instructions Four bytes instruction
  • 64. Executing a program byte by byte • ROM contents
  • 65. Why PIC use Harvard architecture?
  • 66. Instruction size of PIC 18 • MOLW (2 byte instruction) Opcode (8 bits) Literal value
  • 67. Instruction size of PIC 18 • ADDLW • MOVWF
  • 68. Instruction size of PIC 18 • MOVFF (4 bytes) • GOTO (4 bytes) Because, instructions are either 2 bytes or 4 bytes
  • 69. Ways to increase performance • There are three ways available to microprocessor designers to increase the processing power of CPU • Increase clock frequency  more power and heat dissipation • Use Harvard architecture  very expensive and unrealistic for x86 architecture • Use RISC architecture Microchip used all three methods
  • 70. Features of RISC • Feature 1: RISC processors have fixed instruction size. • Feature 2: Use large number of registers (at least 32 registers). • Feature 3: RISC processors have a small instruction set. • Feature 4: more than 95% of instructions are executed with only one clock cycle. • Feature 5: RISC processors have separate buses for data and code. • Feature 6: due to the small set of instructions, they are implemented using the hardwire method. (no more than 10% of transistors) • Feature 7: RISC uses load/store architecture. (no direct access to external memory for arithmetic operations, only via registers)
  • 71. • Shall we try MPLAB IDE?????